python-gardenlinux-lib documentation

APT module

class gardenlinux.apt.Debsrc(deb_source, deb_version)

Class to reflect deb sources.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

apt

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

class gardenlinux.apt.DebsrcFile

Class to represent deb sources loaded and parsed as dict.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

apt

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

read(f: TextIO) None

Read and parse the given TextIO data to extract deb sources.

Parameters:

f – TextIO data to parse

Since:

0.7.0

Features module

class gardenlinux.features.CName(cname, arch=None, version=None)

Class to represent a canonical name (cname).

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

features

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

property arch: str | None

Returns the architecture for the cname parsed.

Returns:

(str) CName architecture

property cname: str

Returns the cname parsed.

Returns:

(str) CName

property commit_id: str | None

Returns the commit ID if part of the cname parsed.

Returns:

(str) Commit ID

property feature_set: str

Returns the feature set for the cname parsed.

Returns:

(str) Feature set of the cname

property flavor: str

Returns the flavor for the cname parsed.

Returns:

(str) Flavor

property platform: str

Returns the platform for the cname parsed.

Returns:

(str) Flavor

property version: str | None

Returns the version if part of the cname parsed.

Returns:

(str) Version

property version_and_commit_id: str | None

Returns the version and commit ID if part of the cname parsed.

Returns:

(str) Version and commit ID

class gardenlinux.features.Parser(gardenlinux_root: str | None = None, feature_dir_name: str | None = 'features', logger: Logger | None = None)

Parser for GardenLinux features.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

features

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

filter(cname: str, ignore_excludes: bool = False, additional_filter_func: Callable[[str], bool] | None = None) networkx.Graph

Filters the features graph.

Parameters:
  • cname – Canonical name to filter

  • ignore_excludes – Ignore exclude feature files

  • additional_filter_func – Additional filter function

Returns:

(networkx.Graph) Filtered features graph

Since:

0.7.0

filter_as_dict(cname: str, ignore_excludes: bool = False, additional_filter_func: Callable[[str], bool] | None = None) dict

Filters the features graph and returns it as a dict.

Parameters:
  • cname – Canonical name to filter

  • ignore_excludes – Ignore exclude feature files

  • additional_filter_func – Additional filter function

Returns:

(dict) List of features for a given cname, split into platform, element and flag

Since:

0.7.0

filter_as_list(cname: str, ignore_excludes: bool = False, additional_filter_func: Callable[[str], bool] | None = None) list

Filters the features graph and returns it as a list.

Parameters:
  • cname – Canonical name to filter

  • ignore_excludes – Ignore exclude feature files

  • additional_filter_func – Additional filter function

Returns:

(list) Features list for a given cname

Since:

0.7.0

filter_as_string(cname: str, ignore_excludes: bool = False, additional_filter_func: Callable[[str], bool] | None = None) str

Filters the features graph and returns it as a string.

Parameters:
  • cname – Canonical name to filter

  • ignore_excludes – Ignore exclude feature files

  • additional_filter_func – Additional filter function

Returns:

(str) Comma separated string with the expanded feature set for the cname

Since:

0.7.0

static get_cname_as_feature_set(cname)

Returns the features of a given canonical name.

Parameters:

cname – Canonical name

Returns:

(set) Features of the cname

Since:

0.7.0

property graph: networkx.Graph

Returns the features graph based on the GardenLinux features directory.

Returns:

(networkx.Graph) Features graph

Since:

0.7.0

static set_default_gardenlinux_root_dir(root_dir)

Sets the default GardenLinux root directory used.

Parameters:

root_dir – GardenLinux root directory

Since:

0.7.0

static sort_graph_nodes(graph)

Sorts graph nodes by feature type.

Parameters:

graph – Graph to sort

Returns:

(list) Sorted feature set

Since:

0.7.0

static sort_reversed_graph_nodes(graph)

Sorts graph nodes by feature type.

Parameters:

graph – Graph to reverse and sort

Returns:

(list) Reversed and sorted feature set

Since:

0.7.0

Flavors module

class gardenlinux.flavors.Parser(data, logger=None)

Parser for GardenLinux flavors.yaml.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

flavors

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

filter(include_only_patterns=[], wildcard_excludes=[], only_build=False, only_test=False, only_test_platform=False, only_publish=False, filter_categories=[], exclude_categories=[])

Filters flavors data and generates combinations.

Parameters:
  • include_only_patterns – Include pattern list

  • wildcard_excludes – Exclude wildcard list

  • only_build – Return only build-enabled flavors

  • only_test – Return only test-enabled flavors

  • only_test_platform – Return only platform-test-enabled flavors

  • only_publish – Return only flavors to be published

  • filter_categories – List of categories to include

  • exclude_categories – List of categories to exclude

