Category Archives: Programming

Learning Python: module import issues

So I’ve taken it upon myself to learn Python, which is something I’ve wanted to do for a while. I usually write code in PHP or shellscript, with the odd thing in Perl every once in a while (but I’m not a real big fan of perl and I don’t have the desire to dig into it more). A lot of my more sophisticated projects that can’t be done in shellscript are usually done with CLI PHP. But Python is something I’ve wanted to learn, so I’ve started digging into it and my first dive is rewriting a CLI PHP program “suite” that creates and scours a database for RPM information (dependencies, requires, files, etc.).

I’ve been at it for about 2 weeks now with what little time I have and the original suite consists of two programs: rqp and rqs. These two programs were a result of a rewrite of the “srpm” PHP program that Stew Benedict wrote years ago for the Mandriva secteam (and which has proven invaluable of the years). It handled only src.rpm files, so I rewrote and extended it to handle binary and source rpm files (rqp and rqs respectively). It was a quick-n-dirty extension that was used for a few years on the Mandriva secteam and worked really well (and probably is still working well for them).

I’ve gotten rqp converted to Python and it’s working quite well. Because rqp and rqs share a *lot* of functions, I wanted to write rqp.py and rqs.py and have a shared module between them (rq.py) and this is where I’m having issues. Does anyone know how to have a module get access to an object from the calling program? For instance, rqp uses the optparse module to nicely handle the commandline arguments, but a lot of the modules use options.foo to look up arguments that were passed. The functions in rq.py (the module) can’t seem to get the value of options, and while I could put the optparse stuff in the module, it would leave the actual rqp and rqs programs really really small (and I’d have to either put in two functions because the two programs use different syntax). So I’ve got in rqp.py:

import rq

which works ok, but if rq.db_connect() requires options.database (for instance), it can’t get it. So in rq.py, I tried doing a circular import or whatever it’s called by doing:

import options from rqp

But this doesn’t want to work either. The output looks quite sad:

% ./rqp.py -d
rqp 0.2 ($Id: rqp 275 2009-03-07 22:34:15Z vdanen $)

Traceback (most recent call last):
  File "./rqp.py", line 548, in 
    import rq
  File "/Users/vdanen/svn/scripts/rq/trunk/rq.py", line 11, in 
    from rqp import options
ImportError: cannot import name options

There has to be a way to make the options variable (and one or two others I think) accessible to the module, but I haven’t been able to find a way to do it. Does anyone know how this can be accomplished?

Check out subversion repositories with ViewVC

This week’s TechMail is Check out subversion repositories with ViewVC which is pretty much just about installing and configuring the ViewVC web-based tool to view subversion repositories (works with cvs too).

If programming languages were religions…

Found this really cute/funny blog post today about programming languages being religions, or the comparison of programming languages to religions (i.e. C being Judaism, Visual Basic being Satanism, etc.). Quite funny.

Here’s the link: If programming languages were religions….

Is the new Komodo 5 toolset worth the upgrade?

This week’s Techmail looks at some of the new features of ActiveState’s Komodo IDE and asks Is the new Komodo 5 toolset worth the upgrade?. Personally, I think it was. Others may or may not agree… someone else has already posted about using a “real” IDE (Eclipse). Gag me with a spoon.

Zsh tab completion with subversion 1.5

This has ticked me off for a bit, and I finally decided to find out why. Tab completion in zsh was returning the following every time I tried to use it, after upgrading to subversion 1.5:

_arguments:comparguments:303: invalid argument: ARG

Looks like the reason is that the subversion developers changed “arg” to “ARG”. So when I googled I found this helpful post:

ZSH Tab Completion Fix for Subversion 1.5 which basically points to this new _subversion functions file to be plopped into the zsh functions directory (/usr/share/zsh/4.3.4/functions; change the version to suit of course — the directory may also be slightly different on Linux vs OS X).

Now tab completion works properly and life is good. =)

Subversion 1.5.x upgrade oddities

Found some weirdness with subversion 1.5 today. I had previously upgraded to 1.5.1 when it came out (from 1.4.x) and found I couldn’t commit to svn+ssh urls. 1.5.2 fixes that, but has a naughty habbit of upgrading the repository format behind your back. So, if you have a working copy you checked out with 1.4.x and then do anything in that working copy it upgrades it to the new format for 1.5.x. Sadly, it doesn’t tell you it’s doing this and as a result, those working copies are essentially useless if you need to back out to 1.4.x for whatever reason.

Not only that, however, but subversion will upgrade parts of your working copy piecemeal. For instance, I keep all my web development stuff in ~/svn/websites/. So after upgrading to 1.5.2 today I did some work in ~/svn/websites/intranet/ and that directory, and it’s subdirectories, were upgraded to the new format. The top-level directory, however, and the rest of the working copy, were not (they were still using format 8 rather than format 9).

I guess with a CLI client this might not matter so much, but it caused me some grief using Cornerstone, a commercial svn client. Fortunately, the author is super-responsive and pointed me to this change-svn-wc-format.py script which I can use to update all my working copies (I’m not trusting subversion to do it properly for me right now).

Anyways, if anyone else gets in this same boat, here’s some info on how to resolve it. I like using Cornerstone on my mac (it’s about the only GUI svn client I can stand); otherwise I’d be using the CLI client and probably never would have found this.