opsicommon.utils package

Submodules

opsicommon.utils.rsync module

rsync

class opsicommon.utils.rsync.Buffer

Bases: Structure

avail_in

Structure/Union member

avail_out

Structure/Union member

eof_in

Structure/Union member

next_in

Structure/Union member

next_out

Structure/Union member

exception opsicommon.utils.rsync.LibrsyncError(res)

Bases: Exception

Parameters:

res (int) –

opsicommon.utils.rsync.librsync_delta_file(filename, signature, deltafile)

Create delta file from original file and the signature of the file to patch.

Parameters:
  • filename (Path | str) –

  • signature (bytes) –

  • deltafile (Path | str) –

Return type:

None

opsicommon.utils.rsync.librsync_patch_file(oldfile, deltafile, newfile)

Create the new file from old file and delta file.

Parameters:
  • oldfile (Path | str) –

  • deltafile (Path | str) –

  • newfile (Path | str) –

Return type:

None

opsicommon.utils.rsync.librsync_signature(filename, base64_encoded=True)

Get the signature of the file to patch.

Parameters:
  • filename (Path | str) –

  • base64_encoded (bool) –

Return type:

str | bytes

Module contents

General utility functions.

class opsicommon.utils.LegacyVersion(version)

Bases: Version

Parameters:

version (str) –

class opsicommon.utils.PopenFrozen(*args, **kwargs)

Bases: PopenFrozen

Parameters:
  • args (Any) –

  • kwargs (Any) –

class opsicommon.utils.Singleton

Bases: type

opsicommon.utils.combine_versions(obj)

Returns the combination of product and package version.

Returns:

The version.

Return type:

str

Parameters:

obj (Union[Product, ProductOnClient, ProductOnDepot]) –

opsicommon.utils.compare_versions(version1, condition, version2)

Compare the versions v1 and v2 with the given condition.

condition may be one of ==, =, <, <=, >, >=.

Raises:

ValueError – If invalid value for version or condition if given.

Return type:

bool

Returns:

If the comparison matches this will return True.

Parameters:
  • version1 (str) –

  • condition (Literal['==', '=', '<', '<=', '>', '>=']) –

  • version2 (str) –

opsicommon.utils.execute(cmd, allow_exit_codes=None)
Parameters:
  • cmd (list[str]) –

  • allow_exit_codes (UnionType[list[int | EllipsisType], tuple[int | EllipsisType], None]) –

Return type:

CompletedProcess

opsicommon.utils.frozen_lru_cache(*decorator_args)

This decorator is intended to be used as drop-in replacement for functools.lru_cache. It mitigates the weakness of not being able to handle dictionary type arguments by freezing them.

Parameters:

decorator_args (Any) –

Return type:

Callable

opsicommon.utils.generate_opsi_host_key()

Generates an random opsi host key.

On Python 3.5 or lower this will try to make use of an existing random device. As a fallback the generation is done in plain Python.

Return type:

str

opsicommon.utils.ip_address_in_network(address, network)

Checks if the given IP address is in the given network range. Returns True if the given address is part of the network. Returns False if the given address is not part of the network.

Parameters:
  • address (str) – The IP which we check.

  • network (str) – The network address written with slash notation.

Return type:

bool

opsicommon.utils.make_temp_dir(base=None)
Parameters:

base (Optional[Path]) –

Return type:

Generator[Path, None, None]

opsicommon.utils.monkeypatch_subprocess_for_frozen()
Return type:

None

opsicommon.utils.prepare_proxy_environment(hostname, proxy_url='system', no_proxy_addresses=None, session=None)

proxy_url can be: * an explicid url like http://10.10.10.1:8080 * the string “system” in which case the os environment determines proxy behaviour * emptystring or None to disable proxy usage. If session is given its proxy settings are adapted. Else a new session is created and returned.

Parameters:
  • hostname (str) –

  • proxy_url (Optional[str]) –

  • no_proxy_addresses (Optional[list[str]]) –

  • session (Optional[Session]) –

Return type:

Session

opsicommon.utils.timestamp(secs=0.0, date_only=False)

Returns a timestamp of the current system time in format YYYY-mm-dd[ HH:MM:SS]

Parameters:
  • secs (float) –

  • date_only (bool) –

Return type:

str

opsicommon.utils.utc_timestamp(date_only=False)

Returns a utc timestamp in format YYYY-mm-dd[ HH:MM:SS]

Parameters:

date_only (bool) –

Return type:

str