Utils module

class rebasehelper.utils.ConsoleHelper[source]

Class for command line interaction with the user.

class Capturer(stdout=False, stderr=False)[source]

ContextManager for capturing stdout/stderr

classmethod cprint(message, color=None)[source]

Print colored output if possible

Parameters:
  • color – color to be used in the output
  • message – string to be printed out
static get_message(message, default_yes=True, any_input=False)[source]

Function for command line messages

Parameters:
  • message – prompt string
  • default_yes – If the default value is YES
  • any_input – if True, return input without checking it first
Returns:

True or False, based on user’s input

classmethod should_use_colors(conf)[source]

Determine whether ansi colors should be used for CLI output

use_colors = False
class rebasehelper.utils.CoprHelper[source]
classmethod build(client, project, srpm)[source]
classmethod create_project(client, project, chroot, description, instructions)[source]
classmethod download_build(client, build_id, destination)[source]
classmethod get_build_status(client, build_id)[source]
classmethod get_build_url(client, build_id)[source]
classmethod get_client()[source]
classmethod watch_build(client, build_id)[source]
exception rebasehelper.utils.DownloadError[source]

Exception indicating that download of a file failed.

class rebasehelper.utils.DownloadHelper[source]

Class for downloading sources defined in SPEC file

static download_file(url, destination_path, timeout=10, blocksize=8192)[source]

Method for downloading file from HTTP, HTTPS and FTP URL.

Parameters:
  • url – URL from which to download the file
  • destination_path – path where to store downloaded file
  • timeout – timeout in seconds for blocking actions like connecting, etc.
  • blocksize – size in Bytes of blocks used for downloading the file and reporting progress
Returns:

None

static progress(download_total, downloaded, start_time)[source]

The function prints download progress and remaining time of the download directly to the standard output.

Parameters:
  • download_total (int or float) – size of the file which is being downloaded
  • downloaded (int or float) – already downloaded size of the file
  • start_time (float) – time in seconds since the epoch from the point when the download started. This is used to calculate the remaining time of the download.
Returns:

None

class rebasehelper.utils.FileHelper[source]
static file_available(filename)[source]
class rebasehelper.utils.GitHelper[source]

Class which operates with git repositories

GIT_USER_EMAIL = 'rebase-helper@localhost.local'
GIT_USER_NAME = 'rebase-helper'
classmethod get_email()[source]
classmethod get_user()[source]
classmethod run_mergetool(repo)[source]
exception rebasehelper.utils.GitRebaseError[source]

Error indicating problems with Git

exception rebasehelper.utils.GitRuntimeError[source]

Error indicating problems with Git

class rebasehelper.utils.KojiHelper[source]
baseurl = 'http://kojipkgs.fedoraproject.org/work/'
baseurl_pkg = 'https://kojipkgs.fedoraproject.org/packages/'
ca_cert = '/home/docs/.fedora-server-ca.cert'
cert = '/home/docs/.fedora.cert'
classmethod display_task_results(tasks)[source]

Taken from from koji_cli.lib

classmethod download_build(build_id, destination)[source]

Downloads all x86_64 RPMs and logs of a Koji build

Parameters:
  • build_id – Koji build ID
  • destination – target path
Returns:

(list of paths to RPMs, list of paths to logs)

classmethod download_scratch_build(session, task_list, dir_name)[source]
functional = False
classmethod get_koji_tasks(task_id, dir_name)[source]
classmethod get_latest_build(package)[source]

Searches for the latest Koji build of a package

Parameters:package – package name
Returns:(latest version, Koji build ID)
koji_web = 'koji.fedoraproject.org'
scratch_url = 'http://koji.fedoraproject.org/work/'
server = 'https://koji.fedoraproject.org/kojihub'
classmethod session_maker(baseurl=None)[source]
classmethod upload_srpm(session, source)[source]
classmethod watch_koji_tasks(session, tasklist)[source]

Taken from from koji_cli.lib

exception rebasehelper.utils.LookasideCacheError[source]

Exception indicating a problem accessing lookaside cache

class rebasehelper.utils.LookasideCacheHelper[source]

Class for downloading files from Fedora/RHEL lookaside cache

classmethod download(tool, basepath, package)[source]
rpkg_config_dir = '/etc/rpkg'
class rebasehelper.utils.MacroHelper[source]

Helper class for working with RPM macros

static dump()[source]

Returns list of all defined macros

Returns:list of macros
static expand(s, default=None)[source]
static filter(macros, **kwargs)[source]

Returns all macros satisfying specified filters

Parameters:
  • macros – list of macros to be filtered
  • kwargs – filters
Returns:

filtered list of macros

class rebasehelper.utils.PathHelper[source]

