daklib.utils

Utility functions

@contact: Debian FTP Master <ftpmaster@debian.org> @copyright: 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org> @license: GNU General Public License version 2 or later

Module Attributes

key_uid_email_cache

Cache for email addresses from gpg key uids

Functions

TemplateSubst(subst_map, filename)

Perform a substition of template

build_file_list(changes[, is_a_dsc, field, ...])

call_editor([text, suffix])

run editor and return the result as a string

call_editor_for_file(path)

check_dsc_files(dsc_filename, dsc, dsc_files)

Verify that the files listed in the Files field of the .dsc are those expected given the announced Format.

check_reverse_depends(removals, suite[, ...])

clean_symlink(src, dest, root)

Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.

deb_extract_control(path)

extract DEBIAN/control from a binary package

extract_component_from_section(section)

split "section" into "section", "component" parts

find_next_free(dest[, too_many])

find_possibly_compressed_file(filename)

param filename:

path to a control file (Sources, Packages, etc) to

fubar(msg[, exit_code])

print error message and exit program

get_changes_files(from_dir)

Takes a directory and lists all .changes files in it (as well as chdir'ing to the directory; this is due to broken behaviour on the part of p-u/p-a when you're not in the right place)

get_conf()

get_logins_from_ldap([fingerprint])

retrieve login from LDAP linked to a given fingerprint

get_users_from_ldap()

retrieve login and user names from LDAP

getusername()

get login name

gpg_get_key_addresses(fingerprint)

retreive email addresses from gpg key uids for a given fingerprint

gpg_keyring_args([keyrings])

input_or_exit([prompt])

is_in_debug_section(control)

binary package is a debug package

join_with_commas_and(list)

mail_addresses_for_upload(maintainer, ...)

mail addresses to contact for an upload

move(src, dest[, overwrite, perms])

move_to_morgue(morguesubdir, filenames, ...)

Move a file to the correct dir in morgue

open_ldap_connection()

open connection to the configured LDAP server

parse_args(Options)

Handle -a, -c and -s arguments; returns them as SQL constraints

parse_boolean_from_user(value)

parse_built_using(control)

source packages referenced via Built-Using

parse_changes(filename[, signing_rules, ...])

Parses a changes or source control (.dsc) file and returns a dictionary where each field is a key.

parse_deb822(armored_contents[, ...])

parse_wnpp_bug_file([file])

Parses the wnpp bug list available at https://qa.debian.org/data/bts/wnpp_rm Well, actually it parsed a local copy, but let's document the source somewhere ;)

poolify(source)

convert source name into directory path used in pool structure

pp_deps(deps)

prefix_multi_line_string(lines, prefix[, ...])

prepend prefix to each line in lines

process_buildinfos(directory, ...)

Copy buildinfo files into Dir::BuildinfoArchive

result_join(original[, sep])

send_mail(message[, whitelists])

sendmail wrapper, takes a message string

size_type(c)

split_args(s[, dwim])

Split command line arguments which can be separated by either commas or whitespace.

suite_suffix(suite_name)

Return suite_suffix for the given suite

temp_dirname([parent, prefix, suffix, mode, ...])

Return a secure and unique directory by pre-creating it.

warn(msg)

print warning message

whoami()

get user name

Classes

ArchKey(arch, *args)

Key object for use in sorting lists of architectures.

class daklib.utils.ArchKey(arch, *args)[source]

Key object for use in sorting lists of architectures.

Sorts normally except that ‘source’ dominates all others.

arch
issource
daklib.utils.TemplateSubst(subst_map: Mapping[str, str], filename: str) str[source]

Perform a substition of template

daklib.utils._gpg_get_addresses_from_listing(output: bytes) list[str][source]
daklib.utils.build_file_list(changes: Mapping[str, str], is_a_dsc: bool = False, field='files', hashname='md5sum') dict[str, dict[str, str]][source]
daklib.utils.call_editor(text: str = '', suffix: str = '.txt') str[source]

run editor and return the result as a string

Parameters:
  • text – initial text

  • suffix – extension for temporary file

Returns:

