debian.debian_support module

Facilities to deal with Debian-specific metadata

class debian.debian_support.AptPkgVersion(version: str | BaseVersion | None)

Bases: BaseVersion

Represents a Debian package version, using apt_pkg.VersionCompare

_compare(other: Any) int
class debian.debian_support.BaseVersion(version: str | BaseVersion | None)

Bases: object

Base class for classes representing Debian versions

It doesn’t implement any comparison, but it does check for valid versions according to Section 5.6.12 in the Debian Policy Manual. Since splitting the version into epoch, upstream_version, and debian_revision components is pretty much free with the validation, it sets those fields as properties of the object, and sets the raw version to the full_version property. A missing epoch or debian_revision results in the respective property set to None. Setting any of the properties results in the full_version being recomputed and the rest of the properties set from that.

It also implements __str__, just returning the raw version given to the initializer.

_compare(other: Any) int
_set_full_version(version: str) None
_update_full_version() None
magic_attrs = ('full_version', 'epoch', 'upstream_version', 'debian_revision', 'debian_version')
re_valid_version = re.compile('^((?P<epoch>\\d+):)?(?P<upstream_version>[A-Za-z0-9.+:~-]+?)(-(?P<debian_revision>[A-Za-z0-9+.~]+))?$')
class debian.debian_support.NativeVersion(version: str | BaseVersion | None)

Bases: BaseVersion

Represents a Debian package version, with native Python comparison

_compare(other: Any) int
classmethod _order(x: str) int

Return an integer value for character x

classmethod _version_cmp_part(va: str, vb: str) int
classmethod _version_cmp_string(va: str, vb: str) int
re_all_digits_or_not = re.compile('\\d+|\\D+')
re_alpha = re.compile('[A-Za-z]')
re_digit = re.compile('\\d')
re_digits = re.compile('\\d+')
class debian.debian_support.PackageFile(name: str, file_obj: TextIO | BinaryIO | None = None, encoding: str = 'utf-8')

Bases: object

A Debian package file.

Objects of this class can be used to read Debian’s Source and Packages files.

_aux_read_line() str
raise_syntax_error(msg: str, lineno: int | None = None) NoReturn
re_continuation = re.compile('^\\s+(?:\\.|(\\S.*?)\\s*)$')
re_field = re.compile('^([A-Za-z][A-Za-z0-9-_]+):(?:\\s*(.*?))?\\s*$')
exception debian.debian_support.ParseError(filename: str, lineno: int, msg: str)

Bases: Exception

An exception which is used to signal a parse failure.

Attributes:

filename - name of the file lineno - line number in the file msg - error message

print_out(file: TextIO) None

Writes a machine-parsable error message to file.

class debian.debian_support.PseudoEnum(name, order)

Bases: object

A base class for types which resemble enumeration types.

class debian.debian_support.Release(name, order, version='')

Bases: PseudoEnum

Debian release defined with respect to its name, order of release and version. The latter can be empty in case of ‘sid’.

See https://www.debian.org/releases/

releases: Dict[str, Release] = {'bo': Release('bo'), 'bookworm': Release('bookworm'), 'bullseye': Release('bullseye'), 'buster': Release('buster'), 'buzz': Release('buzz'), 'etch': Release('etch'), 'forky': Release('forky'), 'hamm': Release('hamm'), 'jessie': Release('jessie'), 'lenny': Release('lenny'), 'potato': Release('potato'), 'rex': Release('rex'), 'sarge': Release('sarge'), 'sid': Release('sid'), 'slink': Release('slink'), 'squeeze': Release('squeeze'), 'stretch': Release('stretch'), 'trixie': Release('trixie'), 'wheezy': Release('wheezy'), 'woody': Release('woody')}
class debian.debian_support.Version(version: str | BaseVersion | None)

Bases: AptPkgVersion

debian.debian_support.download_file(remote: str, local: str) List[str]

Copies a gzipped remote file to the local system.

remote - URL, without the .gz suffix local - name of the local file

debian.debian_support.download_gunzip_lines(remote: str) List[str]

Downloads a file from a remote location and gunzips it.

Returns the lines in the file.

debian.debian_support.intern_release(name: str, releases: Any | None = None) Any
debian.debian_support.merge_as_sets(*args)

Create an order set (represented as a list) of the objects in the sequences passed as arguments.

debian.debian_support.patch_lines(lines: List, patches: Iterable[Tuple[int, int, List]]) None

Applies patches to lines. Updates lines in place.

debian.debian_support.patches_from_ed_script(source: Iterable, re_cmd: Pattern | None = None) Iterator[Tuple[int, int, List]]

Converts source to a stream of patches.

Patches are triples of line indexes:

  • number of the first line to be replaced

  • one plus the number of the last line to be replaced

  • list of line replacements

This is enough to model arbitrary additions, deletions and replacements.

debian.debian_support.read_lines_sha1(lines: List[bytes] | List[str]) str
debian.debian_support.read_lines_sha256(lines: List[bytes] | List[str]) str
debian.debian_support.replace_file(lines: List[str], local: str, encoding: str = 'UTF-8') None
debian.debian_support.update_file(remote: str, local: str, verbose: bool = False) List[str]

Updates the local file by downloading a remote patch.

Returns a list of lines in the local file.

debian.debian_support.version_compare(a: Any, b: Any) int