Class which finds a file or files in specific directory

static find_all_files(top_path, pattern)[source]

Finds a file that matches the given ‘pattern’ recursively starting in the ‘top_path’ directory. If found, returns full path to the first occurrence of the file, otherwise returns None.

static find_all_files_current_dir(top_path, pattern)[source]

Finds all files that matches the given ‘pattern’ in the ‘top_path’ directory. If found, returns fields of all files, otherwise returns None.

static find_first_dir_with_file(top_path, pattern)[source]

Finds a file that matches the given ‘pattern’ recursively starting in the ‘top_path’ directory. If found, returns full path to the directory with first occurrence of the file, otherwise returns None.

static find_first_file(top_path, pattern, recursion_level=None)[source]

Finds a file that matches the given ‘pattern’ recursively starting in the ‘top_path’ directory. If found, returns full path to the first occurrence of the file, otherwise returns None.

static get_temp_dir()[source]

Returns a path to new temporary directory.

class rebasehelper.utils.ProcessHelper[source]

Class for execution subprocess

DEV_NULL = '/dev/null'
static run_subprocess(cmd, input=None, output=None)[source]

Runs the passed command as a subprocess.

Parameters:
  • cmd – command with arguments to be run
  • input – file to read the input from. If None, read from STDIN
  • output – file to write the output of the command. If None, write to STDOUT
Returns:

exit code of the process

static run_subprocess_cwd(cmd, cwd=None, input=None, output=None, shell=False)[source]

Runs the passed command as a subprocess in different working directory.

Parameters:
  • cmd – command with arguments to be run
  • cwd – the directory to change the working dir to
  • input – file to read the input from. If None, read from STDIN
  • output – file to write the output of the command. If None, write to STDOUT
  • shell – if to run the command as shell command (default: False)
Returns:

exit code of the process

static run_subprocess_cwd_env(cmd, cwd=None, env=None, input=None, output=None, shell=False)[source]

Runs the passed command as a subprocess in different working directory with possibly changed ENVIRONMENT VARIABLES.

Parameters:
  • cmd – command with arguments to be run
  • cwd – the directory to change the working dir to
  • env – dictionary with ENVIRONMENT VARIABLES to define
  • input – file to read the input from. If None, read from STDIN
  • output – file to write the output of the command. If None, write to STDOUT
  • shell – if to run the command as shell command (default: False)
Returns:

exit code of the process

static run_subprocess_env(cmd, env=None, input=None, output=None, shell=False)[source]

Runs the passed command as a subprocess with possibly changed ENVIRONMENT VARIABLES.

Parameters:
  • cmd – command with arguments to be run
  • env – dictionary with ENVIRONMENT VARIABLES to define
  • input – file to read the input from. If None, read from STDIN
  • output – file to write the output of the command. If None, write to STDOUT
  • shell – if to run the command as shell command (default: False)
Returns:

exit code of the process

class rebasehelper.utils.RpmHelper[source]

Helper class for doing various tasks with RPM database, packages, …

ARCHES = None
static all_packages_installed(pkg_names=None)[source]

Check if all packages in passed list are installed.

Parameters:pkg_names – iterable with package named to check for
Returns:True if all packages are installed, False if at least one package is not installed.
static get_arches()[source]

Get list of all known architectures

static get_header_from_rpm(rpm_name)[source]

Function returns a rpm header from given rpm package for later on analysis

Parameters:rpm_name
Returns:
static get_info_from_rpm(rpm_name, info)[source]

Method returns a name of the package from RPM file format

Parameters:pkg_name
Returns:
static install_build_dependencies(spec_path=None, assume_yes=False)[source]

Install all build requires for a package using PolicyKits

Parameters:spec_path – absolute path to SPEC file
Returns:
static is_package_installed(pkg_name=None)[source]

Checks whether package with passed name is installed.

Parameters:package_name – package name we want to check for
Returns:True if installed, False if not installed
classmethod parse_spec(path)[source]
classmethod split_nevra(string)[source]

Splits string into name, epoch, version, release and arch components

class rebasehelper.utils.TemporaryEnvironment(exit_callback=None, **kwargs)[source]

Class representing a temporary environment (directory) that can be used as a workspace. It can be used with with statement.

TEMPDIR = 'TEMPDIR'
env()[source]

Returns copy of _env dictionary.

Returns:copy of _env dictionary
path()[source]

Returns path to the temporary environment.

Returns:abs path to the environment
rebasehelper.utils.get_value_from_kwargs(kwargs, field, source='old')[source]

Function returns a part of self.kwargs dictionary

Parameters:
  • kwargs
  • source – ‘old’ or ‘new’
  • field – like ‘patches’, ‘source’
Returns:

value from dictionary