Getting the SVN revision number of a file in python

September 11th, 2008

I’m writing out data from python programs and it is important to have an audit trail.  I decided that I would write out the SVN revision number of the code generating the reports, into the reports.

Getting the svn revision number of a file is fairly straight forward in python:

os.popen('svn info %s | grep "Last Changed Rev" ' % fName, "r").readline().replace("Last Changed Rev:","")

that acutally returns a string with the revision number in it.

Thats a bit of code though, and I didn’t want it sprinkled, duplicated, all over my different python files

so I put it in my util library

in python, grabbing the name of the file you are working from is fairly straightforward:

__file__

however, since I was writing this in my utility library, I didn’t care about that file’s name, I wanted the name of the calling file.

I figured that out

fName = sys._getframe(1).f_code.co_filename

this gets the name of the file 1 call up the call stack

combining these I ended up with

def getSvnVersionOfFile(fName = sys._getframe(1).f_code.co_filename):
return os.popen('svn info %s | grep "Last Changed Rev" ' % Name, "r").readline().replace("Last Changed Rev:","")

Security Anomally in CoreGraphics Event Taps

September 4th, 2008

When I was playing around with changing modifier keys for OS X I stumbled onto some inconsistencies with permission requirements and abilities for two very similar event types.

The code I used here is modified from http://osxbook.com .  You can download it here  http://paddymullen.com/upload/securityAnomally.tar.gz
There are two programs included in the tar ball.  getKeyPressCode and insertKeyPressOnModifier.  They have a very similar structure.  I will start by describing getKeyPressCode

GetKeyPressCode has two functions, main and a call back function.  A call is made to CGEventTapCreate , which passes the myCGEventcallBack function in (I’m hazy on my c code,  it must somehow pass in a pointer), and event mask flags for the type of event, in this case kCGEventKeyDown or kCGEventKeyUp.
The callback in getKeyPressCode displays the keycode for any character you press, in any application on the system. If you press the = key, it replaces that with ‘f’ .
To run getKeyPressCode, you need to be superuser (sudo) or have Assistive devices enabled.  Otherwise the program will fail saying, event tap failed to create.  Also notice that when you go to a  systemwide password box (such as you would be prompted for in keychain) , no keyUp or keyDown events are fired, even though the program was run with superuser privileges.

The second program is insertKeyPressOnModifier.  This program has the same form, the difference is that it catches modifier keys — CGEventFlagsChanged.  This program displays the EventFlags for modifier keys (“CAPSLOCK” , “SHIFT”, “CTRL”, “OPTION”, “OPTION/ALT”, “APPLE”) when a modifier key is pressed.  When any modifier key is pressed, the program inserts an “=” or “+” depending on whether or not shift was pressed.  Again this behaviour takes place in any application on the system.

Now the interesting thing is, you don’t need superuser rights or assistive devices enabled to run insertKeyPressOnModifier.  Even more interesting is, inserKeyPressOnModifier still fires events when you are in a system wide password box, it will also insert ‘=’ characters.  This seems like a potential security hole.

I filed a bug report for this a year ago, apple hasn’t responded or fixed the hole.  This I have observed this behavior on a Mac Book Pro running Tiger and Leopard.  I’m not well versed in C, CoreGraphics, OS X internals, or general security measures like this.  There could be a very good explanation for the behavior, to me though, it seems like an inconsistency that could be a hole.  I haven’t seen the password box behavior mentioned anywhere else.

You can look at the header file for CGEvent on your mac here

/Developer/SDKs/MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/CoreGraphics/CGEvent.h

modding bs.el for emacs

August 6th, 2008

I use bs.el to switch between buffers in emacs.  I have bs-cycle-next mapped to C-Tab and bs-cycle-previous mapped to C-Shift-Tab .  The problem is when I quickly page through my buffers, the buffer list that shows up in the mini window rotates and the current buffer doesn’t show up in the list,

1-2-3-4-5 c-tab

2-3-4-5-6 c-tab

3-4-5-6-1
the position of buffers doesn’t remain the same, which makes it hard to quickly go to the desired buffer.  I wanted behaviour like this

(6) 1 2 3 4 5

6   (1)  2  3 4 5

6   1  (2)  3 4 5

With the included file, bs.el now behaves in the way I prefer.   This is the first serious lisp programming I have ever done, also the first mod I have made to emacs.

http://paddymullen.com/upload/try2-bsmods.el

