opsicommon.package package

Submodules

opsicommon.package.archive module

handling of archives

class opsicommon.package.archive.ArchiveProgress(total=100, completed=0, percent_completed=0.0, _listener=<factory>, _listener_lock=<factory>)

Bases: object

Parameters:
  • total (int)

  • completed (int)

  • percent_completed (float)

  • _listener (list[ArchiveProgressListener])

  • _listener_lock (allocate_lock)

advance(amount)
Parameters:

amount (int)

Return type:

None

completed: int = 0
percent_completed: float = 0.0
register_progress_listener(listener)
Parameters:

listener (ArchiveProgressListener)

Return type:

None

set_completed(completed)
Parameters:

completed (int)

Return type:

None

total: int = 100
unregister_progress_listener(listener)
Parameters:

listener (ArchiveProgressListener)

Return type:

None

class opsicommon.package.archive.ArchiveProgressListener

Bases: ABC

progress_changed(progress)

Called when the progress state changes.

Parameters:

progress (ArchiveProgress)

Return type:

None

class opsicommon.package.archive.ProgressFileWrapper(filesize, fileobj, progress=None)

Bases: object

Parameters:
read(size=-1)
Parameters:

size (int)

Return type:

bytes

class opsicommon.package.archive.ProgressTarFile(*args, **kwargs)

Bases: TarFile

Parameters:
  • args (Any)

  • kwargs (Any)

addfile(tarinfo, fileobj=None)

Add the TarInfo object `tarinfo’ to the archive. If `fileobj’ is given, it should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by using gettarinfo().

Parameters:
  • tarinfo (TarInfo)

  • fileobj (Optional[IO[bytes]])

Return type:

None

opsicommon.package.archive.chdir(new_dir)
Parameters:

new_dir (Path)

Return type:

Generator[None, None, None]

opsicommon.package.archive.compress_command(archive, compression)
Parameters:
  • archive (Path)

  • compression (str)

Return type:

str

opsicommon.package.archive.create_archive(archive, sources, base_dir, *, compression=None, dereference=False, progress_listener=None)
Parameters:
  • archive (Path)

  • sources (list[Path])

  • base_dir (Path)

  • compression (str | None)

  • dereference (bool)

  • progress_listener (ArchiveProgressListener | None)

Return type:

None

opsicommon.package.archive.create_archive_external(archive, sources, base_dir, *, compression=None, dereference=False, progress_listener=None)
Parameters:
  • archive (Path)

  • sources (list[Path])

  • base_dir (Path)

  • compression (str | None)

  • dereference (bool)

  • progress_listener (ArchiveProgressListener | None)

Return type:

None

opsicommon.package.archive.create_archive_internal(archive, sources, base_dir, compression=None, dereference=False, progress_listener=None)
Parameters:
  • archive (Path)

  • sources (list[Path])

  • base_dir (Path)

  • compression (str | None)

  • dereference (bool)

  • progress_listener (ArchiveProgressListener | None)

Return type:

None

opsicommon.package.archive.decompress_command(archive)
Parameters:

archive (Path)

Return type:

str

opsicommon.package.archive.extract_archive(archive, destination, *, file_pattern=None, progress_listener=None)
Parameters:
Return type:

None

opsicommon.package.archive.extract_archive_external(archive, destination, *, file_pattern=None, progress_listener=None)
Parameters:
Return type:

None

opsicommon.package.archive.extract_archive_internal(archive, destination, *, file_pattern=None, progress_listener=None)
Parameters:
Return type:

None

opsicommon.package.archive.extract_command(archive, file_pattern=None)
Parameters:
  • archive (Path)

  • file_pattern (str | None)

Return type:

str

opsicommon.package.archive.get_file_type(filename)
Parameters:

filename (str | Path)

Return type:

str

opsicommon.package.archive.get_files(paths, follow_symlinks=False)
Parameters:
  • paths (list[Path])

  • follow_symlinks (bool)

Return type:

Generator[tuple[Path, int], None, None]

opsicommon.package.archive.untar(tar, destination, file_pattern=None)
Parameters:
  • tar (TarFile)

  • destination (Path)

  • file_pattern (str | None)

Return type:

None

opsicommon.package.archive.use_pigz()
Return type:

bool

opsicommon.package.associated_files module

handling of package content, hash files and more

opsicommon.package.associated_files.create_package_content_file(base_dir)
Parameters:

base_dir (Path)

Return type:

Path

opsicommon.package.associated_files.create_package_md5_file(package_path, filename=None)
Parameters:
  • package_path (Path)

  • filename (Path | None)

Return type:

