Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query and manage Debian package repositories in Python?

Tags:

python

debian

apt

I want to be able to look at local .deb files and at remote repositories and deduce dependencies etc so that I can build my own repositories and partial mirrors (probably by creating config files for reprepro).

The challenge is that many of the command-line tools to help with this (apt-rdepends etc) assume that you're running on the target system and make use of your local apt cache, whereas I'll often be handling stuff for different Ubuntu and Debian distributions from the one I'm currently running on, so I'd like to do this a bit more at arm's length.

The capable but very poorly-documented python-apt packages let me examine .deb files on the local filesystem and pull out dependencies. I'm now wondering if there are similar tools to parse the Packages.gz files from repositories? (It's not too tricky, but I don't want to reinvent the wheel!)

The overall goal is to create and maintain two repositories: one with our own packages in, and a partial mirror of an Ubuntu distribution with some known required packages plus anything that they, or our own ones, depend upon.

like image 223
Quentin Stafford-Fraser Avatar asked Nov 23 '22 23:11

Quentin Stafford-Fraser


1 Answers

A very effective way is to create local apt caches for all the relevant distributions. The tool chdist from the devscripts package allows you to create a number of these caches without the need to use root privileges. You can then use the tools you are used to (e.g. apt-rdepends) to query those caches by wrapping them up in chdist. You can even point python-apt at your local cache using the rootdir keyword argument to apt.cache.Cache where you can then resolve dependencies.

like image 136
Helmut Grohne Avatar answered Nov 26 '22 18:11

Helmut Grohne