string with the edited text

daklib.utils.call_editor_for_file(path: str) None[source]
daklib.utils.check_dsc_files(dsc_filename: str, dsc: Mapping[str, str], dsc_files: Mapping[str, Mapping[str, str]]) list[str][source]

Verify that the files listed in the Files field of the .dsc are those expected given the announced Format.

Parameters:
Returns:

all errors detected

daklib.utils.check_reverse_depends(removals: Iterable[str], suite: str, arches: Optional[Iterable[Architecture]] = None, session=None, cruft: bool = False, quiet: bool = False, include_arch_all: bool = True) bool[source]

Relativize an absolute symlink from ‘src’ -> ‘dest’ relative to ‘root’. Returns fixed ‘src’

daklib.utils.deb_extract_control(path: str) bytes[source]

extract DEBIAN/control from a binary package

daklib.utils.extract_component_from_section(section: str) tuple[str, str][source]

split “section” into “section”, “component” parts

If “component” is not given, “main” is used instead.

Returns:

tuple (section, component)

daklib.utils.find_next_free(dest: str, too_many: int = 100) str[source]
daklib.utils.find_possibly_compressed_file(filename: str) str[source]
Parameters:

filename – path to a control file (Sources, Packages, etc) to look for

Returns:

path to the (possibly compressed) control file, or null if the file doesn’t exist

daklib.utils.fubar(msg: str, exit_code: int = 1) NoReturn[source]

print error message and exit program

daklib.utils.get_changes_files(from_dir: str) list[str][source]

Takes a directory and lists all .changes files in it (as well as chdir’ing to the directory; this is due to broken behaviour on the part of p-u/p-a when you’re not in the right place)

Returns a list of filenames

daklib.utils.get_conf()[source]
daklib.utils.get_logins_from_ldap(fingerprint: str = '*') dict[str, str][source]

retrieve login from LDAP linked to a given fingerprint

daklib.utils.get_users_from_ldap() dict[str, str][source]

retrieve login and user names from LDAP

daklib.utils.getusername() str[source]

get login name

daklib.utils.gpg_get_key_addresses(fingerprint: str) list[str][source]

retreive email addresses from gpg key uids for a given fingerprint

daklib.utils.gpg_keyring_args(keyrings: Optional[Iterable[str]] = None) list[str][source]
daklib.utils.input_or_exit(prompt: Optional[str] = None) str[source]
daklib.utils.is_in_debug_section(control: Mapping[str, str]) bool[source]

binary package is a debug package

Parameters:

control – control file of binary package

Returns:

True if the binary package is a debug package

daklib.utils.join_with_commas_and(list: Sequence[str]) str[source]
daklib.utils.key_uid_email_cache: dict[str, list[str]] = {}

Cache for email addresses from gpg key uids

daklib.utils.mail_addresses_for_upload(maintainer: str, changed_by: str, fingerprint: str) list[str][source]

mail addresses to contact for an upload

Parameters:
  • maintainer – Maintainer field of the .changes file

  • changed_by – Changed-By field of the .changes file

  • fingerprint – fingerprint of the key used to sign the upload

Returns:

list of RFC 2047-encoded mail addresses to contact regarding this upload

daklib.utils.move(src: str, dest: str, overwrite: bool = False, perms: int = 436) None[source]
daklib.utils.move_to_morgue(morguesubdir: str, filenames: Iterable[str], fs_transaction: FilesystemTransaction, logger: Logger)[source]

Move a file to the correct dir in morgue

Parameters:
  • morguesubdir – subdirectory of morgue where this file needs to go

  • filenames – names of files

  • fs_transaction – FilesystemTransaction instance

  • logger – logger instance

daklib.utils.open_ldap_connection()[source]

open connection to the configured LDAP server

daklib.utils.parse_args(Options) tuple[str, str, str, bool][source]

Handle -a, -c and -s arguments; returns them as SQL constraints

daklib.utils.parse_boolean_from_user(value: str) bool[source]
daklib.utils.parse_built_using(control: Mapping[str, str]) list[tuple[str, str]][source]

