COT.helpers.helper module¶
Interface for providers of non-Python helper programs.
Provides the ability to install the program if not already present, and the ability to run the program as well.
-
exception
HelperError[source]¶ Bases:
exceptions.EnvironmentErrorA helper program exited with non-zero return code.
-
exception
HelperNotFoundError[source]¶ Bases:
exceptions.OSErrorA helper program cannot be located.
-
class
Helper(name, version_args=None, version_regexp='([0-9.]+')[source]¶ Bases:
objectA provider of a non-Python helper program.
Class Properties
PACKAGE_MANAGERSClass-level lookup for package manager executables. Class Methods
apt_installTry to use apt-getto install a package.port_installTry to use portto install a package.yum_installTry to use yumto install a package.download_and_expandContext manager for downloading and expanding a .tar.gz file. find_executableWrapper for distutils.spawn.find_executable().Instance Properties
nameName of the helper program. pathDiscovered path to the helper. versionRelease version of the associated helper program. Instance Methods
call_helperCall the helper program with the given arguments. install_helperInstall the helper program (abstract method). -
__init__(name, version_args=None, version_regexp='([0-9.]+')[source]¶ Initializer.
Parameters: - name – Name of helper executable
- version_args (list) – Args to pass to the helper to
get its version. Defaults to
['--version']if unset. - version_regexp – Regexp to get the version number from the output of the command.
-
call_helper(args, capture_output=True, require_success=True)[source]¶ Call the helper program with the given arguments.
Parameters: - args (list) – List of arguments to the helper program.
- capture_output (boolean) – If
True, stdout/stderr will be redirected to a buffer and returned, instead of being displayed to the user. - require_success (boolean) – if
True, an exception will be raised if the helper exits with a non-zero status code.
Returns: Captured stdout/stderr (if
capture_output), elseNone.
-
classmethod
download_and_expand(*args, **kwds)[source]¶ Context manager for downloading and expanding a .tar.gz file.
Creates a temporary directory, downloads the specified URL into the directory, unzips and untars the file into this directory, then yields to the given block. When the block exits, the temporary directory and its contents are deleted.
with self.download_and_expand("http://example.com/foo.tgz") as d: # archive contents have been extracted to 'd' ... # d is automatically cleaned up.
Parameters: url (str) – URL of a .tgz or .tar.gz file to download.
-
install_helper()[source]¶ Install the helper program (abstract method).
Raise: NotImplementedErroras this method must be implemented by a concrete subclass.
-
PACKAGE_MANAGERS= {'apt-get': '/usr/bin/apt-get', 'yum': None, 'port': None}¶ Class-level lookup for package manager executables.
-
name¶ Name of the helper program.
-
path¶ Discovered path to the helper.
-
version¶ Release version of the associated helper program.
-