Path

opsicommon.package.associated_files.create_package_zsync_file(package_path, filename=None)
Parameters:
  • package_path (Path)

  • filename (Path | None)

Return type:

Path

opsicommon.package.associated_files.md5sum(path)
Parameters:

path (Path)

Return type:

str

opsicommon.package.control_file_handling module

handling for opsi control files

opsicommon.package.control_file_handling.create_package_dependencies(pdeps)
Parameters:

pdeps (list[dict[str, str | None]])

Return type:

list[dict[str, str | None]]

opsicommon.package.control_file_handling.create_product(data_dict)
Parameters:

data_dict (dict[str, Any])

Return type:

Product

opsicommon.package.control_file_handling.create_product_dependencies(pid, prod_v, pack_v, pdeps)
Parameters:
  • pid (str)

  • prod_v (str)

  • pack_v (str)

  • pdeps (list[dict[str, str]])

Return type:

list[ProductDependency]

opsicommon.package.control_file_handling.create_product_properties(pid, prod_v, pack_v, props)
Parameters:
  • pid (str)

  • prod_v (str)

  • pack_v (str)

  • props (list[dict[str, Any]])

Return type:

list[ProductProperty]

opsicommon.package.control_file_handling.dictify_product(product)
Parameters:

product (Product)

Return type:

dict[str, Any]

opsicommon.package.control_file_handling.dictify_product_dependencies(product_dependencies)
Parameters:

product_dependencies (list[ProductDependency])

Return type:

list[dict[str, Any]]

opsicommon.package.control_file_handling.dictify_product_properties(product_properties)
Parameters:

product_properties (list[ProductProperty])

Return type:

list[dict[str, Any]]

opsicommon.package.control_file_handling.multiline_string(value)
Parameters:

value (str)

Return type:

String

opsicommon.package.legacy_control_file module

handling for old control file format

class opsicommon.package.legacy_control_file.LegacyControlFile(control_file=None)

Bases: object

Parameters:

control_file (Path | None)

generate_control_file(control_file)
Parameters:

control_file (Path)

Return type:

None

optionRegex = re.compile('^([^\\:]+)\\s*\\:\\s*(.*)$')
parse_product_property(productProperty)
Parameters:

productProperty (dict[str, str])

Return type:

None

sectionRegex = re.compile('^\\s*\\[([^\\]]+)\\]\\s*$')
valueContinuationRegex = re.compile('^\\s(.*)$')

opsicommon.package.repo_meta module

opsi packages repository metadata handling

class opsicommon.package.repo_meta.RepoMetaMetadataFile(type, urls)

Bases: object

Parameters:
type: RepoMetaMetadataFileType
urls: list[str]
class opsicommon.package.repo_meta.RepoMetaMetadataFileType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

CUSTOM = 'custom'
PACKAGES = 'packages'
class opsicommon.package.repo_meta.RepoMetaPackage(url, size, md5_hash, sha256_hash, product_id, product_version, package_version, name=None, priority=0, product_dependencies=<factory>, package_dependencies=<factory>, description=None, compatibility=None, changelog_url=None, release_notes_url=None, icon_url=None, zsync_url=None, release_date=None)

Bases: object

Parameters:
  • url (str | list[str])

  • size (int)

  • md5_hash (str)

  • sha256_hash (str)

  • product_id (str)

  • product_version (str)

  • package_version (str)

  • name (str | None)

  • priority (int)

  • product_dependencies (list[RepoMetaPackageDependency])

  • package_dependencies (list[RepoMetaProductDependency])

  • description (str | None)

  • compatibility (list[RepoMetaPackageCompatibility] | None)

  • changelog_url (str | None)

  • release_notes_url (str | None)

  • icon_url (str | None)

  • zsync_url (str | None | list[str | None])

  • release_date (datetime | None)

changelog_url: str | None = None
compatibility: list[RepoMetaPackageCompatibility] | None = None
description: str | None = None
classmethod from_dict(data)
Parameters:

data (dict[str, Any])

Return type:

RepoMetaPackage

classmethod from_package_file(package_file, url)
Parameters:
  • package_file (Path)

  • url (str | list[str])

Return type:

RepoMetaPackage

icon_url: str | None = None
md5_hash: str
merge(other)
Parameters:

other (RepoMetaPackage)

Return type:

None

name: str | None = None
package_dependencies: list[RepoMetaProductDependency]
package_version: str
priority: int = 0
product_dependencies: list[RepoMetaPackageDependency]
product_id: str
product_version: str
release_date: datetime | None = None
release_notes_url: str | None = None
sha256_hash: str
size: int
url: str | list[str]
property version: str
zsync_url: str | None | list[str | None] = None
class opsicommon.package.repo_meta.RepoMetaPackageCollection(schema_version='1.1', repository=<factory>, metadata_files=<factory>, packages=<factory>)