TODO: figure out font-face-lock to get the current buffer highlighted instead of surrounded with pipes ||

I bought a 30 inch screen

June 29th, 2008

I should blog about this now, while the imprint is fresh in my head.

1. I am moving from a laptop to a Samsung 30 inch lcd

2. It is big, huge, the way you use the computer will change.

3. Moving from a laptop, you have to get an external keyboard, get one you like.  I’m typing this on my father’s iMac keyboard right now, it sucks.

4.  Bump up your mouse acceleration,  A mouse is necessary with this size screen, forget a trackpad, and even a mouse is innadequate.

5.  Window management on OS X is severely lacking.  I really want to get stumpwm working.

So far I like it.

Giving up the ghost, gracefully

May 4th, 2008

I recently have read a couple of posts about people gracefully putting their startups to bed.  I want to commend these brave writers.  It is incredibly hard to give up on a business venture, financially and emotionally, I should know I have done so twice.

I think it says so much for these people, Russ, Eran, and JB.  These are the types of people you want running software projects for your company.  I can’t count how many times I have seen managers refuse to put an end to projects that just aren’t going anywhere. Even when killing the project would be the best thing for the company, it is often not done because of pride or political factors.
It is hard to admit defeat, especially when you phrase it like that.  If however you look at it as an opportunity cost calculation, you can take a more optimistic view of the situation.  I believe the oportunity cost calculation is the proper way to look at decisions like these.  Say my startup is profitable, but just inching along, if I have the opportunity to join another more profitable venture, it is costing me the difference.  That difference is the opportunity cost.   I believe that for everyone in the list above, continuing their startup would have had a very high opportunity cost (they are very desirable employees).

smart people

March 29th, 2008

Derik: I would like a world where the smartest people run the government.

Me: I wouldn’t.  I wouldn’t want a world where we needed smart people to run the government.  I want a government that is so unimportant that I’m not tempted to waste smart people on it.

Axemen on the history channel

March 25th, 2008

This past weekend I caught the first two episodes of Axemen on this History Channel.  I really enjoyed it.  I used to work in heavy construction and I am still fascinated by it.  If you enjoy Axemen, check out this site, Van Natta Bros Logging.

The advertising club of New York

March 19th, 2008

Last night I went to the advertising club of new york meetup at Microsoft’s office, with my girlfriend. The meeting was focussed on advertising on mobile phones. I had been to one of these events before, at google, that event was ok. This event wasn’t, it was horrible.

To start with the audience was full of dead people. Most of the people in the audience were 35+ year olds who worked in traditional media advertising agencies. They were confused by basic internet advertising metrics. I don’t know how to explain it. The room was full of the type of business people that tech guys hate. Full of people who would say “Let’s do a facebook app” and then spend $1m to build it because they chose a slick manager who is incompetent.

One of the presenters, Dean Collins, presented his Amatheon’s mobile analytics software. Early in his presentation he had a slide that said something along the lines of ” Traditional analytics don’t work on mobile phones. You can’t tell which handset visitors are using. You can’t tell where they are coming from. You can’t tell what resolution they are using” he then said “Does anyone disagree?”. I raised my hand and answered “I do. The only browser in the mobile space that matters is the iPhone. And all of the traditional anayltics work on it”. He replied “I don’t care about the iPhone, its only 4% of the market and not what we are aiming for.”

I was embarrassed that I had attacked Dean so viciously. I think it was the way he challenged the audience, saying “does anyone disagree”, it just set me off. It is hard to get attacked when you are presenting to an audience. Given that, I feel that my statement was correct.

Collins went on detailing how his software provides analytics for the mobile space. He went on to describe his software pretty well, it looked impressive. The software also is inexpensive for what it does. The quality of their software aside, I think the working with amatheon would be helpful for a company, because amatheon knows the mobile analytics space.

The nvidia article that actually helped me

March 15th, 2008

http://www.ubuntugeek.com/how-to-fix-nvidia-acceleration-in-feisty-nvidia-8800-and-legacy-users.html

F1 is coming back

March 11th, 2008

Well it is 3 short days until practice starts in Australia I can’t wait.  Will be joining this fantasy formula 1 league with some of my friends.

Thinking about F1 my thoughts turned to Formula1db , my Formula 1 results database that I built a while ago.   The data is about to be three seasons out of date.  I’m strongly considering open sourcing it, possibly along with the php for the site too.  I might release the code for the python screen scraper too, if I can find it.