debian.debfile module

Representation of Debian binary package (.deb) files

Debfile Classes

class debian.debfile.DebControl(member: debian.arfile.ArMember)

Bases: debian.debfile.DebPart

debcontrol()debian.deb822.Deb822

Return the debian/control as a Deb822 (a Debian-specific dict-like class) object.

For a string representation of debian/control try .get_content(‘control’)

md5sums(encoding='None', errors='None')
md5sums(encoding, errors='None')

Return a dictionary mapping filenames (of the data part) to md5sums. Fails if the control part does not contain a ‘md5sum’ file.

Keys of the returned dictionary are the left-hand side values of lines in the md5sums member of control.tar.gz, usually file names relative to the file system root (without heading ‘/’ or ‘./’).

The returned keys are Unicode objects if an encoding is specified, otherwise binary. The returned values are always Unicode.

scripts() → Dict[str, bytes]

Return a dictionary of maintainer scripts (postinst, prerm, …) mapping script names to script text.

class debian.debfile.DebData(member: debian.arfile.ArMember)

Bases: debian.debfile.DebPart

exception debian.debfile.DebError

Bases: debian.arfile.ArError

class debian.debfile.DebFile(filename: Optional[str] = None, mode: str = 'r', fileobj: Optional[BinaryIO] = None)

Bases: debian.arfile.ArFile

Representation of a .deb file (a Debian binary package)

DebFile objects have the following (read-only) properties:
  • version debian .deb file format version (not related with the

    contained package version), 2.0 at the time of writing for all .deb packages in the Debian archive

  • data DebPart object corresponding to the data.tar.gz (or

    other compressed or uncompressed tar) archive contained in the .deb file

  • control DebPart object corresponding to the control.tar.gz (or

    other compressed tar) archive contained in the .deb file

__updatePkgName() → None
changelog() → Optional[debian.changelog.Changelog]

Return a Changelog object for the changelog.Debian.gz of the present .deb package. Return None if no changelog can be found.

close() → None
property control
property data
debcontrol()debian.deb822.Deb822

See .control.debcontrol()

md5sums(encoding='None', errors='None')
md5sums(encoding, errors='None')

See .control.md5sums()

scripts() → Dict[str, bytes]

See .control.scripts()

property version
class debian.debfile.DebPart(member: debian.arfile.ArMember)

Bases: object

‘Part’ of a .deb binary package.

A .deb package is considered as made of 2 parts: a ‘data’ part (corresponding to the possibly compressed ‘data.tar’ archive embedded in a .deb) and a ‘control’ part (the ‘control.tar.gz’ archive). Each of them is represented by an instance of this class. Each archive should be a compressed tar archive although an uncompressed data.tar is permitted; supported compression formats are: .tar.gz, .tar.bz2, .tar.xz .

When referring to file members of the underlying .tar.gz archive, file names can be specified in one of 3 formats “file”, “./file”, “/file”. In all cases the file is considered relative to the root of the archive. For the control part the preferred mechanism is the first one (as in deb.control.get_content(‘control’) ); for the data part the preferred mechanism is the third one (as in deb.data.get_file(‘/etc/vim/vimrc’) ).

__normalize_member() → str

try (not so hard) to obtain a member file name in a form relative to the .tar.gz root and with no heading ‘.’

close() → None
get_content(fname, encoding='None', errors='None')
get_content(fname, encoding, errors='None')

Return the string content of a given file, or None (e.g. for directories).

If encoding is given, then the content will be a Unicode object; otherwise, it will contain binary data.

get_file(fname, encoding='None', errors='None')
get_file(fname, encoding, errors='None')

Return a file object corresponding to a given file name.

If encoding is given, then the file object will return Unicode data; otherwise, it will return binary data.

has_file(fname: str) → bool

Check if this part contains a given file name.

tgz() → tarfile.TarFile

Return a TarFile object corresponding to this part of a .deb package.

Despite the name, this method gives access to various kind of compressed tar archives, not only gzipped ones.

debian.debfile.overload(f)