rpms – RPM metadata
This module provides classes for manipulating rpms.json files. rpms.json files provide details about RPMs included in composes.
Example:
import productmd.compose
compose = productmd.compose.Compose("/path/to/compose")
# Print the entire dict that maps all variants, arches, and RPMs for this
# compose:
print(compose.rpms.rpms)
# Find all the source RPMs in this compose:
srpms = set()
for variant in compose.rpms.rpms:
for arch in compose.rpms.rpms[variant]:
for srpm in compose.rpms.rpms[variant][arch]:
srpms.add(srpm)
print(srpms)
# ... prints the set of SRPMs in all our variants:
# ['ceph-2:12.2.5-25.el7cp.src',
# 'ceph-ansible-0:3.1.0-0.1.rc9.el7cp.src',
# 'ceph-iscsi-cli-0:2.7-1.el7cp.src',
# ...
# ]
Classes
- class productmd.rpms.Rpms
- serialize(parser, force_version=None)
Serialize RPM metadata.
- Parameters:
parser (dict) – Dictionary to serialize into
force_version (tuple or None) – Force output version (overrides output_version)
- add(variant, arch, nevra, path, sigkey, category, srpm_nevra=None, location=None, sigkeys=None)
Map RPM to to variant and arch.
- Parameters:
variant (str) – compose variant UID
arch (str) – compose architecture
nevra (str) – name-epoch:version-release.arch
path (str) – relative path to the RPM file
sigkey (str or None) – sigkey hash. When sigkeys is provided, this is derived from
sigkeys[0]and should not be set explicitly.category (str) – RPM category, one of binary, debug, source
srpm_nevra (str) – name-epoch:version-release.arch of RPM’s SRPM
location (
Locationor None) – Location object for v2.0 distributed composes. When provided, the Location is stored alongside v1.x fields and used during v2.0 serialization. The path parameter is still required for v1.x compatibility; if location is given and path is not explicitly set, path defaults tolocation.local_path.sigkeys (list of str or None) – list of signing key identifiers for RPM v6 packages with multiple signatures. Each value must be a hex string. Only included in v2.0 serialization. When provided, sigkey is derived from
sigkeys[0]. This derivation only happens atadd()time; modifying sigkeys directly on the entry dict afterwards will not update sigkey.
- get_location(variant, arch, srpm_nevra, rpm_nevra)
Return the Location object for an RPM entry, or None.
- Parameters:
variant (str) – compose variant UID
arch (str) – compose architecture
srpm_nevra (str) – name-epoch:version-release.arch of the SRPM
rpm_nevra (str) – name-epoch:version-release.arch of the RPM
- Returns:
Location object, or None if not found or not set
- Return type:
Locationor None
- get_sigkeys(variant, arch, srpm_nevra, rpm_nevra)
Return the list of signing key identifiers for an RPM entry.
- Parameters:
variant (str) – compose variant UID
arch (str) – compose architecture
srpm_nevra (str) – name-epoch:version-release.arch of the SRPM
rpm_nevra (str) – name-epoch:version-release.arch of the RPM
- Returns:
list of signing key identifiers, empty if not found or not set
- Return type:
list of str
- detect_data_version(data: Dict[str, Any]) Tuple[int, int]
Detect version from parsed data.
- Parameters:
data (dict) – Parsed metadata
- Returns:
Version tuple
- Return type:
tuple
- 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
- get_output_version(force_version: Tuple[int, int] | None = None) Tuple[int, int]
Resolve the effective output version.
Priority: force_version > output_version (instance) > _default_output_version (class)
- Parameters:
force_version (tuple or None) – Explicit version override
- Returns:
Version tuple
- Return type:
tuple
- 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
- property output_version: Tuple[int, int]
Get the version to use when serializing.
Returns the instance override if set, otherwise the class default.
- Returns:
Version tuple (major, minor)
- Return type:
tuple
- should_use_locations() bool
Check if Location objects should be used for output.
- Returns:
True if using v2.0+ format
- Return type:
bool
- validate()
Validate attributes by running all self._validate_*() methods.
- Raises:
TypeError – if an attribute has invalid type
ValueError – if an attribute contains invalid value