pydebcontents: Searching Debian Contents files
Package repositories published by Debian (and its derivatives) have lots of different index files describing the Releases, Packages, Sources, and the file Contents of the packages. The Debian wiki has a full description of the repository format.
Access to the data within the Release, Packages, and Sources files is provided by the python-debian module, available within the Debian archive and from PyPI.
This module provides access to the Contents files.
Requirements
This module requires no Python modules outside of stdlib.
Searching the Contents files is, however, dependent on the external zgrep program being on your PATH; zgrep is used to transparently search the gzip-compressed Contents.gz files.
The Contents files need to be arranged as they would be found on a Debian mirror:
dists/{release}/{component}/Contents-{arch}.gz.
Users of the apt-cacher-ng package might like to use its local file cache for access to the Contents files in the expected format.
Installation
From PyPI:
pip install pydebcontents
From git:
git clone https://salsa.debian.org/debian-irc-team/pydebcontents
cd pydebcontents
pip install .
Usage
The module comes with a simple command-line interface that feels a bit like the standard apt-file program.
For example, to find all the README files shipped in packages:
py-apt-file --base /var/cache/apt-cacher-ng/debrep/ search --mode glob usr/share/doc/*/README
The only verb that py-apt-file knows at present is search.
$ py-apt-file search --help
usage: py-apt-file search [-h] [--release RELEASE] [--arch ARCH] [--component COMP] [--mode {glob,regex,fixed}]
[--max MAX]
PATTERN
positional arguments:
PATTERN glob, regular expression or fixed string
options:
-h, --help show this help message and exit
--release RELEASE release to search (default: sid)
--arch ARCH, --architecture ARCH
architecture to search (default: amd64)
--component COMP archive components to search (default: all of them)
--mode {glob,regex,fixed}
match mode for pattern
--max MAX maximum number of packages to return
From Python, the module can be used as:
import pydebcontents
contents = pydebcontents.ContentsFile("/var/cache/apt-cacher-ng/debrep/", "sid", "amd64", ["contrib"])
contents.search("usr/share/doc/.*/README")
A ContentsDict structure is returned, which is a dict where the
keys are package entries (in the {section}/{package} format used in the Contents files), and the values are lists of matching filenames.
The search term that ContentsFile.search uses is a str representation of a regular expression.
There are convenience functions in pydebcontents for handling search patterns, including navigating some of the foibles of zgrep and the Contents file format:
glob2reconverts glob syntax to regular expressionfixed2reconverts a fixed string into a regular expressionre2recleans up an existing regular expressionpattern2reis for programmatic use in selecting one of the above three functions.
To-do list / limitations
- A previous attempt at a Python-only implementation was too slow to be usable for searching the Contents files; this could be revisited.
- The mirrors are now carrying other compression formats such as
xzthat will not be found or used at present. - There is no utility provided to obtain the Contents files and arrange them on disk in a suitable tree.
- There is no ability to simply point at a Contents file on-disk that is not in the desired tree format.
Metadata
Release files for pydebcontents 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydebcontents-0.3.1.tar.gz | 12.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydebcontents-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.0 kB
Release files / pydebcontents-0.3.1.tar.gz
| Download URL | pydebcontents-0.3.1.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1fe3a8de2eb140d92b33f87d23c45908777004121feaa3a1fe2362449b58c46
|
|
BLAKE2b-256 checksum How to use checksums |
02d2b876e7b68a0ae424842f425a0fb946b855a9933f1f9fc6143b15be12f602
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / pydebcontents-0.3.1-py3-none-any.whl
| Download URL | pydebcontents-0.3.1-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66046376c625e08eff59f2b4de52833328a93e6e1d41c3f0964b0d6772de03e6
|
|
BLAKE2b-256 checksum How to use checksums |
fadb9da949ceda90e21b2a8f73c6ef43f52354f0adcfa8ccaf054ddf7439af8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for pydebcontents 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.