Returns:

(list) Filtered flavors

Since:

0.7.0

static group_by_arch(combinations)

Groups combinations by architecture into a dictionary.

Parameters:

combinations – Flavor combinations to group

Returns:

(list) Grouped flavor combinations

Since:

0.7.0

static remove_arch(combinations)

Removes the architecture from combinations.

Parameters:

combinations – Flavor combinations to remove the architecture

Returns:

(list) Changed flavor combinations

Since:

0.7.0

static should_exclude(combination, excludes, wildcard_excludes)

Checks if a combination should be excluded based on exact match or wildcard patterns.

Parameters:
  • combinations – Flavor combinations

  • excludes – List of features to exclude

  • wildcard_excludes – List of feature wildcards to exclude

Returns:

(bool) True if excluded

Since:

0.7.0

static should_include_only(combination, include_only_patterns)

Checks if a combination should be included based on –include-only wildcard patterns. If no patterns are provided, all combinations are included by default.

Parameters:
  • combinations – Flavor combinations

  • include_only_patterns – List of features to include

Returns:

(bool) True if included

Since:

0.7.0

Git module

class gardenlinux.git.Git(git_directory='.', logger=None)

Git operations handler based on the given Git directory.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

git

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

property commit_id

Returns the commit ID for Git HEAD.

Returns:

(str) Git commit ID

Since:

0.7.0

property root

Returns the root directory of the current Git repository.

Returns:

(object) Git root directory

Since:

0.7.0

property root_repo

Returns the root Git Repo instance.

Returns:

(object) Git root Git Repo instance

Since:

0.7.0

OCI module

class gardenlinux.oci.Container(container_url: str, insecure: bool = False, token: str | None = None, logger: Logger | None = None)

OCI container instance to provide methods for interaction.

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

oci

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

generate_index()

Generates an OCI image index

Returns:

(object) OCI image index

Since:

0.7.0

generate_manifest(cname: str, architecture: str | None = None, version: str | None = None, commit: str | None = None, feature_set: str | None = None)

Generates an OCI image manifest

Parameters:
  • cname – Canonical name of the manifest

  • architecture – Target architecture of the manifest

  • version – Artifacts version of the manifest

  • commit – The commit hash of the manifest

  • feature_set – The expanded list of the included features of this manifest

Returns:

(object) OCI image manifest

Since:

0.7.0

static get_artifacts_metadata_from_files(files: list, arch: str) list

Returns OCI layer metadata for the given list of files.

Parameters:
  • files – a list of filenames (not paths) to set oci_metadata for

  • arch – arch of the target image

Returns:

(list) List of dicts, where each dict represents a layer

Since:

0.7.0

push_index_for_tags(index, tags)

Push tags for an given OCI image index.

Parameters:
  • index – OCI image index

  • tags – List of tags to push the index for

Since:

0.7.0

push_index_from_directory(manifests_dir: PathLike | str, additional_tags: list = None)

Replaces an old manifest entries with new ones

Parameters:
  • manifests_dir – Directory where the manifest entries are read from

  • additional_tags – Additional tags to push the index with

Since:

0.7.0

push_manifest(manifest: Manifest, manifest_file: str | None = None, additional_tags: list | None = None) Manifest

Pushes an OCI image manifest.

Parameters:
  • manifest – OCI image manifest

  • artifacts_with_metadata – A list of file names and their artifacts metadata

  • manifest_file – File name where the modified manifest is written to

  • additional_tags – Additional tags to push the manifest with

Returns:

(object) OCI image manifest

Since:

0.7.0

push_manifest_and_artifacts(manifest: Manifest, artifacts_with_metadata: list[dict], artifacts_dir: PathLike | str | None = '.build', manifest_file: str | None = None, additional_tags: list | None = None) Manifest

Pushes an OCI image manifest and its artifacts.

Parameters:
  • manifest – OCI image manifest

  • artifacts_with_metadata – A list of file names and their artifacts metadata

  • artifacts_dir – Path of the image artifacts

  • manifest_file – File name where the modified manifest is written to

  • additional_tags – Additional tags to push the manifest with

Returns:

(object) OCI image manifest

Since:

0.7.0

push_manifest_and_artifacts_from_directory(manifest: Manifest, artifacts_dir: PathLike | str | None = '.build', manifest_file: str | None = None, additional_tags: list | None = None) Manifest

Pushes an OCI image manifest and its artifacts from the given directory.

Parameters:
  • manifest – OCI image manifest

  • artifacts_dir – Path of the image artifacts

  • manifest_file – File name where the modified manifest is written to

  • additional_tags – Additional tags to push the manifest with

Returns:

