Dpkg Python module?
Asked Answered
G

4

11

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?

Gerlac answered 30/7, 2012 at 18:2 Comment(0)
R
8

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)

Rarefied answered 30/7, 2012 at 23:20 Comment(2)
I noticed after digging into gdebi that it uses the functionality you're referring to, and then just does a popen to then run dpkg. Thanks.Gerlac
direct link to documentation of python-apt: apt-team.pages.debian.net/python-apt/library/index.htmlThermel
C
2

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

Catharina answered 7/3, 2017 at 2:9 Comment(0)
J
0

I have little familiarity with python modules for debs, but I wanted to point out that calling subprocesses isn't the bad thing on *ix, that it is on Windows. Windows almost seems intended to break calling things as a subprocess and parsing output, but *ix usually makes it quite viable.

Jointed answered 30/7, 2012 at 18:46 Comment(0)
G
0

Apparently Gdebi is python based. If gdebi installed you have access to it's functionality via the GDebi module.

I can't seem to find any documentation, so I'm not sure that it's meant to be a public API, but it might do the trick.

Gerlac answered 30/7, 2012 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.