Source code for kentauros.modules.constructor.rpm.spec_version_out

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


from kentauros.definitions import SourceType

from kentauros.modules.sources.bzr import BzrSource
from kentauros.modules.sources.git import GitSource
from kentauros.modules.sources.url import UrlSource
from kentauros.modules.sources.local import LocalSource
from kentauros.modules.sources.no_source import NoSource


[docs]def spec_version_bzr(source: BzrSource) -> str: """ This function returns the version string for packages built from *bzr* repositories. Arguments: BzrSource source: source repository a version string will be generated for Returns: str: version string in the format `$VERSION+rev%{rev}` """ assert isinstance(source, BzrSource) ver_str = source.spkg.get_version() + "+rev%{rev}" return ver_str
[docs]def spec_version_git(source: GitSource) -> str: """ This function returns the version string for packages built from *git* repositories. Arguments: GitSource source: source repository a version string will be generated for Returns: str: version string in the format `$VERSION+git%{date}.%{commit}` """ assert isinstance(source, GitSource) ver_str = source.spkg.get_version() + "+git%{date}.%{commit}" return ver_str
[docs]def spec_version_local(source: LocalSource) -> str: """ This function returns the version string for packages built from tarballs specified by a *local path*. Arguments: LocalSource source: source a version string will be generated for Returns: str: version string in the format `$VERSION` """ assert isinstance(source, LocalSource) ver_str = source.spkg.get_version() return ver_str
[docs]def spec_version_url(source: UrlSource) -> str: """ This function returns the version string for packages built from tarballs specified by *url*. Arguments: UrlSource source: source a version string will be generated for Returns: str: version string in the format `$VERSION` """ assert isinstance(source, UrlSource) ver_str = source.spkg.get_version() return ver_str
[docs]def spec_version_nosource(source: NoSource) -> str: """ This function returns the version string for packages built without sources. Arguments: NoSource source: source a version string will be generated for Returns: str: version string in the format `$VERSION` """ assert isinstance(source, NoSource) ver_str = source.spkg.get_version() return ver_str
SPEC_VERSION_DICT = dict() """ This dictionary maps `SourceType` enum members to their respective RPM spec version string generator functions. """ SPEC_VERSION_DICT[SourceType.BZR] = spec_version_bzr SPEC_VERSION_DICT[SourceType.GIT] = spec_version_git SPEC_VERSION_DICT[SourceType.LOCAL] = spec_version_local SPEC_VERSION_DICT[SourceType.NONE] = spec_version_nosource SPEC_VERSION_DICT[SourceType.URL] = spec_version_url