Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dpkg Python module?

I'm trying to do some package manipulation (a la dpkg) and while I can just popen or subprocess.call I'd rather do things the python way if possible.

Unfortunately I've been unable to find a python module to do the trick.

I've seen reference to python-deb but it appears to be defunct. python-apt might seem like a potential solution, but AFAICT it cannot handle individual .deb files.

Anyone know of a good dpkg python solution?

like image 409
Catskul Avatar asked Jul 30 '12 18:07

Catskul


2 Answers

Actually, python-apt allows you to work with these files directly. Here's an example:

from apt.debfile import DebPackage
from pprint import pprint
pkg = DebPackage('/tmp/wajig_2.7_all.deb')
pprint(pkg.filelist)

Output:

$ ./script.py
['./',
 'etc/',
 'etc/bash_completion.d/',
 ...
 'usr/bin/',
 'usr/bin/wajig']

It's not as complete as I would like sadly, but it has a bunch of functionality.

(more info)

like image 94
tshepang Avatar answered Sep 19 '22 02:09

tshepang


Python-apt is probably the canonical way of doing this, but if you require the ability to work on non-debian platforms, I've released an early version of a native reimplementation of some parts of it:

https://github.com/memory/python-dpkg

like image 43
Doctor Memory Avatar answered Sep 21 '22 02:09

Doctor Memory