kentauros.modules.sources package

Submodules

kentauros.modules.sources.abstract module

This module contains the template / dummy Source class, which is then inherited by actual sources.

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

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

class kentauros.modules.sources.abstract.Source(package)[source]

Bases: kentauros.modules.module.PkgModule

This class serves as an abstract base class for source handlers. They are expected to override this class’s unimplemented methods. It also provides common infrastructure for all code sources in the form of generalised implementations of get, refresh and formatver methods.

Variables:
  • updated (bool) – indicates whether the source was updated since the state in the DB
  • sdir (str) – source directory of the package this source belongs to
  • dest (str) – destination path when downloading / copying sources
  • spkg (Package) – stores the package argument given at initialisation
  • stype (SourceType) – type of source
clean() → bool[source]

This method cleans up all of a package’s sources - excluding other files in the packages’s source directory, which may include patches or other, additional files - they are preserved.

Returns:boolTrue if successful
execute() → bool[source]

This method provides a generic way of preparing a package’s sources. This will invoke the Source.get() method or the Source.update() method and the Source.export() method (as overridden by the subclass, respectively).

If sources can be downloaded / copied into place successfully, an update for them will not be attempted. Otherwise (sources are already present within the package directory), an update will be attempted before exporting.

Returns:bool – success status of source getting or updating
export() → bool[source]

It is expected that an appropriately named tarball is present within the package’s source directory after this method has been executed.

formatver() → str[source]

This method provides a generic way of getting a package’s version as string. Subclasses are expected to override this method with their own version string generators, which then might include git commit hashes, git commit date and time, bzr revision, etc..

Returns:str – formatted version string
get() → bool[source]

It is expected that an appropriately named source file or directory is present within the package’s source directory after this method has been executed.

get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_orig() → str[source]

This method is expected to read and return the ‘orig’ value specified in the package configuration file in the source section. It is also expected to replace variables with their corresponding values.

refresh() → bool[source]

This method provides a generic way of refreshing a package’s sources. This will invoke the generic Source.clean() method and the Source.get() method (as overridden by the subclass).

Returns:bool – success status of source getting
status() → dict[source]

This method is expected to return a dictionary of statistics about the respective source. This might include, for example, the current git commit hash, bzr revision number, etc.

update() → bool[source]

It is expected that the source repository present within the package’s source directory is up-to-date with upstream sources after this method has been executed, except when package configuration explicitely specifies something else.

kentauros.modules.sources.bzr module

This sub-module only contains the BzrSource class, which has methods for handling sources that have source.type=bzr specified and source.orig set to a bzr repository URL (or an lp: abbreviation) in the package’s configuration file.

class kentauros.modules.sources.bzr.BzrSource(package)[source]

Bases: kentauros.modules.sources.abstract.Source

This Source subclass holds information and methods for handling bzr sources.

  • If the bzr command is not found on the system, self.active is automatically set to False
  • For the purpose of checking connectivity to the remote server, the URL is stored in self.remote. If the specified repository is hosted on launchpad.net, lp: will be substituted with launchpad’s URL automatically.
Parameters:package (Package) – package instance this Source belongs to
export() → bool[source]

This method executes the export from the package source repository to a tarball with pretty file name. It also respects the bzr.keep=False setting in the package configuration file - the bzr repository will be deleted from disk after the export if this flag is set.

Returns:boolTrue if successful, False if not or already exported
formatver() → str[source]

This method returns a nicely formatted version string for bzr sources.

Returns:str – nice version string (base version + “+bzr” + revision)
get() → bool[source]

This method executes the bzr repository download to the package source directory. This respects the branch and revision set in the package configuration file.

Returns:boolTrue if successful, False if not or source already exists
get_branch() → str[source]
Returns:str – string containing the branch that is set in the package configuration
get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_keep_repo() → bool[source]
Returns:bool – boolean value indicating whether the bzr repository should be kept
get_orig() → str[source]
Returns:str – string containing the upstream bzr repository URL (or lp: link)
get_revno() → str[source]
Returns:str – string containing the revision number that is set in the package configuration
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
rev() → str[source]

This method determines which revision the bzr repository associated with this BzrSource currently is at and returns it as a string. Once run, it saves the last processed revision number in self.saved_rev, in case the revision needs to be determined when bzr repository might not be accessible anymore (e.g. if bzr.keep=False is set in configuration, so the repository is not kept after export to tarball).

Returns:str – either revision string from repo, last stored rev string or “” when unsuccessful
status() → dict[source]

This method returns statistics describing this BzrSource object and its associated file(s). At the moment, this only includes the branch and revision specified in the configuration file.

Returns:dict – key-value pairs (property: value)
status_string() → str[source]

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

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

