laniakea.utils package

Submodules

laniakea.utils.arches module

laniakea.utils.arches.any_arch_matches(architectures, aliases)

Check if any architecture in iterable architectures matches any architecture wildcard in aliases.

laniakea.utils.arches.arch_matches(arch, alias)

Check if given arch arch matches the other arch alias. This is most useful for the complex any-* rules.

laniakea.utils.base64 module

laniakea.utils.base64.decode_base64(input_string)

Decode a base64 string to bytes inferring padding from the length of the string.

laniakea.utils.base64.encode_base64(input_bytes, urlsafe=False)

Encode bytes as a base64 string without any padding.

laniakea.utils.command module

exception laniakea.utils.command.SubprocessError(out, err, ret, cmd)

Bases: Exception

laniakea.utils.command.run_command(command, input=None, capture_output=True)
laniakea.utils.command.run_forwarded(command, cwd=None, print_output=True)

Run a command, optionally forwarding all output to the current stdout and return the output as well.

laniakea.utils.command.safe_run(cmd, input=None, expected=0)
laniakea.utils.command.safe_run_forwarded(command, expected=0, cwd=None, print_output=True)

laniakea.utils.deb822 module

class laniakea.utils.deb822.Changes(*args, **kwargs)

Bases: Changes

add_file(fp)
class laniakea.utils.deb822.Dsc(*args, **kwargs)

Bases: _gpg_multivalued

exception laniakea.utils.deb822.ParseDEB822Error

Bases: Exception

Exception raised for errors in parsing DEB822 data.

laniakea.utils.deb822.split_maintainer_field(maintainer)

Split a Maintainer or Changed-By field into its parts

Parameters:

maintainer (str) –

Return type:

Tuple[str, str, str]

Returns:

A tuple consisting of the RFC822 compatible version of the maintainer field, the maintainer name and the maintainer email.

laniakea.utils.gpg module

laniakea.utils.json module

laniakea.utils.json.json_compact_dump(obj, as_bytes=False)

Convert :obj to JSON string reproducibly and in the most compact form possible.

laniakea.utils.misc module

exception laniakea.utils.misc.LockError

Bases: Exception

An error happened while acquiring a file lock.

class laniakea.utils.misc.ProcessFileLock(name, noisy=True)

Bases: object

Simple wy to prevent multiple processes from executing the same code via a file lock.

acquire(raise_error=True)

Try to acquire a lockfile with the given name, useful to ensure only one process is executing a critical section at a time. :type raise_error: :param raise_error: True if we should raise an error, instead of just returning False if lock can’t be acquired. :rtype: bool :return: True if lock was acquired.

acquire_wait()
property lock_filename: str
release()

Release an acquired lock. Does nothing if no lock was taken.

laniakea.utils.misc.cd(where)
laniakea.utils.misc.datetime_to_rfc2822_string(dt)

Convert a datetime object into an RFC2822 date string.

laniakea.utils.misc.download_file(url, fname, check=False, headers=None, **kwargs)
laniakea.utils.misc.ensure_laniakea_master_user(warn_only=False)

Ensure we are running as Laniakea’s “lkmaster” user. In case we are root, we try to switch to that user automatically, otherwise we exist immediately and ask the user to run the current command again as the proper user.

laniakea.utils.misc.find_free_port_nr()
laniakea.utils.misc.get_dir_shorthand_for_uuid(uuid)

Get short prefix for UUIDs for use in directory names.

laniakea.utils.misc.is_remote_url(uri)

Check if string contains a remote URI.

laniakea.utils.misc.listify(item)

Return a list of :item, unless :item already is a list.

laniakea.utils.misc.process_file_lock(name, *, raise_error=True, wait=False, noisy=True)
laniakea.utils.misc.random_string(length=8)

Generate a random alphanumerical string with length :length.

laniakea.utils.misc.safe_strip(s)

Strip a string and handle None

laniakea.utils.misc.set_process_title(title)

Change the current process title, if possible.

laniakea.utils.misc.split_strip(s, sep)

Split a string, removing empty segments from the result and stripping the individual parts

laniakea.utils.misc.stringify(item)

Convert anything into a string, if it isn’t one already. Assume UTF-8 encoding if we have bytes.

Module contents

class laniakea.utils.Changes(*args, **kwargs)

Bases: Changes

add_file(fp)
exception laniakea.utils.LockError

Bases: Exception

An error happened while acquiring a file lock.

laniakea.utils.any_arch_matches(architectures, aliases)

Check if any architecture in iterable architectures matches any architecture wildcard in aliases.

laniakea.utils.arch_matches(arch, alias)

Check if given arch arch matches the other arch alias. This is most useful for the complex any-* rules.

laniakea.utils.cd(where)
laniakea.utils.check_filename_safe(fname)

Check if a filename contains only safe characters

Return type:

bool

laniakea.utils.datetime_to_rfc2822_string(dt)

Convert a datetime object into an RFC2822 date string.

laniakea.utils.decode_base64(input_string)

Decode a base64 string to bytes inferring padding from the length of the string.

laniakea.utils.download_file(url, fname, check=False, headers=None, **kwargs)
laniakea.utils.encode_base64(input_bytes, urlsafe=False)

Encode bytes as a base64 string without any padding.

laniakea.utils.get_dir_shorthand_for_uuid(uuid)

Get short prefix for UUIDs for use in directory names.

Hardlink a file :src to :dst or copy the file in case linking is not possible

laniakea.utils.is_remote_url(uri)

Check if string contains a remote URI.

laniakea.utils.json_compact_dump(obj, as_bytes=False)

Convert :obj to JSON string reproducibly and in the most compact form possible.

laniakea.utils.listify(item)

Return a list of :item, unless :item already is a list.

laniakea.utils.open_compressed(fname, mode='rb')

Open a few compressed filetypes easily.

laniakea.utils.process_file_lock(name, *, raise_error=True, wait=False, noisy=True)
laniakea.utils.random_string(length=8)

Generate a random alphanumerical string with length :length.

laniakea.utils.run_command(command, input=None, capture_output=True)
laniakea.utils.run_forwarded(command, cwd=None, print_output=True)

Run a command, optionally forwarding all output to the current stdout and return the output as well.

laniakea.utils.safe_rename(src, dst, *, override=False)

Instead of directly moving a file with rename(), copy the file and then delete the original. Also reset the permissions on the resulting copy.

laniakea.utils.safe_run(cmd, input=None, expected=0)
laniakea.utils.safe_run_forwarded(command, expected=0, cwd=None, print_output=True)
laniakea.utils.safe_strip(s)

Strip a string and handle None

laniakea.utils.set_process_title(title)

Change the current process title, if possible.

laniakea.utils.split_strip(s, sep)

Split a string, removing empty segments from the result and stripping the individual parts

laniakea.utils.stringify(item)

Convert anything into a string, if it isn’t one already. Assume UTF-8 encoding if we have bytes.