API¶
Exceptions¶
-
exception
pyrpkg.errors.
rpkgError
¶ Our base error class
-
exception
pyrpkg.errors.
rpkgAuthError
¶ Raised in case of authentication errors
-
exception
pyrpkg.errors.
UnknownTargetError
¶
-
exception
pyrpkg.errors.
HashtypeMixingError
(existing_hashtype, new_hashtype)¶ Raised when we try to mix hash types in a sources file
-
exception
pyrpkg.errors.
MalformedLineError
¶ Raised when parsing a sources file with malformed lines
-
exception
pyrpkg.errors.
InvalidHashType
¶ Raised when we don’t know the requested hash algorithm
-
exception
pyrpkg.errors.
DownloadError
¶ Raised when something went wrong during a download
-
exception
pyrpkg.errors.
UploadError
(message, http_status=None)¶ Raised when something went wrong during an upload
cli¶
-
class
pyrpkg.cli.
cliClient
(config, name=None)¶ This is a client class for rpkg clients.
-
_get_bool_opt
(opt, default=False)¶
-
_gitcred_check_input
()¶ Parses the git-credential-helper IO format input.
-
_gitcred_return
(args)¶ Returns git-credential-helper IO format output.
-
_gitcred_test
(args)¶ Test the token we are about to return for freshness.
Note that this is a best-effort, and it could be that we return scucess but the actual push fails, in which case git will call the erase method, and we tell the user to retry.
-
_oidc_scopes
¶ Returns the configured OIDC scopes to request.
-
_oidc_token
(**kwargs)¶ Returns an OpenID Connect token via the global client.
- Returns: (string or bool or None): Returns a string token, None if the
- client did not return a token, or False if the client was not configured.
-
build
(sets=None)¶
-
chainbuild
()¶
-
clean
()¶
-
clog
()¶
-
clone
()¶
-
cmd
¶ This is a property for the command attribute
-
commit
()¶
-
compile
()¶
-
container_build
()¶
-
container_build_koji
()¶
-
container_build_setup
()¶
-
copr_build
()¶
-
diff
()¶
-
do_imports
(site=None)¶ Import extra stuff not needed during build
As a side effect method sets self.site with a loaded library.
Parameters: site (the module of downstream client that is built on top of rpkg.) – used to specify which library to load.
-
get_name
()¶
-
gimmespec
()¶
-
gitbuildhash
()¶
-
gitcred_erase
()¶ Performs the git-credential-helper erase operation.
-
gitcred_get
()¶ Performs the git-credential-helper get operation.
-
gitcred_store
()¶ Nothing to do here.
If we returned a token, that’s already stored. If the user manually entered a password, we do not want to store it. Thus we present to you, a no-op.
-
giturl
()¶
-
import_srpm
()¶
-
install
()¶
-
lint
()¶
-
load_cmd
()¶ This sets up the cmd object
-
local
()¶
-
mock_config
()¶
-
mockbuild
()¶
-
module_api_url
¶ A property that returns the MBS base API URL based on the maximum API version supported by both rpkg and MBS :return: a string of the MBS API URL
-
module_api_version
¶ A property that returns that maximum API version supported by both rpkg and MBS :return: an int of the API version
-
module_build
()¶ Builds a module using MBS
-
module_build_cancel
()¶ Cancel an MBS build
-
module_build_info
()¶ Show information about an MBS build
-
module_build_local
()¶ Build a module locally using mbs-manager
-
module_build_watch
()¶ Watch an MBS build from the command-line
-
module_get_auth_config
()¶ Get the authentication configuration for the MBS
Returns: a tuple consisting of the authentication method, the OIDC ID provider, the OIDC client ID, the OIDC client secret, and the OIDC scopes. If the authentication method is not OIDC, the OIDC values in the tuple are set to None. Return type: tuple
-
module_overview
()¶ Show the overview of the latest builds in the MBS
-
module_validate_config
()¶ Validates the configuration needed for MBS commands
Raises: pyrpkg.errors.rpkgError
-
module_watch_build
(build_ids)¶ Watches the first MBS build in the list in a loop that updates every 15 seconds. The loop ends when the build state is ‘failed’, ‘done’, or ‘ready’.
Parameters: build_ids (list[int]) – a list of module build IDs
-
name
¶ Property used to identify prog name and key in config file
-
new
()¶
-
new_sources
()¶
-
oidc_client
¶ Returns a OpenID Connect client reference.
- Returns: (openidc_client.OpenIDCClient or None): client if configured,
- None if unconfigured.
-
oidc_configured
¶ Returns a boolean indicating whether OIDC is configured.
-
parse_cmdline
(manpage=False)¶ Parse the commandline, optionally make a manpage
This also sets up self.user
-
patch
()¶
-
prep
()¶
-
pull
()¶
-
push
()¶
-
register_build
()¶ Register the build target
-
register_build_common
()¶ Create a common build parser to use in other commands
-
register_chainbuild
()¶ Register the chain build target
-
register_clean
()¶ Register the clean target
-
register_clog
()¶ Register the clog target
-
register_clone
()¶ Register the clone target and co alias
-
register_commit
()¶ Register the commit target and ci alias
-
register_compile
()¶ Register the compile target
-
register_container_build
()¶
-
register_container_build_setup
()¶
-
register_copr_build
()¶ Register the copr-build target
-
register_diff
()¶ Register the diff target
-
register_gimmespec
()¶ Register the gimmespec target
-
register_gitbuildhash
()¶ Register the gitbuildhash target
-
register_gitcred
()¶ Register the (hidden) gitcred target
These commands implement the git-credential helper API, so that we are able to provide OpenID Connect/OAuth2 tokens if requested for https based pushing.
-
register_giturl
()¶ Register the giturl target
-
register_help
()¶ Register the help command.
-
register_import_srpm
()¶ Register the import-srpm target
-
register_install
()¶ Register the install target
-
register_lint
()¶ Register the lint target
-
register_local
()¶ Register the local target
-
register_mock_config
()¶ Register the mock-config target
-
register_mockbuild
()¶ Register the mockbuild target
-
register_module_build
()¶
-
register_module_build_cancel
()¶
-
register_module_build_info
()¶
-
register_module_build_watch
()¶
-
register_module_local_build
()¶
-
register_module_overview
()¶
-
register_new
()¶ Register the new target
-
register_new_sources
()¶ Register the new-sources target
-
register_patch
()¶ Register the patch target
-
register_prep
()¶ Register the prep target
-
register_pull
()¶ Register the pull target
-
register_push
()¶ Register the push target
-
register_rpm_common
()¶ Create a common parser for rpm commands
-
register_scratch_build
()¶ Register the scratch-build target
-
register_sources
()¶ Register the sources target
-
register_srpm
()¶ Register the srpm target
-
register_switch_branch
()¶ Register the switch-branch target
-
register_tag
()¶ Register the tag target
-
register_unused_patches
()¶ Register the unused-patches target
-
register_upload
()¶ Register the upload target
-
register_verify_files
()¶ Register the verify-files target
-
register_verrel
()¶
-
scratch_build
()¶
-
setupLogging
(log)¶ Setup the various logging stuff.
-
setup_argparser
()¶ Setup the argument parser and register some basic commands.
-
setup_subparsers
()¶ Setup basic subparsers that all clients should use
-
sources
()¶ Download files listed in sources
For command compile, prep, install, local and srpm, files are needed to be downloaded before doing what the command does. Hence, for these cases, sources is not called from command line. Instead, from rpkg inside.
-
srpm
()¶
-
switch_branch
()¶
-
tag
()¶
-
unused_patches
()¶
-
upload
()¶
-
usage
()¶
-
verify_files
()¶
-
verrel
()¶
-
commands¶
-
class
pyrpkg.__init__.
NullHandler
(level=0)¶ Null logger to avoid spurious messages, add a handler in app code
-
emit
(record)¶ Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
-
-
class
pyrpkg.__init__.
Commands
(path, lookaside, lookasidehash, lookaside_cgi, gitbaseurl, anongiturl, branchre, kojiconfig, build_client, koji_config_type='config', user=None, dist=None, target=None, quiet=False, distgit_namespaced=False, realms=None, lookaside_namespaced=False)¶ This is a class to hold all the commands that will be called by clients
-
UPLOADEXTS
= ['tar', 'gz', 'bz2', 'lzma', 'xz', 'Z', 'zip', 'tff', 'bin', 'tbz', 'tbz2', 'tgz', 'tlz', 'txz', 'pdf', 'rpm', 'jar', 'war', 'db', 'cpio', 'jisp', 'egg', 'gem', 'spkg', 'oxt', 'xpi']¶
-
_byte_offset_to_line_number
(text, offset)¶ Convert byte offset (given by e.g. DecodeError) to human readable format (line number and char position)
Returns: a pair of line number and char offset. Return type: list(int, int)
-
_cleanup_tmp_dir
(tmp_dir)¶ Tries to remove directory and ignores EEXIST error
If occoured directory not exist error (EEXIST) it silently continue. Otherwise raise rpkgError exception.
-
_clone_config
(conf_git, repo)¶
-
_config_dir_basic
(config_dir=None, root=None)¶ Setup directory with essential mock config
If config directory doesn’t exist it will be created. If temporary directory was created by this method and error occours during processing, temporary directory is removed. Otherwise it caller’s responsibility to remove this directory.
Returns used config directory
-
_config_dir_other
(config_dir, filenames=('site-defaults.cfg', 'logging.ini'))¶ Populates mock config directory with other necessary files
If files are found in system config directory for mock they are copied to mock config directory defined as method’s argument. Otherwise empty files are created.
-
_deprecated_read_koji_config
()¶ Read Koji config from Koji configuration files
-
_get_build_arches_from_spec
()¶ Given the path to an spec, retrieve the build arches
-
_get_build_arches_from_srpm
(srpm, arches)¶ Given the path to an srpm, determine the possible build arches
Use supplied arches as a filter, only return compatible arches
-
_get_namespace_anongiturl
(repo_name)¶ Get the namespaced git url, if DistGit namespace enabled
Parameters: repo_name (str) – a repository name with or without namespace. Returns: anonymous giturl with a proper namespace. If repository name does not have namespace and dist-git namespace is enabled, default namespace rpms will be set. Return type: str
-
_get_namespace_giturl
(repo_name)¶ Get the namespaced git url, if DistGit namespace enabled
Parameters: repo_name (str) – a repository name with or without namespace. Returns: giturl with proper namespace. If namespace is not in the repository name and dist-git namespace is enabled, default namespace rpms will set. Return type: str
-
_guess_hashtype
()¶ Attempt to figure out the hash type based on branch data
-
_has_krb_creds
()¶ Kerberos authentication is disabled if neither gssapi nor krbV is available
-
_load_krb_user
()¶ This attempts to get the username from active tickets
-
_newer
(file1, file2)¶ Compare the last modification time of the given files
Returns: True if file1 is newer than file2 Return type: bool
-
_run_command
(cmd, shell=False, env=None, pipe=[], cwd=None)¶ Run the given command.
_run_command is able to run single command or two commands via pipe. Whatever the way to run the command, output to both stdout and stderr will not be captured and output to terminal directly, that is useful for caller to redirect.
Parameters: - cmd (str or list) – executable and arguments to run. Depending on argument shell, cmd could be a list if shell is False, and a string if False is passed to shell.
- shell (bool) – whether to run in a shell or not, defaults to False.
- env (dict(str, str)) – environment variables to use (if any)
- pipe (str or list) – command to pipe the output of cmd into. Same as argument cmd, pipe could be a string or list depending on value of shell.
- cwd (str) – optional directory to run the command from
Raises: rpkgError – any error raised from underlying subprocess while executing command in local system will be mapped to
rpkgError
.
-
_srpmdetails
(srpm)¶ Return a tuple of package name, package files, and upload files.
-
add_tag
(tagname, force=False, message=None, file=None)¶ Add a git tag to the repository
Parameters: - tagname (str) – tag name.
- force (bool) – Optionally can force the tag, include a message, or reference a message file.
- file (str) – Optional. File containing tag message.
-
anon_kojisession
¶ This property ensures the anon kojisession attribute
-
build
(skip_tag=False, scratch=False, background=False, url=None, chain=None, arches=None, sets=False, nvr_check=True, fail_fast=False)¶ Initiate a build. Available options are:
skip_tag: Skip the tag action after the build
scratch: Perform a scratch build
background: Perform the build with a low priority
url: A url to an uploaded srpm to build from
chain: A chain build set
arches: A set of arches to limit the scratch build for
sets: A boolean to let us know whether or not the chain has sets
- nvr_check: A boolean; locally construct NVR and submit a build only if
- NVR doesn’t exist in a build system
fail_fast: Perform the build in fast failure mode, which will cause the entire build to fail if any subtask/architecture build fails.
This function submits the task to koji and returns the taskID
It is up to the client to wait or watch the task.
-
ca_cert
¶ A CA certificate to authenticate the server in SSL connections
Downstream users of the pyrpkg API should override this property if they actually need to use a CA certificate, usually because their lookaside cache is using HTTPS with a self-signed certificate.
This defaults to None, which means the system CA bundle is used.
-
cert_file
¶ A client-side certificate for SSL authentication
Downstream users of the pyrpkg API should override this property if they actually need to use a client-side certificate.
This defaults to None, which means no client-side certificate is used.
-
check_inheritance
(build_target, dest_tag)¶ Check if build tag inherits from dest tag
-
check_repo
(has_namespace=True, **criteria)¶
-
clean
(dry=False, useignore=True)¶ Clean a repository checkout of untracked files.
Parameters: - dry (bool) – Can optionally perform a dry-run. Defaults to False.
- useignore (bool) – Can optionally not use the ignore rules. Defaults to True.
-
clog
(raw=False)¶ Write the latest spec changelog entry to a clog file
-
clone
(repo, path=None, branch=None, bare_dir=None, anon=False, target=None)¶ Clone a repo, optionally check out a specific branch.
Parameters: - repo (str) – the name of the repository to clone.
- path (str) – an optional basedir to perform the clone in.
- branch (str) – an optional name of a branch to checkout instead of <remote>/master.
- bare_dir (str) – an optional name of a directory to make a bare clone to if this is a bare clone. None otherwise.
- anon (bool) – whether or not to clone anonymously. Defaults to False.
- target (str) – an optional name of the folder in which to clone the repo.
-
clone_with_dirs
(repo, anon=False, target=None)¶ Clone a repo old style with subdirs for each branch.
Parameters: - repo (str) – name of the repository to clone.
- anon (bool) – whether or not to clone anonymously. Defaults to False.
- target (str) – an optional name of the folder in which to clone the repo.
-
commit
(message=None, file=None, files=[], signoff=False)¶ Commit changes to a repository (optionally found at path)
Requires the caller be a real tty or a message passed.
Parameters: - message (str) – an optional message to use as the commit message
- file (str) – an optional file to find the commit message within
- files (list) – an optional list to list files to commit.
- signoff (bool) – signoff commit optionally. Defaults to False.
-
compile
(arch=None, short=False, builddir=None, nocheck=False)¶ Run rpmbuild -bc
optionally for a specific arch, or short-circuit it, or define an alternate builddir
Logs the output and returns nothing
-
construct_build_url
(repo_name=None, commit_hash=None)¶ Construct build URL with namespaced anongiturl and commit hash
Parameters: - repo_name (str) – name of the repository part of the build URL. If omitted, namespaced name will be guessed from current repository. The given repository name will be used in URL directly without guessing namespace.
- commit_hash (str) – the commit hash appended to build URL. It omitted, the latest commit hash got from current repository will be used.
Returns: URL built from anongiturl.
Return type: str
-
container_build_koji
(target_override=False, opts={}, kojiconfig=None, kojiprofile=None, build_client=None, koji_task_watcher=None, nowait=False)¶
-
container_build_setup
(get_autorebuild=None, set_autorebuild=None)¶
-
copr_build
(project, srpm_name, nowait, config_file)¶
-
delete_tag
(tagname)¶ Delete a git tag from the repository found at optional path
-
diff
(cached=False, files=[])¶ Execute a git diff
Parameters: - cached (bool) – optionally diff the cached or staged changes. Defaults to not.
- files (list) – optional list of files to diff relative to the module base directory.
-
find_untracked_patches
()¶ Find patches that are not tracked by git and sources both
-
get_base_repo
(repo)¶
-
get_latest_commit
(repo, branch)¶ Discover the latest commit has for a given repository and return it
-
gitbuildhash
(build)¶ Determine the git hash used to produce a particular N-V-R
-
giturl
()¶ Return the git url that would be used for building
-
import_srpm
(srpm)¶ Import the contents of an srpm into a repo.
This function will add/remove content to match the srpm, upload new files to the lookaside, and stage the changes.
Parameters: srpm (str) – file to import contents from. Returns: a list of files to upload. Return type: list
-
install
(arch=None, short=False, builddir=None, nocheck=False)¶ Run rpm -bi
optionally for a specific arch, short-circuit it, or define an alternative builddir
Logs the output and returns nothing
-
koji_upload
(file, path, callback=None)¶ Upload a file to koji
file is the file you wish to upload
path is the relative path on the server to upload to
callback is the progress callback to use, if any
Returns nothing or raises
-
kojisession
¶ This property ensures the kojisession attribute
-
kojiweburl
¶ This property ensures the kojiweburl attribute
-
lint
(info=False, rpmlintconf=None)¶ Run rpmlint over a built srpm
Log the output and returns nothing rpmlintconf is the name of the config file passed to rpmlint if specified by the command line argument.
-
list_tag
(tagname='*')¶ List all tags in the repository which match a given tagname.
Parameters: tagname (str) – an optional shell glob to match part of tags (it is matched with fnmatch). Defaults to ‘*’ to list all tags.
-
load_kojisession
(anon=False)¶ Initiate a koji session.
The koji session can be logged in or anonymous
-
load_repo
()¶ Create a repo object from our path
-
load_user
()¶ This sets the user attribute
-
local
(localargs, arch=None, hashtype=None, builddir=None)¶ rpmbuild locally for given arch.
Takes localargs (passed to rpmbuild), arch to build for, and hashtype to build with.
Writes output to a log file and logs it to the logger. Log file is written into current working directory and in format .build-{version}-{release}.log.
Parameters: - arch (str) – to optionally build for a specific arch.
- hashtype (str) – an alternative algorithm used for payload file digests.
- builddir (str) – an alternative builddir.
Raises: rpkgError – if underlying rpmbuild fails.
-
login_koji_session
(koji_config, session)¶ Login Koji session
-
lookasidecache
¶ A helper to interact with the lookaside cache
Downstream users of the pyrpkg API may override this property with their own, returning their own implementation of a lookaside cache helper object.
Returns: lookaside cache instance providing all the needed stuff to communicate with a Fedora-style lookaside cache. Return type: pyrpkg.lookaside.CGILookasideCache
-
mock_config
(target=None, arch=None)¶ Generate a mock config based on branch data.
Parameters: - target (str) – an alternative build target, otherwise default build target will be used.
- arch (str) – an alternative arch, otherwise local system arch will be used.
Returns: the mock config content got from Koji.
Return type: str
-
mock_results_dir
¶
-
mockbuild
(mockargs=[], root=None, hashtype=None)¶ Build the package in mock, using mockargs
Log the output and returns nothing
-
module_build_cancel
(api_url, build_id, auth_method, oidc_id_provider=None, oidc_client_id=None, oidc_client_secret=None, oidc_scopes=None)¶ Cancel an MBS build
Parameters: - api_url (str) – URL of the MBS API
- build_id (int) – build ID to cancel
- auth_method (str) – authentication method used by the MBS
- oidc_id_provider (str) – the OIDC provider when MBS is using OIDC for authentication
- oidc_client_id (str) – the OIDC client ID when MBS is using OIDC for authentication
- oidc_client_secret (str) – the OIDC client secret when MBS is using OIDC for authentication. Based on the OIDC setup, this could be None.
- oidc_scopes (list) – a list of OIDC scopes when MBS is using OIDC for authentication
-
module_build_info
(api_url, build_id)¶ Show information about an MBS build
Parameters: - api_url (str) – URL of the MBS API
- build_id (int) – build ID to query MBS about
-
module_get_api_version
(api_url)¶ Queries the /about/ API to determine what the latest API version that MBS supports is and returns the latest API that both rpkg and MBS support. :param api_url: a string of the URL of the MBS API :return: an int of the API version
-
module_get_build
(api_url, build_id)¶ Get an MBS build :param api_url: a string of the URL of the MBS API :param build_id: an integer of the build ID to query MBS about :return: None or a dictionary representing the module build
-
static
module_get_koji_state_dict
()¶ Get a dictionary of Koji build states with the keys being strings and the values being their associated integer.
Returns: a dictionary of Koji build states Return type: dict
-
module_get_scm_info
(scm_url=None, branch=None, check_repo=True)¶ Determines the proper SCM URL and branch based on the arguments. If the user doesn’t specify an SCM URL and branch, then the git repo the user is currently in is used instead.
Parameters: - scm_url (str) – a string of the module’s SCM URL
- branch (str) – a string of the module’s branch
- check_repo (bool) – a boolean that determines if check_repo should be run when an scm_url is not provided.
Returns: a tuple containing a string of the SCM URL and a string of the branch
Return type: tuple
-
module_get_url
(api_url, build_id, action='GET')¶ Get the proper MBS API URL for the desired action
Parameters: - api_url (str) – a string of the URL of the MBS API
- build_id (int) – an integer of the module build desired. If this is set to None, then the base URL for all module builds is returned.
- action (str) – a string determining the HTTP action. If this is set to GET, then the URL will contain ?verbose=true. Any other value will not have verbose set.
Returns: a string of the desired MBS API URL.
Return type: str
-
module_local_build
(file_path, stream, local_builds_nsvs=None, verbose=False, debug=False, skip_tests=False, mbs_config=None, mbs_config_section=None, default_streams=None)¶ A wrapper for mbs-manager build_module_locally.
Parameters: - file_path (str) – a string, path of the module’s modulemd yaml file.
- stream (str) – a string, stream of the module.
- local_builds_nsvs (list) – a list of localbuild ids to import into MBS before running this local build.
- verbose (bool) – a boolean specifying if mbs-manager should be verbose. This is overridden by self.quiet.
- debug (bool) – a boolean specifying if mbs-manager should be debug. This is overridden by self.quiet and verbose.
- skip_tests (bool) – a boolean determining if the check sections should be skipped.
- mbs_config (str) – a string, path to alternative MBS config file to use.
- mbs_config_section (str) – a string, name of alternative config section to use.
- default_streams (list[str]) – a list, contains strings with default name:stream pairs which are passed to mbs-manager using the ‘-s’ command line argument.
Returns: None
-
module_overview
(api_url, limit=10, finished=True)¶ Show the overview of the latest builds in MBS
Parameters: - api_url (str) – a string of the URL of the MBS API
- limit (int) – an integer of the number of most recent module builds to display. This defaults to 10.
- finished (bool) – a boolean that determines if only finished or unfinished module builds should be displayed. This defaults to True.
Sends authorized request to MBS
Parameters: - verb (str) – a string of the HTTP verb of the request (e.g. POST)
- url (str) – a string of the URL to make the request on.
- body (dict) – a dictionary of the data to send in the authorized request.
- auth_method (str) – a string of the authentication method used by the MBS. Valid methods are oidc and kerberos.
- oidc_id_provider (str) – a string of the OIDC provider when MBS is using OIDC for authentication
- oidc_client_id (str) – a string of the OIDC client ID when MBS is using OIDC for authentication
- oidc_client_secret (str) – a string of the OIDC client secret when MBS is using OIDC for authentication. Based on the OIDC setup, this could be None.
- oidc_scopes (list) – a list of OIDC scopes when MBS is using OIDC for authentication
- kwargs – any additional python-requests keyword arguments.
Returns: a python-requests response object
-
module_submit_build
(api_url, scm_url, branch, auth_method, optional=None, oidc_id_provider=None, oidc_client_id=None, oidc_client_secret=None, oidc_scopes=None)¶ Submit a module build to the MBS
Parameters: - api_url – a string of the URL of the MBS API
- scm_url – a string of the module’s SCM URL
- branch – a string of the module’s branch
- auth_method (str) – a string of the authentication method used by the MBS.
- optional (list[str]) – an optional list of “key=value” to be passed in with the MBS build submission.
- oidc_id_provider (str) – a string of the OIDC provider when MBS is using OIDC for authentication.
- oidc_client_id (str) – a string of the OIDC client ID when MBS is using OIDC for authentication
- oidc_client_secret (str) – a string of the OIDC client secret when MBS is using OIDC for authentication. Based on the OIDC setup, this could be None. :kwarg oidc_scopes: a list of OIDC scopes when MBS is using OIDC for authentication.
Returns: a list of module build IDs that are being built from this request.
Return type: list[int]
-
module_watch_build
(api_url, build_ids)¶ Watches the first MBS build in the list in a loop that updates every 15 seconds. The loop ends when the build state is ‘failed’, ‘done’, or ‘ready’.
Parameters: - api_url (str) – a string of the URL of the MBS API
- build_ids (list[int]) – a list of module build IDs
-
new
()¶ Return changes in a repo since the last tag
-
osbs_config_filename
¶
-
package
¶
-
password
¶ This property ensures the password attribute
-
patch
(suffix, rediff=False)¶ Generate a patch from the expanded source and add it to index
suffix: Look for files named with this suffix to diff rediff: optionally retain any comments in the patch file and rediff
Will create a patch file named name-version-suffix.patch
-
path
¶
-
prep
(arch=None, builddir=None)¶ Run rpmbuild -bp
Parameters: - arch (str) – optional to run prep section for a specific arch. By default, local system arch will be used.
- builddir (str) – an alternative builddir.
-
pull
(rebase=False, norebase=False)¶ Pull changes from the remote repository
Optionally rebase current branch on top of remote branch
Optionally override .git setting to always rebase
-
push
(force=False, extra_config=None)¶ Push changes to the remote repository
-
read_koji_config
()¶ Read Koji config from Koji configuration files or profile
-
repo
¶ This property ensures the repo attribute
-
runas
¶ This property ensures the runas attribute
-
sources
(outdir=None)¶ Download source files
-
srpm
(hashtype=None)¶ Create an srpm using hashtype from content
Requires sources already downloaded. The generated SRPM file will be put into package repository directory.
Parameters: hashtype (str) – an alternative algorithm used for payload file digests.
-
switch_branch
(branch, fetch=True)¶ Switch the working branch
Will create a local branch if one doesn’t already exist, based on <remote>/<branch>
Logs output and returns nothing.
-
topurl
¶ This property ensures the topurl attribute
-
unused_patches
()¶ Discover patches checked into source control that are not used
Returns: a list of unused patches, which may be empty. Return type: list
-
upload
(files, replace=False)¶ Upload source file(s) in the lookaside cache
Both file sources and .gitignore will be updated with uploaded files, and added to index tree eventually.
Parameters: - files (iterable) – an iterable of files to upload.
- replace (bool) – optionally replace the existing tracked sources. Defaults to False.
Raises: rpkgError – if failed to add a file to file sources.
-
user
¶ This property ensures the user attribute
-
verify_files
(builddir=None)¶ Run rpmbuild -bl to verify the %files section
Parameters: builddir (str) – optionally define an alternate builddir.
-
Lookaside¶
-
class
pyrpkg.lookaside.
CGILookasideCache
(hashtype, download_url, upload_url, client_cert=None, ca_cert=None)¶ A class to interact with a CGI-based lookaside cache
-
download
(name, filename, hash, outfile, hashtype=None, **kwargs)¶ Download a source file
Parameters: - name (str) – The name of the module. (usually the name of the SRPM). This can include the namespace as well (depending on what the server side expects).
- filename (str) – The name of the file to download.
- hash (str) – The known good hash of the file.
- outfile (str) – The full path where to save the downloaded file.
- hashtype (str) – Optional. The hash algorithm. (e.g ‘md5’) This defaults to the hashtype passed to the constructor.
- kwargs – Additional keyword arguments. They will be used when constructing the full URL to the file to download.
-
file_is_valid
(filename, hash, hashtype=None)¶ Ensure the file is correct
Parameters: - filename (str) – The full path to the file. It is assumed to exist.
- hash (str) – The known good hash of the file.
- hashtype (str) – Optional. The hash algorithm to use. (e.g ‘md5’) This defaults to the hashtype passed to the constructor.
Returns: True if the file is valid, False otherwise.
Return type: bool
-
get_download_url
(name, filename, hash, hashtype=None, **kwargs)¶
-
hash_file
(filename, hashtype=None)¶ Compute the hash of a file
Parameters: - filename (str) – The full path to the file. It is assumed to exist.
- hashtype (str) – Optional. The hash algorithm to use. (e.g ‘md5’) This defaults to the hashtype passed to the constructor.
Returns: The hash digest.
-
print_progress
(to_download, downloaded, to_upload, uploaded)¶
-
raise_upload_error
(http_status)¶
-
remote_file_exists
(name, filename, hash)¶ Verify whether a file exists on the lookaside cache
Parameters: - name (str) – The name of the module. (usually the name of the SRPM). This can include the namespace as well (depending on what the server side expects).
- filename (str) – The name of the file to check for.
- hash (str) – The known good hash of the file.
-
upload
(name, filepath, hash)¶ Upload a source file
Parameters: - name (str) – The name of the module. (usually the name of the SRPM) This can include the namespace as well (depending on what the server side expects).
- filepath (str) – The full path to the file to upload.
- hash (str) – The known good hash of the file.
-
Sources¶
-
class
pyrpkg.sources.
SourcesFile
(sourcesfile, entry_type, replace=False)¶ -
add_entry
(hashtype, file, hash)¶
-
parse_line
(line)¶
-
write
()¶
-
-
class
pyrpkg.sources.
SourceFileEntry
(hashtype, file, hash)¶
-
class
pyrpkg.sources.
BSDSourceFileEntry
(hashtype, file, hash)¶
gitignore¶
-
class
pyrpkg.gitignore.
GitIgnore
(path)¶ A class to manage a .gitignore file
-
add
(line)¶ Add a line
Parameters: line (str) – The line to add to the file. It will not be added if it already matches an existing line.
-
match
(line)¶ Check whether the line matches an existing one
This uses fnmatch to match against wildcards.
Parameters: line (str) – The new line to match against existing ones. Returns: True if the new line matches, False otherwise. Return type: bool
-
write
()¶ Write the file to the disk
This will only actually write if necessary, that is if lines have been added since the last time the file was written.
-
Package Repository¶
-
class
pyrpkg.pkgrepo.
PackageRepository
(path, default_branch_remote='origin', overwritten_branch_merge=None)¶ Represent a package repository
-
active_branch
¶
-
branch_merge
¶ This property ensures the branch attribute
-
branch_remote
¶ This property ensures the branch_remote attribute
-
check
(is_dirty=True, all_pushed=True)¶ Check various status of current repository
Parameters: - is_dirty (bool) – Default to True. To check whether there is uncommitted changes.
- all_pushed (bool) – Default to True. To check whether all changes are pushed.
Raises: rpkgError – if any unexpected status is detected. For example, if changes are not committed yet.
- NOTE: has_namespace is removed because it should belong to package
- metadata and be handled there using package repository information provided by this module.
-
commit_hash
¶ This property ensures the commit attribute
-
fetch_remotes
()¶ Fetch from all remotes
-
git
¶
-
git_dir
¶
-
heads
¶
-
index
¶
-
is_dirty
()¶
-
iter_commits
()¶
-
list_branches
()¶ Returns a tuple of local and remote branch names
-
load_branch_merge
()¶ Find the remote tracking branch from the branch we’re on.
The goal of this function is to catch if we are on a branch we can make some assumptions about. If there is no merge point then we raise and ask the user to specify.
- NOTE: do not handle default branch merge. Command line option –release
- overrides return value from this method, which should be handled in caller side.
-
load_branch_remote
()¶ Find the name of remote from branch we’re on.
-
load_commit
()¶ Discover the latest commit to the package
-
load_push_url
()¶ Find the pushurl or url of remote of branch we’re on.
-
path
¶
-
push_url
¶ This property ensures the push_url attribute
-
repo
¶
-
Package Metadata¶
-
class
pyrpkg.pkginfo.
PackageMetadata
(repo, overwrite_target=None, distgit_namespaced=True)¶ Package metadata
Parameters: - repo (
PackageRepository
) – object ofPackageRepository
representing underlying git repository. - distgit_namespaced (bool) – namespace is enabled in dist-git or not.
-
container_build_target
¶ This property ensures the target for container builds.
-
disttag
¶ This property ensures the disttag attribute
-
distval
¶ This property ensures the distval attribute
-
distvar
¶ This property ensures the distvar attribute
-
epoch
¶ This property ensures the epoch attribute
-
load_container_build_target
()¶ This creates a target based on git branch and namespace.
-
load_localarch
()¶ Get the local arch as defined by rpm
-
load_mockconfig
()¶ This sets the mockconfig attribute
-
load_module_name
()¶
-
load_nameverrel
()¶ Set the release of a package module.
-
load_ns
()¶ Loads the namespace
-
load_nvr
()¶ This sets the nvr attribute
-
load_repo_name
()¶ Loads repository name
-
load_rpmdefines
()¶ Populate rpmdefines based on current active branch
-
load_spec
()¶ This sets the spec attribute
-
load_target
()¶ This creates the target attribute based on branch merge
-
localarch
¶ This property ensures the module attribute
-
mockconfig
¶ This property ensures the mockconfig attribute
-
module_name
¶ This property ensures the module attribute
-
ns
¶ This property provides the namespace of the module
-
ns_module_name
¶
-
ns_repo_name
¶
-
nvr
¶ This property ensures the nvr attribute
-
rel
¶ This property ensures the rel attribute
-
repo_name
¶ Property to get repository name
-
rpmdefines
¶ This property ensures the rpm defines
-
sources_filename
¶ File name of sources
-
spec
¶ This property ensures the module attribute
-
srpm_filename
¶
-
target
¶ This property ensures the target attribute
-
ver
¶ This property ensures the ver attribute
- repo (
Utilities¶
-
class
pyrpkg.utils.
cached_property
¶ A property caching its return value
This is pretty much the same as a normal Python property, except that the decorated function is called only once. Its return value is then saved, subsequent calls will return it without executing the function any more.
- Example:
>>> class Foo(object): ... @cached_property ... def bar(self): ... print("Executing Foo.bar...") ... return 42 ... >>> f = Foo() >>> f.bar Executing Foo.bar... 42 >>> f.bar 42
-
pyrpkg.utils.
warn_deprecated
(clsname, oldname, newname)¶ Emit a deprecation warning
Parameters: - clsname (str) – The name of the class which has its attribute deprecated.
- oldname (str) – The name of the deprecated attribute.
- newname (str) – The name of the new attribute, which should be used instead.
-
pyrpkg.utils.
_log_value
(log_func, value, level, indent, suffix='')¶
-
pyrpkg.utils.
log_result
(log_func, result, level=0, indent=2)¶