kentauros.modules.constructor.rpm package

Submodules

kentauros.modules.constructor.rpm.spec_common module

This sub-module serves provides shared code for this subpackage. This includes:

  • RPMSpecError: custom exception that is raised when errors occur during the parsing of .spec files
  • format_tag_line(): simple function generating prettified spec tag lines
exception kentauros.modules.constructor.rpm.spec_common.RPMSpecError(value='')[source]

Bases: Exception

This custom exception will be raised when errors occur during parsing of an RPM spec file.

Parameters:value (str) – informational string accompanying the exception
kentauros.modules.constructor.rpm.spec_common.format_tag_line(tag: str, value: str) → str[source]

This function takes a tag and value as arguments and returns a nicely formatted tag line, aligning values after column 16 (second / fourth tab).

Parameters:
  • tag (str) – tag of tag line
  • value (str) – tag value
Returns:

str – pretty tag line

kentauros.modules.constructor.rpm.spec_preamble_out module

This sub-module contains the functions that generate the necessary version strings for the .spec file, which depend on the type of source that is used.

kentauros.modules.constructor.rpm.spec_preamble_out.SPEC_PREAMBLE_DICT = {<SourceType.LOCAL: 30>: <function spec_preamble_local>, <SourceType.NONE: 0>: <function spec_preamble_nosource>, <SourceType.URL: 10>: <function spec_preamble_url>, <SourceType.BZR: 21>: <function spec_preamble_bzr>, <SourceType.GIT: 20>: <function spec_preamble_git>}

This dictionary maps SourceType enum members to their respective RPM spec preamble generator functions.

kentauros.modules.constructor.rpm.spec_preamble_out.spec_preamble_bzr(source: kentauros.modules.sources.bzr.BzrSource) → str[source]

This function returns the “%global” necessary for packages built from bzr repositories. This includes a definition of “rev” just now.

Parameters:source (BzrSource) – source repository the revision will be determined from
Returns:str – string containing the %global rev $REV line
kentauros.modules.constructor.rpm.spec_preamble_out.spec_preamble_git(source: kentauros.modules.sources.git.GitSource) → str[source]

This function returns the “%globals” necessary for packages built from git repositories. This includes a definition of “commit” and “date” just now. The value of “commit” here are the first 8 characters of the corresponding git commit hash.

Parameters:source (GitSource) – source repository the commit hash and date will be determined from
Returns:str – string with the %global commit COMMIT and %global date $DATE lines
kentauros.modules.constructor.rpm.spec_preamble_out.spec_preamble_local(source: kentauros.modules.sources.local.LocalSource) → str[source]

This function returns the “%global” necessary for packages built from tarballs specified by a local path.

Parameters:source (LocalSource) – source the %global will be determined from
Returns:str – empty string
kentauros.modules.constructor.rpm.spec_preamble_out.spec_preamble_nosource(source: kentauros.modules.sources.no_source.NoSource) → str[source]

This function returns an empty string.

Parameters:source (NoSource) – source the %global will be determined from
Returns:str – empty string
kentauros.modules.constructor.rpm.spec_preamble_out.spec_preamble_url(source: kentauros.modules.sources.url.UrlSource) → str[source]

This function returns the “%global” necessary for packages built from tarballs specified by url.

Parameters:source (UrlSource) – source the %global will be determined from
Returns:str – empty string

kentauros.modules.constructor.rpm.spec_source_out module

This sub-module contains the functions that generate the necessary “Source0:” tags for the .spec file.

kentauros.modules.constructor.rpm.spec_source_out.SPEC_SOURCE_DICT = {<SourceType.LOCAL: 30>: <function spec_source_local>, <SourceType.NONE: 0>: <function spec_source_nosource>, <SourceType.URL: 10>: <function spec_source_url>, <SourceType.BZR: 21>: <function spec_source_bzr>, <SourceType.GIT: 20>: <function spec_source_git>}

This dictionary maps SourceType enum members to their respective RPM spec Source tag string generator functions.

kentauros.modules.constructor.rpm.spec_source_out.spec_source_bzr(source: kentauros.modules.sources.bzr.BzrSource) → str[source]

This function returns the Source tag for packages built from bzr repositories.

Parameters:source (BzrSource) – source repository a Source tag will be generated for
Returns:str – Source tag with comments
kentauros.modules.constructor.rpm.spec_source_out.spec_source_git(source: kentauros.modules.sources.git.GitSource) → str[source]

This function returns the Source string for packages built from git repositories.

Parameters:source (GitSource) – source repository a Source tag will be generated for
Returns:str – Source tag with comments
kentauros.modules.constructor.rpm.spec_source_out.spec_source_local(source: kentauros.modules.sources.local.LocalSource) → str[source]

This function returns the Source string for packages built from tarballs specified by a local path.

Parameters:source (LocalSource) – source a Source tag will be generated for
Returns:str – Source tag in the format Source0: $VERSION
kentauros.modules.constructor.rpm.spec_source_out.spec_source_nosource(source: kentauros.modules.sources.no_source.NoSource) → str[source]

This function returns an empty string, as it should never be called.

