Monthly Archives: June 2009

Python and SWIG: local variable ‘_mod’ referenced before assignment

I was doing some stuff that requires importing C++ libraries to use in Python, and that error came up.

I’m using Stackless, so I first thought that was the case. Eventually it turned out to be related to the build configuration of the program I was compiling, FIFE.

The thing here is, SWIG generated a wrapper for that library that had a bad. It was at the very top of the wrapper file (

8  from sys import version_info
9  if version_info >= (2,6,0):
10     def swig_import_helper():
11         from os.path import dirname
12         import imp
13         fp = None
14         try:
15             fp, pathname, description = imp.find_module('_fife', [dirname(__file__)])
16         except ImportError:
17             import _fife
18             return _fife
19         if fp is not None:
20             try:
21                 _mod = imp.load_module('_fife', fp, pathname, description)
22             finally:
23                 fp.close()
24                 return _mod
25     _fife = swig_import_helper()
26     del swig_import_helper
27 else:
28     import _fife
29 del version_info

The bad thing here is that there’s no “except:” where it should be. When I added one on line 22, it caught an exception. Technically, the exception should be passed to a higher-level “try:” (on line 14). However:

1. “finally:” is executed in all cases, exception or no exception.
2. The upper-level “try:” doesn’t have a default exception handler.

I didn’t dig deeper into this, because I have no time at the moment.

Default Netkit root password

Is ‘root’.

Dumping audio from video file

See here.

So I just use:

mplayer -dumpaudio <source> -dumpfile <destination>

It’s always useful to see beforehand what the format of audio in the source is.

Copying an audio CD in ArchLinux

dd didn’t work. This thread was most helpful:

So I used cdrdao, like this:

dmesg | grep scsi # find CD-ROM's SCSI "bus address"
cdrdao copy --device 1,0,0

Stackless-Python in Netkit VM

I needed to do this, since I’m running a x86_64 machine, and netkit emulates a 32-bit one. Thus external programs cannot be run inside Netkit, which, surprise, is also a security feature.

1. Install netkit:

# yaourt netkit

2. Use the second method described in the Netkit FAQ to update packages in the VM image:

# mkdir /mnt/nkft
# mount -o loop,offset=32768 $NETKIT_HOME/fs/netkit-fs /mnt/nkfs
# chroot /mnt/nkfs

3. Install the build tools:

# apt-get install gcc g++ make automake autoconf libc6-dev binutils

4. Then proceed with Stackless (there seems to be no Debian package yet). First, install dependencies:

# apt-get install bzip2 openssl


# wget
# tar xf stackless-262-export.tar.bz2
# cd stackless-2.6.2

;; I tried building specifying “–with-threads –enable-shared” to
;; configure and it didn’t work, with “PIC register ebx clobbered in asm”.
;; Adding “–stackless-fewerregisters” might help if
;; you really need that. Thanks to Lloyd Weehuizen.
# ./configure --prefix=/usr
# make
# make install

5. After all goes well, as it always does, press CTRL+D. Then:

# umount /mnt/nfks

Simple script to see file sizes

# directory size - show it

import os, sys

if len(sys.argv) < 2:
    os.system("du -sh *")
    print "-----"
    os.system("du -sh .")
    for arg in sys.argv[1:]:
        cmd = "du -sh \"%s\"" % arg

How to see Which process uses a particular file?

lsof – list open files.
fuser – show file user.

In *nix, of course.

Mesh routing stuff — olsrd — batman — babel

Mounting bin/cue files – nah, use ISO instead

It’s easier to mount ISOs.

1. Install bin2iso.
2. bin2iso
3. lsmod | grep loop, if not present, modprobe loop and add to rc.conf
4. mount -t iso9660 -o loop / /media/cd

Lighttpd in jailkit chroot environment

comment = LigHTTPd HTTP server
paths = /usr/sbin/lighttpd, /usr/sbin/lighttpd-angel, /usr/lib/lighttpd, /etc/lighttpd
emptydirs = /tmp, /srv/http, /var/log/lighttpd, /var/run/lighttpd
devices = /dev/urandom, /dev/null
users = http
groups = http
includesections = uidbasics, netbasics, logbasics

comment = PHP 5
paths = /usr/bin/php, /usr/bin/php-cgi, /usr/bin/cgi-fcgi, /usr/bin/spawn-fcgi, /etc/php
includesections = netbasics, logbasics

Permissions need to be changed in your jaildir.


(include file lost, sorry)