This method executes a bzr repository update as specified in the package configuration file. If a specific revision has been set in the config file, this method will not attempt to execute an update.

Returns:boolTrue if update available and successful, False otherwise
verify() → bool[source]

This method runs several checks to ensure bzr commands 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 bzr binary is installed and can be found on the system
Returns:bool – verification success
kentauros.modules.sources.bzr.LOG_PREFIX = 'ktr/sources/bzr'

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

kentauros.modules.sources.git module

This sub-module contains only contains the GitSource class, which has methods for handling sources that have source.type=git specified and source.orig set to a git repository URL in the package’s configuration file.

class kentauros.modules.sources.git.GitSource(package)[source]

Bases: kentauros.modules.sources.abstract.Source

This Source subclass holds information and methods for handling git sources.

  • If the git command is not found on the system, self.active is automatically set to False
  • For the purpose of checking connectivity to the remote server, the URL is stored in self.remote.
  • If neither branch nor commit hash has been set in the package configuration file, then the branch defaults to master (this is also written to the configuration file).
  • If a specific commit hash has been specified in the package configuration file, shallow is automatically set to False (this is also written to the configuration file).
Parameters:package (Package) – package instance this GitSource belongs to
commit() → str[source]

This method provides an easy way of getting the commit hash of the requested commit. It also stores the latest commit hash between method invocations, if the source goes away and the hash is needed again.

Returns:str – commit hash
date() → str[source]

This method provides an easy way of getting the date and time of the requested commit in a standardised format (YYMMDD.HHmmSS). It also stores the latest parsed date between method invocations, if the source goes away and the commit datetime string is needed again.

The returned value represents the date and time of ‘committing’, not of ‘authoring’ the commit, and has been converted to UTC.

Returns:str – commit date.time string (YYMMDD.HHmmSS)
export() → bool[source]

This method executes the export from the package source repository to a tarball with pretty file name. It also respects the git.keep=False setting in the package configuration file - the git repository will be deleted from disk after the export if this flag is set.

Returns:boolTrue if successful or already done, False at failure
formatver() → str[source]

This method assembles a standardised version string for git sources. This includes the package source base version, the git commit date and time and the first eight characters of the git commit hash, for example: 11.3.0+git160422.234950.39e9cf6c

Returns:str – nicely formatted version string
get() → bool[source]

This method executes the git repository download to the package source directory. This respects the branch and commit set in the package configuration file.

Returns:boolTrue if successful, False if not or source pre-exists
get_branch() → str[source]
Returns:str – string containing the branch that is set in the package configuration
get_commit() → str[source]
Returns:str – string containing the commit hash that is set in the package configuration
get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_keep_repo() → bool[source]
Returns:bool – boolean value indicating whether the git repository should be kept
get_orig() → str[source]
Returns:str – string containing the upstream git repository URL
get_shallow() → bool[source]
Returns:bool – boolean value indicating whether the git checkout depth should be 1 or not
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
status() → dict[source]

This method returns statistics describing this BzrSource object and its associated file(s). At the moment, this only includes the branch and commit hash specified in the configuration file.

Returns:dict – key-value pairs (property: value)
status_string() → str[source]

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

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

This method executes a git repository update as specified in the package configuration file. If a specific commit has been set in the config file, this method will not attempt to execute an update.

Returns:boolTrue if update available and successful, False if not
verify() → bool[source]

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

  • checks if all expected keys are present in the configuration file
  • checks that the configuration file is consistent (i.e. shallow clone and commit checkout are not compatible)
  • checks if the git binary is installed and can be found on the system
Returns:bool – verification success
kentauros.modules.sources.git.LOG_PREFIX = 'ktr/sources/git'

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

kentauros.modules.sources.local module

This sub-module contains only contains the LocalSource class, which has methods for handling sources that have source.type=local specified and source.orig set to an absolute path of a local file in the package’s configuration file.

kentauros.modules.sources.local.LOG_PREFIX = 'ktr/sources/local'

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

class kentauros.modules.sources.local.LocalSource(package)[source]

Bases: kentauros.modules.sources.abstract.Source

This Source subclass provides handling of local sources.

Parameters:package (Package) – package instance this source belongs to
export() → bool[source]

It is expected that an appropriately named tarball is present within the package’s source directory after this method has been executed.

get() → bool[source]

This method attempts to copy the specified source from the location specified in the package configuration file to the determined destination. If the destination file already exists, nothing will be done.

Returns:boolTrue if source was copied successfully, False if not
get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_orig() → str[source]
Returns:str – string containing the source file path
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
status() → dict[source]

This method is expected to return a dictionary of statistics about the respective source. This might include, for example, the current git commit hash, bzr revision number, etc.

status_string() → str[source]

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

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