Parameters:source (NoSource) – source a Source tag will be generated for
Returns:str – empty string
kentauros.modules.constructor.rpm.spec_source_out.spec_source_url(source: kentauros.modules.sources.url.UrlSource) → str[source]

This function returns the Source string for packages built from tarballs specified by url.

Parameters:source (UrlSource) – source a Source tag will be generated for
Returns:str – Source tag in the format Source0: $URL

kentauros.modules.constructor.rpm.spec_version_out module

This sub-module contains the functions that generate the necessary “Version:” tags for the .spec file.

kentauros.modules.constructor.rpm.spec_version_out.SPEC_VERSION_DICT = {<SourceType.LOCAL: 30>: <function spec_version_local>, <SourceType.NONE: 0>: <function spec_version_nosource>, <SourceType.URL: 10>: <function spec_version_url>, <SourceType.BZR: 21>: <function spec_version_bzr>, <SourceType.GIT: 20>: <function spec_version_git>}

This dictionary maps SourceType enum members to their respective RPM spec version string generator functions.

kentauros.modules.constructor.rpm.spec_version_out.spec_version_bzr(source: kentauros.modules.sources.bzr.BzrSource) → str[source]

This function returns the version string for packages built from bzr repositories.

Parameters:source (BzrSource) – source repository a version string will be generated for
Returns:str – version string in the format $VERSION+rev%{rev}
kentauros.modules.constructor.rpm.spec_version_out.spec_version_git(source: kentauros.modules.sources.git.GitSource) → str[source]

This function returns the version string for packages built from git repositories.

Parameters:source (GitSource) – source repository a version string will be generated for
Returns:str – version string in the format $VERSION+git%{date}.%{commit}
kentauros.modules.constructor.rpm.spec_version_out.spec_version_local(source: kentauros.modules.sources.local.LocalSource) → str[source]

This function returns the version string for packages built from tarballs specified by a local path.

Parameters:source (LocalSource) – source a version string will be generated for
Returns:str – version string in the format $VERSION
kentauros.modules.constructor.rpm.spec_version_out.spec_version_nosource(source: kentauros.modules.sources.no_source.NoSource) → str[source]

This function returns the version string for packages built without sources.

Parameters:source (NoSource) – source a version string will be generated for
Returns:str – version string in the format $VERSION
kentauros.modules.constructor.rpm.spec_version_out.spec_version_url(source: kentauros.modules.sources.url.UrlSource) → str[source]

This function returns the version string for packages built from tarballs specified by url.

Parameters:source (UrlSource) – source a version string will be generated for
Returns:str – version string in the format $VERSION

Module contents

This subpackage serves the purpose of handling RPM spec files.

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

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

class kentauros.modules.constructor.rpm.RPMSpec(path: str, source: kentauros.modules.sources.abstract.Source)[source]

Bases: object

This class serves as the go-to swiss army knife for handling everything concerning RPM spec files from within kentauros.

The typical usage has 3 stages:

  • reading from file (path that is passed at initialisation)
  • manipulating .spec file contents
  • writing to different file path
Variables:
  • path (str) – path pointing to the associated RPM spec file
  • source (Source) – package sources that are needed to generate some information
build_preamble_string() → str[source]

This method returns the appropriate spec preamble string, depending on the type of Source that has been set.

Returns:str – preamble string containing necessary definitions
build_version_string() → str[source]

This method returns the appropriate spec line containing the “Version” tag, depending on the type of Source that has been set.

Returns:str – preamble string containing necessary definitions
do_release_reset()[source]

This method resets the release number to 0suffix.

export_to_file(path: str)[source]

This method exports the .spec file’s (modified in memory) contents to another file, specified by the path argument.

Parameters:path (str) – path to write the modified .spec contents to
get_lines() → list[source]

This method splits the contents of the .spec file into lines and returns a list of them. It also removes the trailing newline at the end of files so they don’t multiply like rabbits.

Returns:list – list of lines
get_release() → str[source]

This method reads and parses the RPM spec file’s contents for its “Release” tag.

Returns:str – release string found on the line containing the “Version:” tag
get_version() → str[source]

This method reads and parses the RPM spec file’s contents for its “Version” tag.

Returns:str – version string found on the line containing the “Version:” tag
set_source()[source]

This method writes the updated source tag to the rpm spec file.

set_version()[source]

This method writes the updated version to the rpm spec file.

write_contents_to_file(path: str)[source]

This method writes the .spec file’s (modified in memory) contents to another file, specified by the path argument (BUT without prepending the preamble).

Parameters:path (str) – path to write the modified .spec contents to
kentauros.modules.constructor.rpm.do_release_bump(path: str, comment: str = None) → bool[source]

This function calls rpmdev-bumpspec with the specified arguments to bump the release number and create a changelog entry with a given comment.

Parameters:comment (str) – comment to be added to the changelog entry
kentauros.modules.constructor.rpm.parse_release(release: str) -> (<class 'str'>, <class 'str'>)[source]

This function splits the Release string into the leading numeric part and the trailing alphanumeric part.

Parameters:release (str) – Release string
Returns:str, str – numeric part, trailing part