kentauros.modules.constructor package

Submodules

kentauros.modules.constructor.abstract module

This module contains the abstract Constructor class, which is then inherited by actual constructors.

class kentauros.modules.constructor.abstract.Constructor(package)[source]

Bases: kentauros.modules.module.PkgModule

This class is the abstract base class for all constructors. It’s only real function is to provide a unified API for builder classes and store the package to which the builder belongs.

Parameters:package (Package) – package for which this constructor is for
Variables:cpkg (Package) – stores parent package instance reference
build()[source]

This method assembles the source package from files prepared previously.

cleanup()[source]

This method cleans up all temporary files and directories.

export()[source]

This method exports the assembled source packages to the specified package directory.

init()[source]

This method creates the directory structure needed by other methods of this class.

prepare() → bool[source]

This method prepares all files necessary for the actual assembly of the source package.

status() → dict[source]

This method is expected to return a dictionary of statistics about the respective constructor.

kentauros.modules.constructor.abstract.LOG_PREFIX = 'ktr/constructor'

This string specifies the prefix for log and error messages printed to stdout or stderr from inside this subpackage.

kentauros.modules.constructor.srpm module

This module contains the SrpmConstructor class, which can be used to construct .src.rpm packages.

kentauros.modules.constructor.srpm.LOG_PREFIX = 'ktr/constructor/srpm'

This string specifies the prefix for log and error messages printed to stdout or stderr from inside this subpackage.

class kentauros.modules.constructor.srpm.SrpmConstructor(package)[source]

Bases: kentauros.modules.constructor.abstract.Constructor

This Constructor subclass implements methods for all stages of building and exporting source packages. At class instantiation, it checks for existence of rpmbuild and rpmdev-bumpspec binaries. If they are not found in $PATH, this instance is rendered inactive.

Parameters:

package (Package) – package for which this src.rpm constructor is for

Variables:
  • active (bool) – determines if this instance is active
  • dirs (str) – dictionary containing some directory paths
_check_source_presence() → bool[source]

This method checks if the Source’s output directory is present.

_cleanup_sources()[source]

This method cleans up the Source’s output directory according to settings.

_copy_configuration()[source]

This method copies the package configuration file to the rpmbuild/SOURCES directory in case it is included in the package build.

_copy_sources()[source]

This method copies all files (not directories) in the sources directory to the rpmbuild/SOURCES directory.

_copy_specs_around() → bool[source]

This method handles the package’s .spec file.

Variables containing the old and new Version and Release strings are calculated (from all available sources of information, including the old spec file and the local state database).

A preamble to the spec file is generated based on which macros are expected to be set for different types of sources and is prepended to the output .spec file.

