Posts Tagged ‘linux’

SVN stat + externals = visual horror

February 23, 2009

The student robotics firmwares pull in a library, Rob has implemented this wizzardy with svn externals. Whilst I enjoy the idea, I find the modified output of svn stat quite hard to scan quickly and therefore hard to read:

X      lib-fw/flash430/trunk/types
X      motor/firmware/trunk/flash430
X      motor/firmware/trunk/types
?      pwm/svn-stat-dump
?      pwm/svn-stat-dumppy
X      pwm/firmware/trunk/flash430
X      pwm/firmware/trunk/types
M      pwm/firmware/trunk/main.c
X      jointio/firmware/trunk/flash430
X      jointio/firmware/trunk/types
?      power/pcb/trunk/gerbers/power-bstop.gbr
?      power/pcb/trunk/gerbers/power-tstop.gbr
X      power/firmware/trunk/flash430
X      power/firmware/trunk/types

Performing status on external item at ‘motor/firmware/trunk/flash430′
X      motor/firmware/trunk/flash430/types

Performing status on external item at ‘motor/firmware/trunk/flash430/types’

Performing status on external item at ‘motor/firmware/trunk/types’

Performing status on external item at ‘pwm/firmware/trunk/flash430′
X      pwm/firmware/trunk/flash430/types

Performing status on external item at ‘pwm/firmware/trunk/flash430/types’

Performing status on external item at ‘pwm/firmware/trunk/types’

Performing status on external item at ‘lib-fw/flash430/trunk/types’

Performing status on external item at ‘jointio/firmware/trunk/flash430′
X      jointio/firmware/trunk/flash430/types

Performing status on external item at ‘jointio/firmware/trunk/flash430/types’

Each external adds at least two lines, three if modified. So five minutes produced this

usage is:  svn stat | pystat.py, I think I will add an alias as I use it quite a bit.

giving a cleaner output (the white space is a bit mangled by wordpress! X,M,? etc should all line up, I should probably find a way to fix this):

X      lib-fw/flash430/trunk/types
X      motor/firmware/trunk/flash430
X      motor/firmware/trunk/types
?      pwm/svn-stat-dump
?      pwm/svn-stat-dumppy
X      pwm/firmware/trunk/flash430
X      pwm/firmware/trunk/types
M      pwm/firmware/trunk/main.c
X      jointio/firmware/trunk/flash430
X      jointio/firmware/trunk/types
?      power/pcb/trunk/gerbers/power-bstop.gbr
?      power/pcb/trunk/gerbers/power-tstop.gbr
X      power/firmware/trunk/flash430
X      power/firmware/trunk/types
ext  X      motor/firmware/trunk/flash430/types
ext  X      pwm/firmware/trunk/flash430/types
ext  X      jointio/firmware/trunk/flash430/types
ext  X      power/firmware/trunk/flash430/types

This was also one of those things Ive been thinking about for ages, but unwilling to commit the time for such a minor irritant. Once I eventually broke, I decided to time the implementation, it really was sub 5 min including (swift) testing! So yes it was definitely worth it for reduced groan!

Forgetfull command line

January 14, 2009

Problem:
I am lucky to work with a few people who’s knowledge of computing is vast. I am always learning new things one can do at the command line. Unfortunately once typed, their details have instantly left my mind. This is a source of great frustration both for me and them. It is not feasible to make notes on what worked and why at the time. When I next want to do it, guaranteed its not in my bash history.

Solution:
I have knocked up this python script that allows me to log the last command with and optional comment in a separate file to my history so that i can review the dust after it has settled:

pyhs:

#!/usr/bin/python
import sys

argc = len(sys.argv)

if not((argc == 2 ) or (argc == 3)):
print “usage is: history 2 | hs logfile “
sys.exit()

if argc == 3:
comment = ” #”+sys.argv[2]+’\n’
else:
comment=’\n’

l = sys.stdin.readline()
f = open(sys.argv[1],’a')
command = l.split(None,1)[1] # remove line number
command = command.rstrip(‘\n’) # remove trailing newline
f.writelines(command+comment)
f.close()

To use it, it is placed in my path ~/bin/pyhs
then in my .bashrc file the entry:

hs () { history 2 | pyhs ~/command_logs/rob “‘$1′” ;}

note the double-single….single-double quotes, these fix the argument passing….sort of . The inner quotes get passed maby someday ill fix this, but I doubt it.

Ps: Useage:

% cd spam
% ls
# ask somone a question
# get answer and try it
% mysql> GRANT ALL PRIVILEGES ON meat_db.* TO ‘lambchop@’localhost’ IDENTIFIED BY ‘ilikemooo’
#instantly forget the command – but its ok you can log it for later
% hs ‘how to changes the privaledges on the database’

Recursive cd ..

December 23, 2008

There are several projects i am currently working on that have deep directory trees. For example:

/home/tom/project/sr/svn.studentrobotics.org/slug/init-br/build_armeb/staging_dir/armeb-linux-uclibc/include/linux/spi

Ive found my self getting increasingly irritated by having to type variations on :

cd ../../../../..

So set about writing an alias to simplify this. After a little investigation, I discovered Bash functions and came up with this:

xs () { if [[ -z "${1}" ]]; then  cd ..; elif [ ! $(echo "$1" | grep -E "^[0-9]+$”) ]; then  echo ARG1 NAN; else for ((i=0;i<=$1 ;i+=1)); do  cd ..; done; fi }

By adding this line to your .bashrc file (or similar) the command xs (note its next to cd) allows one to travel up the directory tree, examples:

xs 5       -> cd ../../../../..

xs 2       -> cd ../..

xs         -> cd ..

Hope this is usefull to someone.

Easy Fedora Upgrade

December 21, 2008

For a long time i have had a phobia of updating and upgrading my operating system. I guess this is a hangover from the bad old days of windows where the customary 6 month total re-install was as fun as tooth extraction, and usually required just before a large deadline. I have two significant influences on the subject. Jeff appears to hold a similar view of the situation, with good reasoning – Computers are boring, why would you want to spend all your time admin-ing them when you could be building something. Rob, however, is constantly beating us to update and upgrade.

I decided I should upgrade my laptop before 25c3 next week , and so bit the proverbial bullet. After reading many posts and pages and how-to’s all prescribing different techniques, I discovered its actually very easy and quite painless.

So in summary:

su -

yum -y update

yum clean all

preupgrade # If you don’t all-ready have this, yum install preupgrade

Thats it, 4 lines, it takes about 5 min of actual time and then a few hours of downloading and crunching. I was able to keep working for the first few hours until reboot time (It asks politely). Then it crunches a while longer during the next boot (another hourish).

This worked on F9 and is currently crunching on F8

First steps

August 26, 2008

The cnc machine took its first steps today, well a motor waggled about under the power of emc running on linux.

Hopefully I can integrate everything and get a build of emc on something less crucial than my server and maby some opto isolation when i get back from france.