debian.debfile module¶
Representation of Debian binary package (.deb) files
Debfile Classes¶
- class debian.debfile.DebControl(member: ArMember)¶
 Bases:
DebPart- debcontrol() DebControl¶
 Return the debian/control as a deb822.DebControl (a Debian-specific dict-like class) object.
For a string representation of debian/control try .get_content(‘control’)
- md5sums(encoding: Literal[None] = None, errors: str | None = None) Dict[bytes, str]¶
 - md5sums(encoding: str, errors: str | None = None) Dict[str, str]
 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.DebFile(filename: str | Path | None = None, mode: str = 'r', fileobj: BinaryIO | None = None)¶
 Bases:
ArFileRepresentation 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() Changelog | None¶
 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: DebControl¶
 
- debcontrol() DebControl¶
 See .control.debcontrol()
- md5sums(encoding: Literal[None] = None, errors: str | None = None) Dict[bytes, str]¶
 - md5sums(encoding: str, errors: str | None = None) Dict[str, str]
 See .control.md5sums()
- scripts() Dict[str, bytes]¶
 See .control.scripts()
- property version: bytes¶
 
- class debian.debfile.DebPart(member: 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 that is stored in the .tar.gz, i.e. starting with ./
- __resolve_symlinks(path: str) str | None¶
 walk the path following symlinks
- returns:
 resolved_path, info
if the path is not found even after following symlinks within the archive, then None is returned.
- close() None¶
 
- get_content(fname: str | Path, encoding: Literal[None] = None, errors: str | None = None, follow_symlinks: bool = False) bytes | None¶
 - get_content(fname: str | Path, encoding: str, errors: str | None = None, follow_symlinks: bool = False) str | 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.
If follow_symlinks is True, then symlinks within the archive will be followed.
- get_file(fname: str | Path, encoding: None = None, errors: str | None = None, follow_symlinks: bool = False) IO[bytes]¶
 - get_file(fname: str | Path, encoding: str, errors: str | None = None, follow_symlinks: bool = False) IO[str]
 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.
If follow_symlinks is True, then symlinks within the archive will be followed.
- has_file(fname: str | Path, follow_symlinks: bool = False) bool¶
 Check if this part contains a given file name.
Symlinks within the archive can be followed.
- tgz() 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.
- class debian.debfile._NormedFilePath¶
 Bases:
strFile path class for squashing ./ at the start of files for TarFile
This class only replaces the __eq__ method of the file path comparison so that “./” is always added to the start of the file path meaning that “is this the right file to extract” will be true when the code asks for “./control” but the control.tar member contains the file “control”
- class debian.debfile._NormedTarInfo(name='')¶
 Bases:
TarInfoTarInfo replacement that uses file path comparison that squashes ./
This class uses the above _NormedFilePath class for file paths when iterating or inspecting the members of a TarFile. The _NormedFilePath normalises the file path when inspecting or extracting from a .deb file.
The class replaces the ‘name’ member that is normally a str with a property that addresses a _NormedFilePath.
The control tarball members of the .deb may contain an optional entry for “.” and prefix all entries in the tarball with “./”. Archives generated by dpkg have this prefix but third party tools might not. The published spec for the .deb file format, deb(5) from dpkg-dev, explicitly permits this difference and thus it should be supported here.
See https://bugs.debian.org/1031674 for more detail.
- _get_name() str | None¶
 
- _link_target¶
 
- _name: str | None = None¶
 
- _set_name(name: str) None¶
 
- _sparse_structs¶
 
- _tarfile¶
 
- chksum¶
 Header checksum.
- devmajor¶
 Device major number.
- devminor¶
 Device minor number.
- gid¶
 Group ID of the user who originally stored this member.
- gname¶
 Group name.
- linkname¶
 Name of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.
- mode¶
 Permission bits.
- mtime¶
 Time of last modification.
- name¶
 Name of the archive member.
- offset¶
 The tar header starts here.
- offset_data¶
 The file’s data starts here.
- pax_headers¶
 A dictionary containing key-value pairs of an associated pax extended header.
- size¶
 Size in bytes.
- sparse¶
 Sparse member information.
- type¶
 File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.
- uid¶
 User ID of the user who originally stored this member.
- uname¶
 User name.