Based on the information about old and new Version and Release strings, whether a VCS update triggered this build or the build was forced, the new Version string is generated.

  • The Release string might not change in case there are no changes to the package and a simple construct action has been triggered. No changelog entry is added.
  • If the Version string has changed between builds (or it is the first package build), the Release is set to 1 and a changelog entry is added to the .spec file.
  • If a package rebuild is forced (by the –force CLI argument, the Release is incremented by 1 and a changelog message is added to the .spec file.
  • If a build has been triggered because of an updated VCS snapshot, the Release is reset to 1 and a changelog entry is added. This only works if the state database has all necessary information.
_do_initial_build_prep(old_release: str, new_spec_path: str)[source]

This method prepares the .spec file for an initial package build.

Parameters:
  • old_release (str) – old release string
  • new_spec_path (str) – path of new .spec file
static _do_packaging_only_build_prep(new_spec_path: str)[source]

This method prepares the .spec file for a packaging-only change.

Parameters:new_spec_path (str) – path of new .spec file
_do_snapshot_update_build_prep(new_spec_path: str)[source]

This method prepares the .spec file for a snapshot update.

Parameters:new_spec_path (str) – path of new .spec file
_do_version_update_build_prep(new_spec_path: str)[source]

This method prepares the .spec file for a version update.

Parameters:new_spec_path (str) – path of new .spec file
_get_last_release(spec: kentauros.modules.constructor.rpm.RPMSpec)[source]

This method tries to read the latest state from the state database - if that is not available, the .spec file is parsed as a fallback.

Parameters:spec (RPMSpec) – rpm spec object
Returns:str – last known release
_get_last_version(spec: kentauros.modules.constructor.rpm.RPMSpec)[source]

This method tries to read the latest state from the state database - if that is not available, the .spec file is parsed as a fallback.

Parameters:spec (RPMSpec) – rpm spec object
Returns:str – last known version
_get_old_status() -> (<class 'str'>, <class 'str'>)[source]

This method tries to determine the old Version and Release strings from the best available source. If the local state database has not yet been updated with those values, the .spec file is parsed as a fallback.

Returns:tuple – (version, release)
_get_spec_destination() → str[source]

This method calculates the destination of the .spec file in the rpmbuild/SPECS dir.

_prepare_spec() → str[source]

This method sets the Version and Source0 tags in the template spec file and resets the Release tag to 0%{dist} if the version has changed (to the best of the program’s knowledge). A preamble to the .spec file containing all necessary macros / definitions is generated (and returned). Lastly, the spec is exported to the destination file.

Returns:str – the contents of the .spec preamble
static _print_debug_info(new_version, old_version, old_release)[source]

This method prints debug information about old and new Version and Release strings.

_restore_spec_template(new_spec_path: str, preamble: str)[source]

This method restores the original .spec file template (without added preamble, but with possibly added changelog entries).

Parameters:
  • new_spec_path (str) – path of the new spec file
  • preamble (str) – determined preamble string
build()[source]

This method executes the actual SRPM package assembly. It sets $HOME to the created temporary directory and executes rpmbuild -bs with the copy of the package spec file in rpmbuild/SPECS. After that, $HOME is reset to the old value.

clean() → bool[source]

This method is expected to clean up a sub-module’s files and folders, if it creates any during its execution.

Returns:bool – boolean indicating whether cleaning up was successful
cleanup()[source]

This method cleans up all temporary files and directories.

execute() → bool[source]

This method is expected to execute the package module and return a boolean, indicating whether the execution finished successfully or not.

Returns:bool – boolean indicating whether the execution was successful
export()[source]

This method copies the assembled source packages from rpmbuild/SRPMS to the directory for built packages as specified in the kentauros configuration. If multiple SRPM packages are found, they all are copied.

imports() → dict[source]

This method is expected to return a dictionary of statistics about a module that has not yet been imported into the package database.

Returns:dict – dictionary containing the sub-module’s imported stats
init()[source]

This method creates a temporary directory (which is then set to $HOME in the SrpmConstructor.build() method) and other necessary sub-directories (here: SOURCES, SRPMS, SPECS).

prepare() → bool[source]

This method prepares all files necessary for source package assembly.

Returns:bool – returns True if the preparation was successful.
status() → dict[source]

This method is expected to return a dictionary of statistics about the respective constructor.

status_string() → str[source]

This method is expected to return a string describing the status of this module.

Returns:str – string containing module statistics
verify() → bool[source]

This method runs several checks to ensure srpm builds can proceed. It is automatically executed at package initialisation. This includes:

  • checks if all expected keys are present in the configuration file
  • checks if the mock binary is installed and can be found on the system
  • checks if the current user is allowed to run builds with mock
  • checks if the current user is root (building as root is strongly discouraged)
  • checks if the .spec file is present at the expected location
Returns:bool – verification success

Module contents

This subpackage contains the abstract Constructor base class and DummyConstructor and SrpmConstructor subclass definitions. They contain methods for building sources into buildable packages. Additionally, this file contains a dictionary which maps kentauros.definitions.ConstructorType enums to their respective class constructors.

kentauros.modules.constructor.CONSTRUCTOR_TYPE_DICT = {<ConstructorType.SRPM: 1>: <class 'kentauros.modules.constructor.srpm.SrpmConstructor'>}

This dictionary maps ConstructorType enum members to their respective Constructor subclass constructors.