source packages referenced via Built-Using

Parameters:

control – control file to take Built-Using field from

Returns:

list of (source_name, source_version) pairs

daklib.utils.parse_changes(filename: str, signing_rules: Literal[-1, 0, 1] = 0, dsc_file: bool = False, keyrings=None) dict[str, str][source]

Parses a changes or source control (.dsc) file and returns a dictionary where each field is a key. The mandatory first argument is the filename of the .changes file.

signing_rules is an optional argument:

  • If signing_rules == -1, no signature is required.

  • If signing_rules == 0 (the default), a signature is required.

  • If signing_rules == 1, it turns on the same strict format checking as dpkg-source.

The rules for (signing_rules == 1)-mode are:

  • The PGP header consists of “—–BEGIN PGP SIGNED MESSAGE—–” followed by any PGP header data and must end with a blank line.

  • The data section must end with a blank line and must be followed by “—–BEGIN PGP SIGNATURE—–“.

Parameters:

dsc_filefilename is a Debian source control (.dsc) file

daklib.utils.parse_deb822(armored_contents: bytes, signing_rules: Literal[-1, 0, 1] = 0, keyrings=None) dict[str, str][source]
daklib.utils.parse_wnpp_bug_file(file: str = '/srv/ftp-master.debian.org/scripts/masterfiles/wnpp_rm') dict[str, list[str]][source]

Parses the wnpp bug list available at https://qa.debian.org/data/bts/wnpp_rm Well, actually it parsed a local copy, but let’s document the source somewhere ;)

returns a dict associating source package name with a list of open wnpp bugs (Yes, there might be more than one)

daklib.utils.poolify(source: str) str[source]

convert source name into directory path used in pool structure

daklib.utils.pp_deps(deps: Iterable[tuple[str, str, str]]) str[source]
daklib.utils.prefix_multi_line_string(lines: str, prefix: str, include_blank_lines: bool = False) str[source]

prepend prefix to each line in lines

daklib.utils.process_buildinfos(directory: str, buildinfo_files: Iterable[HashedFile], fs_transaction: FilesystemTransaction, logger: Logger) None[source]

Copy buildinfo files into Dir::BuildinfoArchive

Parameters:
  • directory – directory where .changes is stored

  • buildinfo_files – names of buildinfo files

  • fs_transaction – FilesystemTransaction instance

  • logger – logger instance

daklib.utils.result_join(original: Iterable[Optional[str]], sep: str = '\t') str[source]
daklib.utils.send_mail(message: str, whitelists: Optional[list[str]] = None) None[source]

sendmail wrapper, takes a message string

Parameters:

whitelists – path to whitelists. None or an empty list whitelists everything, otherwise an address is whitelisted if it is included in any of the lists. In addition a global whitelist can be specified in Dinstall::MailWhiteList.

daklib.utils.size_type(c: Union[int, float]) str[source]
daklib.utils.split_args(s: str, dwim: bool = True) list[str][source]

Split command line arguments which can be separated by either commas or whitespace. If dwim is set, it will complain about string ending in comma since this usually means someone did ‘dak ls -a i386, m68k foo’ or something and the inevitable confusion resulting from ‘m68k’ being treated as an argument is undesirable.

daklib.utils.suite_suffix(suite_name: str) str[source]

Return suite_suffix for the given suite

daklib.utils.temp_dirname(parent: Optional[str] = None, prefix: str = 'dak', suffix: str = '', mode: Optional[int] = None, group: Optional[str] = None) str[source]

Return a secure and unique directory by pre-creating it.

Parameters:
  • parent – If non-null it will be the directory the directory is pre-created in.

  • prefix – The filename will be prefixed with this string

  • suffix – The filename will end with this string

  • mode – If set the file will get chmodded to those permissions

  • group – If set the file will get chgrped to the specified group.

Returns:

Returns a pair (fd, name)

daklib.utils.warn(msg: str) None[source]

print warning message

daklib.utils.whoami() str[source]

get user name

Returns the user name with a laughable attempt at rfc822 conformancy (read: removing stray periods).