Bases: object

Parameters:
add_package(directory, package_file, *, num_allowed_versions=1, url=None, compatibility=None, add_callback=None)
Parameters:
  • directory (Path)

  • package_file (Path)

  • num_allowed_versions (int)

  • url (list[str] | str | None)

  • compatibility (list[RepoMetaPackageCompatibility] | None)

  • add_callback (Optional[Callable])

Return type:

RepoMetaPackage

get_packages()
Return type:

Generator[RepoMetaPackage, None, None]

limit_versions(name, num_allowed_versions=1)
Parameters:
  • name (str)

  • num_allowed_versions (int)

Return type:

None

metadata_files: list[RepoMetaMetadataFile]
packages: dict[str, dict[str, RepoMetaPackage]]
read_metafile(path)
Parameters:

path (Path)

Return type:

None

read_metafile_data(data)
Parameters:

data (bytes)

Return type:

None

remove_package(name, version)
Parameters:
  • name (str)

  • version (str)

Return type:

None

repository: RepoMetaRepository
scan_packages(directory, add_callback=None)
Parameters:
  • directory (Path)

  • add_callback (Optional[Callable])

Return type:

None

schema_version: str = '1.1'
write_metafile(path)
Parameters:

path (Path)

Return type:

None

class opsicommon.package.repo_meta.RepoMetaPackageCompatibility(os, arch)

Bases: object

Parameters:
  • os (OperatingSystem)

  • arch (Architecture)

arch: Architecture
classmethod from_dict(data)
Parameters:

data (dict[str, str])

Return type:

RepoMetaPackageCompatibility

classmethod from_string(data)
Parameters:

data (str)

Return type:

RepoMetaPackageCompatibility

os: OperatingSystem
class opsicommon.package.repo_meta.RepoMetaPackageDependency(package, version=None, condition=None)

Bases: object

Parameters:
  • package (str)

  • version (str | None)

  • condition (str | None)

condition: str | None = None
classmethod from_dict(data)
Parameters:

data (dict[str, str])

Return type:

RepoMetaPackageDependency

classmethod from_package_dependency(package_dependency)
Parameters:

package_dependency (PackageDependency)

Return type:

RepoMetaPackageDependency

package: str
version: str | None = None
class opsicommon.package.repo_meta.RepoMetaProductDependency(productAction, requiredProductId, requiredProductVersion=None, requiredPackageVersion=None, requiredAction=None, requiredInstallationStatus=None, requirementType=None)

Bases: object

Parameters:
  • productAction (str)

  • requiredProductId (str)

  • requiredProductVersion (str | None)

  • requiredPackageVersion (str | None)

  • requiredAction (str | None)

  • requiredInstallationStatus (str | None)

  • requirementType (str | None)

classmethod from_dict(data)
Parameters:

data (dict[str, str])

Return type:

RepoMetaProductDependency

classmethod from_product_dependency(product_dependency)
Parameters:

product_dependency (ProductDependency)

Return type:

RepoMetaProductDependency

productAction: str
requiredAction: str | None = None
requiredInstallationStatus: str | None = None
requiredPackageVersion: str | None = None
requiredProductId: str
requiredProductVersion: str | None = None
requirementType: str | None = None
class opsicommon.package.repo_meta.RepoMetaRepository(name='opsi package repository')

Bases: object

Parameters:

name (str)

name: str = 'opsi package repository'

opsicommon.package.wim module

WIM handling

class opsicommon.package.wim.WIMImageInfo(*, index, name, directory_count, file_count, creation_time, last_modification_time, total_bytes, hard_link_bytes=0, wimboot_compatible=False, description=None, display_name=None, display_description=None, windows_info=None)

Bases: object

Parameters:
  • index (int)

  • name (str)

  • directory_count (int)

  • file_count (int)

  • creation_time (datetime)

  • last_modification_time (datetime)

  • total_bytes (int)

  • hard_link_bytes (int)

  • wimboot_compatible (bool)

  • description (str | None)

  • display_name (str | None)

  • display_description (str | None)

  • windows_info (WIMImageWindowsInfo | None)

