common – Base classes and common functions

This module provides base classes and common functions used in other productmd modules.

Constants

productmd.common.RELEASE_TYPES = ['fast', 'ga', 'updates', 'updates-testing', 'eus', 'aus', 'els', 'tus', 'e4s']

list() -> new empty list list(iterable) -> new list initialized from iterable’s items

productmd.common.RELEASE_SHORT_RE = <_sre.SRE_Pattern object>

Validation regex for release short name: [a-z] followed by [a-z0-9] separated with dashes.

productmd.common.RELEASE_VERSION_RE = <_sre.SRE_Pattern object>

Validation regex for release version: any string or [0-9] separated with dots.

Functions

productmd.common.parse_nvra(nvra)

Parse RPM N-E:V-R.A string to a dict.

Parameters:nvra (str) – N-E:V-R.A string. This can be a file name or a file path including the ‘.rpm’ suffix.
Return type:dict, with “name”, “epoch”, “version”, “release”, and “arch” elements.
productmd.common.create_release_id(short, version, type, bp_short=None, bp_version=None, bp_type=None)

Create release_id from given parts.

Parameters:
  • short (str) – Release short name
  • version (str) – Release version
  • version – Release type
  • bp_short (str) – Base Product short name
  • bp_version (str) – Base Product version
  • bp_type – Base Product type
Return type:

str

productmd.common.parse_release_id(release_id)

Parse release_id to parts: {short, version, type} or {short, version, type, bp_short, bp_version, bp_type}

Parameters:release_id (str) – Release ID string
Return type:dict
productmd.common.is_valid_release_short(short)

Determine if given release short name is valid.

Parameters:short (str) – Release short name
Return type:bool
productmd.common.is_valid_release_version(version)

Determine if given release version is valid.

Parameters:version (str) – Release version
Return type:bool
productmd.common.split_version(version)

Split version to a list of integers that can be easily compared.

Parameters:version (str) – Release version
Return type:[int] or [string]
productmd.common.get_major_version(version, remove=None)

Return major version of a provided version string. Major version is the first component of the dot-separated version string. For non-version-like strings this function returns the argument unchanged.

The remove parameter is deprecated since version 1.18 and will be removed in the future.

Parameters:version (str) – Version string
Return type:str
productmd.common.get_minor_version(version, remove=None)

Return minor version of a provided version string. Minor version is the second component in the dot-separated version string. For non-version-like strings this function returns None.

The remove parameter is deprecated since version 1.18 and will be removed in the future.

Parameters:version (str) – Version string
Return type:str

Classes

class productmd.common.MetadataBase
validate()

Validate attributes by running all self._validate_*() methods.

Raises:
  • TypeError – if an attribute has invalid type
  • ValueError – if an attribute contains invalid value
load(f)

Load data from a file.

Parameters:f (file or str) – file-like object or path to file
loads(s)

Load data from a string.

Parameters:s (str) – input data
dump(f)

Dump data to a file.

Parameters:f (file or str) – file-like object or path to file
dumps()

Dump data to a string.

Return type:str
class productmd.common.Header(parent, metadata_type)

This class represents the header used in serialized metadata files.

It consists of a type and a version. The type is meant purely for consumers of the file to know what they are dealing with without having to check filename. The version is used by productmd when parsing the file.