What the APT?

I've been playing around with the debian-cd package recently for ProLinux, turns out the Debian build process is a little antiquated and written for the larger part in Perl.

As a result (mainly of the latter), I'm in the process of re-writing the entire procedure in Python and have come across many optimisations, but the biggest revelation is a package called python-apt. Previously I'd see the python dpkg tools package, but python-apt is a new one on me - and it's very handy.

Consider the question; "I'd love to know which package installed 'that' file" or more to the point, "which packages contain 'that' file", here's a very easy answer.

import apt,sys
db = apt.cache.Cache()
for pkg in db.keys():
	words = pkg.split(":")
		package = db[words[0]]
		for item in package.installed_files:
			words = item.split("/")
			if sys.argv[1] in words: print(pkg,item)

If you run this and pass say "xterm.faq.gz" as a parameter, you'll get something like this;

# ./what.py xterm.faq.gz
xterm /usr/share/doc/xterm/xterm.faq.gz
xterm:i386 /usr/share/doc/xterm/xterm.faq.gz

You can do lots of other cool things with dependencies etc, but ultimately it condenses the install process into a couple hundred lines of Python and all the Makefiles, Perl and Bash go out the window.

It seems you can get a Python package to do pretty mich anything for you .. although I'm still looking for the python-coffee package .. maybe one day ...