creation_time: datetime
description: str | None = None
directory_count: int
display_description: str | None = None
display_name: str | None = None
file_count: int
index: int
last_modification_time: datetime
name: str
total_bytes: int
wimboot_compatible: bool = False
windows_info: WIMImageWindowsInfo | None = None
class opsicommon.package.wim.WIMImageWindowsInfo(*, architecture, product_name, edition_id, installation_type, product_type, product_suite, languages, default_language, system_root, major_version, minor_version, build, service_pack_build, service_pack_level, hal=None)

Bases: object

Parameters:
  • architecture (str)

  • product_name (str)

  • edition_id (str)

  • installation_type (str)

  • product_type (str)

  • product_suite (str)

  • languages (list[str])

  • default_language (str)

  • system_root (str)

  • major_version (int)

  • minor_version (int)

  • build (int)

  • service_pack_build (int)

  • service_pack_level (int)

  • hal (str | None)

architecture: str
build: int
default_language: str
edition_id: str
hal: str | None = None
installation_type: str
languages: list[str]
major_version: int
minor_version: int
product_name: str
product_suite: str
product_type: str
service_pack_build: int
service_pack_level: int
system_root: str
class opsicommon.package.wim.WIMInfo(*, guid, version, part_number, total_parts, image_count, chunk_size, boot_index, size, compression=None, images)

Bases: object

Parameters:
  • guid (str)

  • version (int)

  • part_number (int)

  • total_parts (int)

  • image_count (int)

  • chunk_size (int)

  • boot_index (int)

  • size (int)

  • compression (str | None)

  • images (list[WIMImageInfo])

boot_index: int
chunk_size: int
compression: str | None = None
guid: str
image_count: int
images: list[WIMImageInfo]
part_number: int
size: int
total_parts: int
version: int
opsicommon.package.wim.wim_capture(source, wim_file, *, image_name, image_description, boot=False, dereference=False, unix_data=True)
Parameters:
  • source (Path | str)

  • wim_file (Path | str)

  • image_name (str | None)

  • image_description (str | None)

  • boot (bool)

  • dereference (bool)

  • unix_data (bool)

Return type:

None

opsicommon.package.wim.wim_info(wim_file)
Parameters:

wim_file (Path | str)

Return type:

WIMInfo

Module contents

opsi package class and associated methods

class opsicommon.package.OpsiPackage(package_archive=None, temp_dir=None)

Bases: object

Basic class for opsi packages.

Parameters:
  • package_archive (Path | None)

  • temp_dir (Path | None)

check_and_generate_control_file(control_file)
Parameters:

control_file (Path)

Return type:

None

compare_version_with_control_file(control_file, condition)
Parameters:
  • control_file (Path)

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

Return type:

bool

create_package_archive(base_dir, compression='zstd', destination=None, dereference=False, custom_name=None, custom_only=False, progress_listener=None, overwrite=True)
Parameters:
  • base_dir (Path)

  • compression (Literal['zstd', 'bz2', 'gz'])

  • destination (Path | None)

  • dereference (bool)

  • custom_name (str | None)

  • custom_only (bool)

  • progress_listener (ArchiveProgressListener | None)

  • overwrite (bool)

Return type:

Path

extract_package_archive(package_archive, destination, *, new_product_id=None, custom_separated=False, progress_listener=None)

Extact package_archive to destination. If new_product_id is supplied, the control file will be patched accordingly. If custom_separated is True the custom archives will be extracted to custom named directories. If custom_separated is False the archives will be extracted in a combined folder.

Parameters:
  • package_archive (Path)

  • destination (Path)

  • new_product_id (str | None)

  • custom_separated (bool)

  • progress_listener (ArchiveProgressListener | None)

Return type:

None

find_and_parse_control_file(search_dir)
Parameters:

search_dir (Path)

Return type:

Path

from_package_archive(package_archive)
Parameters:

package_archive (Path)

Return type:

None

generate_control_file(control_file)
Parameters:

control_file (Path)

Return type:

None

generate_control_file_legacy(control_file)
Parameters:

control_file (Path)

Return type:

None

get_dirs(base_dir, custom_name, custom_only)
Parameters:
  • base_dir (Path)

  • custom_name (str | None)

  • custom_only (bool)

Return type:

List[Path]

get_package_dependencies_as_json()
Return type:

str

package_archive_name()
Return type:

str

parse_control_file(control_file)
Parameters:

control_file (Path)

Return type:

None

parse_control_file_legacy(control_file)
Parameters:

control_file (Path)

Return type:

None

set_package_dependencies_from_json(json_string)
Parameters:

json_string (str)

Return type:

None

class opsicommon.package.PackageDependency(*, package, version=None, condition=None)

Bases: object

Parameters:
  • package (str)

  • version (str | None)

  • condition (str | None)

condition: str | None
package: str
version: str | None