Skip to main content

Python Warts, part 1 - pointless modules

Ian Bicking has inspired me to start keeping track of the little things in Python annoy me a little bit whenever I run into them. They don't really get in the way of development, but it would be nice if I didn't have to deal with them at all :) Maybe I'm just slow, but I didn't know about the os.statvfs() method until just yesterday. Up until then I've been parsing the output of 'df -k /mnt/drive' to find out how much free space a drive has! Of course, os.statvfs() is pretty much useless by itself. Try it out: import os os.statvfs(".") (4096, 4096, 19107656L, 2773425L, 1802799L, 9715712L, 8529635L, 8529635L, 0, 255) Great. What does that mean? Oh, I need the import the statvfs module to be able to usefully interpret this data. This module contains nothing other than a set of constants that index into the above tuple. So to get the free disk space, I would do something like: import os, statvfs s = os.statvfs(".") freebytes = s[statvfs.F_BSIZE] * s[statvfs.F_BAVAIL] Note that I'm not sure if statvfs.F_BSIZE or statvfs.F_FRSIZE is the proper entry to use. And the python documentation doesn't clear it up for me. There are really two things that bug me about this. The first is that the only reason for the statvfs module's existence is to make the os.statvfs() function useful. I would prefer that os.statvfs() returned a dictionary with meaningful keys, or an object with meaningful attributes. The stat module is another violator; it exists to make os.stat() useful. The second thing that bothers me is that I don't really think something like os.statvfs() is the best way to be calculating the free disk space in Python. Maybe I'll rant about this more in a future post, but functions and modules in Python that exactly mirror the underlying C library bug me. Sure, there may be times when you need access to the raw system call, but I can imagine that many people just want to know how much free space there is in a certain directory. Something along the lines of os.freespace(dir) would be a welcome addition to the standard library.

The things we take for granted

Friends of Melissa and I are currently in Malawi working for Canadian Physicians for Aid and Relief (CPAR). Tess's recent post about the state of medicine in Malawi is pretty scary. We are very very very blessed here in Canada where we do not have to worry about diseases like malaria, where our children have excellent chances of living past their fifth birthday, and the average person can expect to live into his 70's. We live in a society of abundance, of plenty; sometimes of over-abundance and excess. Testimonies like Tess' remind me that I really need to be more generous to those less fortunate.

Wordpress 2.0.1 released...

... with a few bug fixes. But what I'd really like to see is the ability to save a page (as opposed to a post) as a draft. I never get things right the first time so I like to write something, then come back to it a bit later. Luckily I'm not the only one who thinks this way! See Wordpress bugs #2194 and #1820


Hate it when you write a big long commit message in subversion, and then the commit fails for some reason and you have to commit again? Tired of reading in the aborted commit log message into new commit log? Can't remember what subversion calls the aborted log messages? Me too. So I wrote this little plugin for vim that will look in the current directory for any aborted subversion commit logs. It will pick the newest one, and read that in. Just put this script into ~/.vim/ftplugin and name it something starting with "svn" and you should be good to go!

" SVN aborted commit log reader

" Reads in the newest svn-commit.tmp log in the current directory

" (these get left behind by aborted commits)


" Written by Chris AtLee 

" Released under the GPLv2

" Version 0.2

function s:ReadPrevCommitLog()
    " Get the newest file (ignoring this one)
    let commitfile = system("ls -t svn-commit*.tmp | grep -v " . bufname("%") . " | head -1")
    " Strip off trailing newline
    let commitfile = substitute(commitfile, "\\s*\\n$", "", "")
    " If we're left with a file that actually exists, then we can read it in
    if filereadable(commitfile)
        " Read in the old commit message
        "echo "Reading " . commitfile
        silent exe "0read " . commitfile

        " Delete everything from the first "^--This line" to the last one
        normal 1G
        let first = search("^--This line", "")
        normal G$
        let last = search("^--This line", "b") - 1

        if last > first
            silent exe first . "," . last . "d"
        normal 1G
        set modified

call s:ReadPrevCommitLog()


distcc is a simple distributed compiler system Avahi is a framework for multicast DNS service discovery. Together, they are better than peanut butter and chocolate...Or peas and carrots...Or something. Back in November Lennart Poettering posted to the avahi mailing list with a patch that would add zeroconf support into distcc using the avahi framework.  I tried applying it at the time, but I couldn't get avahi working on my machine. Fast forward to the present (Jan. 2005).  The patch applies cleanly, and works pretty much out of the box!  I've made my changes available online here: Hopefully this can find its way into the main Debian archives soon.  There's already a bug report for it (bug #287832)

Farewell ICQ

For those of you who used to chat with me via ICQ and are wondering where I've disappeared to, I'm still alive. I've just stopped logging on because I've been getting way too many spam messages, with apparently no way to prevent them. You can reach me on MSN, my screen name is the same as my e-mail address.

splittar version 0.1

I've just uploaded my first version of splittar - a small utility that will create tar files for you, but limit the size of each one. I wrote this because I couldn't find anything that would generate tar files of a certain size for me, and splitting one giant tar file isn't acceptable to me because that means in order to recover any data out of the piece, you need all of them assembled back into the original file...Which can mean several tens of gigabytes for me. You can check it out at


What is it? splittar is a small utility written in Python. It will create multiple tar files from a set of data with each tar file being limited in size. This is useful for archiving data onto removable media such as CD or DVD. Other solutions that I've found rely on splitting one giant tar file, rendering all but the first tar files useless on its own. With splittar each file that is created is a valid tar file that is useful on its own. Where do I get it? Download it here: You'll also need Python version 2.4 installed. How do I install it? If you downloaded the .tar.gz version, running install should do the trick, although this won't install man pages. If you downloaded the .deb version, then running dpkg -i splittar_0.2_all.deb should work How do I use it? An example is probably the best way to get started. splittar -f outputfile.tar.gz -m CD $HOME This will create files called outputfile-1.tar.gz, outputfile-2.tar.gz, etc., each at most 700 MB in size, from the files in $HOME. See the man page for more information.