owmeta_core.bundle.archive module

exception owmeta_core.bundle.archive.ArchiveTargetPathDoesNotExist[source]

Bases: Exception

Thrown when the Archiver target path does not exist

exception owmeta_core.bundle.archive.TargetDirectoryMismatch(target_directory, expected_target_directory)[source]

Bases: UnarchiveFailed

Thrown when the target path doesn’t agree with the bundle manifest

exception owmeta_core.bundle.archive.UnarchiveFailed[source]

Bases: Exception

Thrown when an Unarchiver fails for some reason not covered by other

class owmeta_core.bundle.archive.ArchiveExtractor(targetdir, tarfile)[source]

Bases: object

Extracts tarfile archives

Parameters
targetdirstr

The directory to which the archive will be extracted

tarfiletarfile.TarFile

The file to extract

extract()[source]

Extract the tarfile to the target directory

class owmeta_core.bundle.archive.Archiver(target_directory, bundles_directory=None)[source]

Bases: object

Archives a bundle directory tree

Parameters
target_directorystr

Where to place archives.

bundles_directorystr, optional

Where the bundles are. If not provided, then this archiver can only pack bundles when given a specific bundle’s directory

pack(bundle_id=None, version=None, *, bundle_directory=None, target_file_name=None)[source]

Pack an installed bundle into an archive file

Parameters
bundle_idstr, optional

ID of the bundle to pack. If omitted, the bundle_directory must be provided

versionint, optional

Bundle version

bundle_directorystr, optional

Bundle directory. If omitted, bundle_id must be provided. If provided, bundle_id and version are ignored

target_file_namestr, optional

Name of the archive file. If not provided, the name will be ‘bundle.tar.xz’ and will placed in the target_directory. Relative paths are relative to target_directory

Raises
BundleNotFound

Thrown when the bundle with the given ID cannot be found, or cannot be found at the demanded version

ArchiveTargetPathDoesNotExist

Thrown when the path to the desired target file does not exist

class owmeta_core.bundle.archive.Unarchiver(bundles_directory=None)[source]

Bases: object

Unpacks an archive file (e.g., a tar.xz) of a bundle

Parameters
bundles_directorystr, optional

The directory under which bundles should be unpacked. Typically the bundle cache directory.

classmethod manifest(bundle_tarfile, input_file=None)[source]

Get the manifest file from a bundle archive

Parameters
bundle_tarfiletarfile.TarFile

Tarfile, ostensibly containing bundle data

input_filefile object or str, optional

Name of the tar file. Will attempt to extract it from the tarfile if not given

unpack(input_file, target_directory=None)[source]

Unpack the archive file

If target_directory is provided, and bundles_directory is provided at initialization, then if the bundle manifest doesn’t match the expected archive path, then an exception is raised.

Parameters
input_filestr or file object

The archive file

target_directorystr, optional

The path where the archive should be unpacked. If this argument is not provided, then the target directory is derived from bundles_directory (see fmt_bundle_directory)

Raises
NotABundlePath

Thrown in one of these conditions:

  • If the input_file is not in an expected format (lzma-zipped TAR file)

  • If the input_file does not have a “manifest” file

  • If the input_file manifest file is invalid or is not a regular file (see validate_manifest for further details)

  • If the input_file is a file path and the corresponding file is not found

TargetDirectoryMismatch

Thrown when both a bundles_directory has been set at initialization and a target_directory is passed to this method and the path under bundles_directory indicated by the manifest in the input_file does not agree with target_directory

owmeta_core.bundle.archive.ensure_archive(bundle_path)[source]

Produce an archive path from a bundle path whether the given path is an archive or not

Parameters
bundle_pathstr

The path to a bundle directory or archive