Dep-wait parser

One thing that's been bothering me since quite a while is the fact that apt and friends are not very verbose when things go wrong. Usually that's just fine; if a package can't be installed, there isn't much you can do about it anyway.

However, for those of us who have to maintain buildd machines, a message like the following is not very helpful:

ome packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
  kdelibs4-dev: Depends: kdelibs4c2a (= 4:3.5.9.dfsg.1-2) but it is not going tobe installed
                Depends: libarts1-dev (>= 1.5.0) but it is not going to be installed
                Depends: libavahi-qt3-dev (>= 0.4) but it is not going to be installed
                Depends: libopenexr-dev (>= 1.2.2-3) but it is not going to be installed
                Depends: libqt3-mt-dev (>= 3:3.3.5) but it is not going to be installed
E: Broken packages

If you're not convinced, let me tell you that the culprit is libopenexr2ldbl. If you've noticed that libopenexr2 is not mentioned anywhere in the above output, you understand why I hate this. Usually, figuring out this stuff requires you to manually walk the dependency tree, which is silly. So today, I finally spent some time to sit down and write a couple of perl scripts to help me with that:

wouter@country:~/code/perl$ ./cache-packages Packages 
Reading data... done (20492 packages). Closing cache... ready. Have a nice day!
wouter@country:~/code/perl$ ./check-dep-waits 
kdelibs4-dev
checking dependencies of kdelibs4-dev
 checking dependencies of kdelibs4c2a (= 4:3.5.9.dfsg.1-2)
   checking dependencies of kdelibs-data (>> 4:3.5.9.dfsg.1)
[... copious output snipped ...]
  checking dependencies of  libopenexr2ldbl (>= 1.2.2)
libopenexr2ldbl is not available in any version

So, there. Obviously the "Packages" file in the first command line above came from a Debian mirror. The "cache-packages" script writes a file "~/.packages-dbm", which contains an MLDBM tiehash of all the packages, indexed on package name. If you have no clue what that means, just remember that it parses the Packages file into something my laptop can load in a split-second rather than requiring 45 seconds to open and parse the Packages file. Once you've ran that, you can call 'check-dep-waits' as many times as you want, that is, until the Packages file is outdated and you need to download a new one.

The second command will just sit and wait. On the first line, you give it a piece of Depends: information, and it will parse that and see whether the dependency can be resolved. There's a lot of output; but given how I want to verify dependencies, I thought I'd rather have too much than too little information. If there are version numbers involved, this script will call dpkg --compare-versions to do the actual verification, so I don't have to watch policy for any possible changes, which is helpful; but it does mean that it'll only work on a Debian machine.

The code is available for download at http://comp.uter.be/perl-Packages, FTWCA buildds.

Update: While on the train, I realized that I'd totally forgotten about virtual packages. That's now been fixed; if you downloaded the code before, you may want to re-fetch it...