kiwi.utils Package

Submodules

kiwi.utils.checksum Module

class kiwi.utils.block.BlockID(device)[source]

Bases: object

Get information from a block device

Parameters:

device (str) – block device node name name. The device can also be specified as UUID=<uuid>

get_blkid(id_type)[source]

Retrieve information for specified metadata ID from block device

Parameters:

id_type (string) – metadata ID, see man blkid for details

Returns:

ID of the block device

Return type:

str

get_filesystem()[source]

Retrieve filesystem type from block device

Returns:

filesystem type

Return type:

str

get_label()[source]

Retrieve filesystem label from block device

Returns:

block device label

Return type:

str

get_partition_count() int[source]

Retrieve number of partitions from block device

Returns:

A number

Return type:

int

get_uuid()[source]

Retrieve filesystem uuid from block device

Returns:

uuid for the filesystem of the block device

Return type:

str

kiwi.utils.block Module

class kiwi.utils.checksum.Checksum(source_filename)[source]

Bases: object

Manage checksum creation for files

Parameters:
  • source_filename (str) – source file name to build checksum for

  • checksum_filename (str) – target file with checksum information

matches(checksum, filename)[source]

Compare given checksum with reference checksum stored in the provided filename. If the checksum matches the method returns True, or False in case it does not match

Parameters:
  • checksum (str) – checksum string to compare

  • filename (str) – filename containing checksum

Returns:

True or False

Return type:

bool

md5(filename=None)[source]

Create md5 checksum

Parameters:

filename (str) – filename for checksum

Returns:

checksum

Return type:

str

sha256(filename=None)[source]

Create sha256 checksum

Parameters:

filename (str) – filename for checksum

kiwi.utils.compress Module

class kiwi.utils.compress.Compress(source_filename: str, keep_source_on_compress: bool = False)[source]

Bases: object

File compression / decompression

Parameters:
  • keep_source (bool) – Request to keep the uncompressed source

  • source_filename (str) – Source file name to compress

  • supported_zipper (list) – List of supported compression tools

  • compressed_filename (str) – Compressed file name path with compression suffix

  • uncompressed_filename (str) – Uncompressed file name path

get_format() str | None[source]

Detect compression format

Returns:

compression format name or None if it couldn’t be inferred

Return type:

Optional[str]

gzip() str[source]

Create gzip(max compression) compressed file

uncompress(temporary: bool = False) str[source]

Uncompress with format autodetection

By default the original source file will be changed into the uncompressed variant. If temporary is set to True a temporary file is created instead

Parameters:

temporary (bool) – uncompress to a temporary file

xz(options: List[str] | None = None) str[source]

Create XZ compressed file

Parameters:

options (list) – custom xz compression options

kiwi.utils.sync Module

class kiwi.utils.sync.DataSync(source_dir: str, target_dir: str)[source]

Bases: object

Sync data from a source directory to a target directory

sync_data(options: List[str] = [], exclude: List[str] = [], force_trailing_slash: bool = False) None[source]

Sync data from source to target using the rsync protocol

Parameters:
  • options (list) – rsync options

  • exclude (list) – file patterns to exclude

  • force_trailing_slash (bool) – add ‘/’ to source_dir if not present

A speciality of the rsync tool is that it behaves differently if the given source_dir ends with a ‘/’ or not. If it ends with a slash the data structure below will be synced to the target_dir. If it does not end with a slash the source_dir and its contents are synced to the target_dir. For example

source
  └── some_data

1. $ rsync -a source target

target
  └── source
        └── some_data

2. $ rsync -a source/ target

target
  └── some_data

The parameter force_trailing_slash can be used to make sure rsync behaves like shown in the second case. If set to true a ‘/’ is appended to the given source_dir if not already present

target_supports_extended_attributes() bool[source]

Check if the target directory supports extended filesystem attributes

Returns:

True or False

Return type:

bool

kiwi.utils.sysconfig Module

class kiwi.utils.sysconfig.SysConfig(source_file)[source]

Bases: object

Read and Write sysconfig style files

Parameters:

source_file (str) – source file path

get(key)[source]
write()[source]

Write back source file with changed content but in same order

Module Contents