It is expected that the source repository present within the package’s source directory is up-to-date with upstream sources after this method has been executed, except when package configuration explicitely specifies something else.

verify() → bool[source]

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

  • checks if all expected keys are present in the configuration file
Returns:bool – verification success

kentauros.modules.sources.no_source module

This sub-module only contains a dummy NoSource class which acts as a smart placeholder in case no source module is defined in the package configuration file.

kentauros.modules.sources.no_source.LOG_PREFIX = 'ktr/sources/none'

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

class kentauros.modules.sources.no_source.NoSource(package)[source]

Bases: kentauros.modules.sources.abstract.Source

This Source subclass does nothing except be a smart placeholder for packages that don’t define a source module in their package configuration.

Parameters:package (Package) – package instance this NoSource belongs to
export() → bool[source]

It is expected that an appropriately named tarball is present within the package’s source directory after this method has been executed.

formatver() → str[source]

This method provides a generic way of getting a package’s version as string. Subclasses are expected to override this method with their own version string generators, which then might include git commit hashes, git commit date and time, bzr revision, etc..

Returns:str – formatted version string
get() → bool[source]

It is expected that an appropriately named source file or directory is present within the package’s source directory after this method has been executed.

get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_orig() → str[source]

This method is expected to read and return the ‘orig’ value specified in the package configuration file in the source section. It is also expected to replace variables with their corresponding values.

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
status() → dict[source]

This method is expected to return a dictionary of statistics about the respective source. This might include, for example, the current git commit hash, bzr revision number, etc.

status_string() → str[source]

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

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

It is expected that the source repository present within the package’s source directory is up-to-date with upstream sources after this method has been executed, except when package configuration explicitely specifies something else.

verify() → bool[source]

This method checks if all configuration values needed for this module are present and valid.

Returns:bool
boolean indicating whether the configuration / system verification completed
successfully

kentauros.modules.sources.source_error module

This sub-module only includes a custom Exception that is raised if unrecoverable errors occur during the execution of a Source module code.

exception kentauros.modules.sources.source_error.SourceError(value='')[source]

Bases: Exception

This custom exception will be raised when unrecoverable errors occur during execution of a Source module.

Parameters:value (str) – informational string accompanying the exception

kentauros.modules.sources.url module

This sub-module contains only contains the UrlSource class, which has methods for handling sources that have source.type=url specified and source.orig set to a URL of a tarball in the package’s configuration file.

kentauros.modules.sources.url.LOG_PREFIX = 'ktr/sources/url'

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

class kentauros.modules.sources.url.UrlSource(package)[source]

Bases: kentauros.modules.sources.abstract.Source

This Source subclass holds information and methods for handling URL sources.

  • If the wget command is not found on the system, self.active is automatically set to False.
  • For the purpose of checking connectivity to the remote server, the URL is stored in self.remote.
Parameters:package (Package) – package instance this UrlSource belongs to
export() → bool[source]

It is expected that an appropriately named tarball is present within the package’s source directory after this method has been executed.

get() → bool[source]

This method executes the download of the file specified by the URL to the package source directory.

Returns:boolTrue if successful, False if not or source already exists
get_keep() → bool[source]

This method is expected to read and return the ‘keep’ value specified in the package configuration file in the source section.

get_keep_repo() → bool[source]
Returns:bool – boolean value indicating whether the downloaded file should be kept
get_orig() → str[source]
Returns:str – string containing the upstream file URL
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
status() → dict[source]

This method returns a dictionary containing the package version of the tarball that was last downloaded (as the status is only updated after successful actions).

Returns:dict – key-value pairs (property: value)
status_string() → str[source]

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

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

It is expected that the source repository present within the package’s source directory is up-to-date with upstream sources after this method has been executed, except when package configuration explicitely specifies something else.

verify() → bool[source]

This method runs several checks to ensure wget commands 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 wget binary is installed and can be found on the system
Returns:bool – verification success

Module contents

This subpackage contains the Source base class an BzrSource, GitSource, LocalSource and UrlSource subclasses, which are used for holding information about a package’s sources and methods for manipulating them. Additionally, this file contains a dictionary which maps SourceType enums to their respective class constructors.

kentauros.modules.sources.SOURCE_TYPE_DICT = {<SourceType.LOCAL: 30>: <class 'kentauros.modules.sources.local.LocalSource'>, <SourceType.URL: 10>: <class 'kentauros.modules.sources.url.UrlSource'>, <SourceType.BZR: 21>: <class 'kentauros.modules.sources.bzr.BzrSource'>, <SourceType.GIT: 20>: <class 'kentauros.modules.sources.git.GitSource'>}

This dictionary maps SourceType enum members to their respective Source subclass constructors.