(object) OCI image manifest

Since:

0.7.0

push_manifest_for_tags(manifest, tags)

Push tags for an given OCI image manifest.

Parameters:
  • manifest – OCI image manifest

  • tags – List of tags to push the index for

Since:

0.7.0

read_or_generate_index()

Reads from registry or generates the OCI image index.

Returns:

OCI image manifest

Since:

0.7.0

read_or_generate_manifest(cname: str, architecture: str | None = None, version: str | None = None, commit: str | None = None, feature_set: str | None = None) Manifest

Reads from registry or generates the OCI image manifest.

Parameters:
  • cname – Canonical name of the manifest

  • architecture – Target architecture of the manifest

  • version – Artifacts version of the manifest

  • commit – The Git commit ID of the manifest

  • feature_set – The expanded list of the included features of this manifest

Returns:

OCI image manifest

Since:

0.7.0

class gardenlinux.oci.Index(*args, **kwargs)

OCI image index

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

oci

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

append_manifest(manifest)

Appends the given OCI image manifest to the index

Parameters:

manifest – OCI image manifest

Since:

0.7.0

property json

Returns the OCI image index as a JSON

Returns:

(bytes) OCI image index as JSON

Since:

0.7.0

property manifests_as_dict

Returns the OCI image manifests of the index

Returns:

(dict) OCI image manifests with CNAME or digest as key

Since:

0.7.0

class gardenlinux.oci.Layer(blob_path: PathLike | str, media_type: str | None = None, is_dir: bool = False)

OCI image layer

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

oci

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

property dict

Return a dictionary representation of the layer

Returns:

(dict) OCI manifest layer metadata dictionary

Since:

0.7.2

static generate_metadata_from_file_name(file_name: PathLike | str, arch: str) <property object at 0x7f44dabe53a0>

Generates OCI manifest layer metadata for the given file path and name.

Parameters:
  • file_name – File path and name of the target layer

  • arch – The arch of the target image

Returns:

(dict) OCI manifest layer metadata dictionary

Since:

0.7.0

static lookup_media_type_for_file_name(file_name: str) str

Looks up the media type based on file extension.

Parameters:

file_name – File path and name of the target layer

Returns:

(str) Media type

Since:

0.7.0

class gardenlinux.oci.Manifest(*args, **kwargs)

OCI image manifest

Author:

Garden Linux Maintainers

Copyright:

Copyright 2024 SAP SE

Package:

gardenlinux

Subpackage:

oci

Since:

0.7.0

License:

https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

append_layer(layer)

Appends the given OCI image manifest layer to the manifest

Parameters:

layer – OCI image manifest layer

Since:

0.7.0

property arch

Returns the architecture of the OCI image manifest.

Returns:

(str) OCI image architecture

Since:

0.7.0

property cname

Returns the GardenLinux canonical name of the OCI image manifest.

Returns:

(str) OCI image GardenLinux canonical name

Since:

0.7.0

property commit

Returns the GardenLinux Git commit ID of the OCI image manifest.

Returns:

(str) OCI image GardenLinux Git commit ID

Since:

0.7.0

config_from_dict(config: dict, annotations: dict)

Write a new OCI configuration to file, and generate oci metadata for it.

For reference see https://github.com/opencontainers/image-spec/blob/main/config.md annotations, mediatype, size, digest are not part of digest and size calculation, and therefore must be attached to the output dict and not written to the file.

Parameters:
  • config – dict with custom configuration (the payload of the configuration)

  • annotations – dict with custom annotations to be attached to metadata part of config

Since:

0.7.0

property config_json

Returns the OCI image manifest config.

Returns:

(bytes) OCI image manifest config

Since:

0.7.0

property digest

Returns the OCI image manifest digest.

Returns:

(str) OCI image manifest digest

Since:

0.7.0

property feature_set

Returns the GardenLinux feature set of the OCI image manifest.

Returns:

(str) OCI image GardenLinux feature set

Since:

0.7.0

property flavor

Returns the GardenLinux flavor of the OCI image manifest.

Returns:

(str) OCI image GardenLinux flavor

Since:

0.7.0

property json

Returns the OCI image manifest as a JSON

Returns:

(bytes) OCI image manifest as JSON

Since:

0.7.0

property layers_as_dict

Returns the OCI image manifest layers as a dictionary.

Returns:

(dict) OCI image manifest layers with title as key

Since:

0.7.0

property size

Returns the OCI image manifest JSON size in bytes.

Returns:

(int) OCI image manifest JSON size in bytes

Since:

0.7.0

property version

Returns the GardenLinux version of the OCI image manifest.

Returns:

(str) OCI image GardenLinux version

Since:

0.7.0

Indices and tables