Python bindings

This module provides Python bindings to the Bodhi REST API.

class bodhi.client.bindings.BodhiClient(base_url='https://bodhi.fedoraproject.org/', username=None, password=None, staging=False, **kwargs)[source]

Bases: fedora.client.openidbaseclient.OpenIdBaseClient

Python bindings to the Bodhi server REST API.

candidates()[source]

Get a list list of update candidates.

Returns:A list of koji builds (dictionaries returned by koji.listTagged()) that are tagged as candidate builds and are owned by the current user.
Return type:list
comment(update, comment, karma=0, email=None)[source]

Add a comment to an update.

Parameters:
  • update (basestring) – The title of the update comment on.
  • comment (basestring) – The text of the comment to add to the update.
  • karma (int) – The amount of karma to leave. May be -1, 0, or 1. Defaults to 0.
  • email (basestring or None) – Email address for an anonymous user. If an email address is supplied here, the comment is added as anonymous (i.e. not a logged in user).
Returns:

The response from the post to comments/.

Return type:

munch.Munch

static compose_str(compose, minimal=True)[source]

Return a string representation of a compose.

Parameters:
  • compose (dict) – A dictionary representation of a Compose.
  • minimal (bool) – If True, return a minimal one-line representation of the compose. Otherwise, return a more verbose string. Defaults to True.
Returns:

A human readable string describing the compose.

Return type:

basestring

csrf()[source]

Return the CSRF token if alread aquired, otherwise login, get a CSRF, cache it, and return.

If there is already a CSRF token, this method returns it.

If there is not, this method ensures that we know the username, logs in if we aren’t already logged in aquires and caches a CSRF token, and returns it.

get_compose(release, request)[source]

Get information about compose.

Parameters:
  • release (basestring) – The name of the release.
  • request (basestring) – The request (testing, stable).
Returns:

The response from Bodhi to the request.

Return type:

munch.Munch

Raises:

ComposeNotFound – If the server returns a 404 error code.

get_koji_session()[source]

Return an authenticated koji session.

Returns:An intialized authenticated koji client.
Return type:koji.ClientSession
get_releases(**kwargs)[source]

Return a list of bodhi releases.

This method returns a dictionary in the following format:

{"releases": [
    {"dist_tag": "dist-f12", "id_prefix": "FEDORA",
     "locked": false, "name": "F12", "long_name": "Fedora 12"}]}
Parameters:kwargs (dict) – A dictionary of extra parameters to pass along with the request.
Returns:A dictionary describing Bodhi’s release objects.
Return type:dict
get_test_status(update)[source]

Query bodhi for the test status of the specified update..

Parameters:update (basestring) – The title or identifier of the update to retrieve the test status of.
Returns:The response from Bodhi describing the query results.
Return type:munch.Munch
init_username()[source]

Check to see if the username attribute on self is set, and set if if it is not.

If the username is already set on self, return.

If the username is not already set on self, attempt to find if there is a username that has successfully authenticated in the Fedora session file. If that doesn’t work, fall back to prompting the terminal for a username. Once the username has been set, re-run self._load_cookies() so we can re-use the user’s last session.

koji_session

Return an authenticated koji session.

Returns:An intialized authenticated koji client.
Return type:koji.ClientSession
latest_builds(package)[source]

Get the latest builds for a package.

Parameters:package (basestring) – The package name, for example “kernel”.
Returns:
A dict-like object of the release dist tag to the
latest build.
Return type:munch.Munch
list_composes()[source]

List composes.

Returns:A dictionary-like representation of the Composes.
Return type:munch.Munch
list_overrides(user=None, packages=None, expired=None, releases=None, builds=None, rows_per_page=None, page=None)[source]

List buildroot overrides.

Parameters:
  • user (basestring) – A username whose buildroot overrides you want returned.
  • packages (basestring) – Comma separated package names to filter buildroot overrides by.
  • expired (bool) – If True, only return expired overrides. If False, only return active overrides.
  • releases (basestring) – Comma separated Release shortnames to filter buildroot overrides by.
  • builds (basestring) – Comma separated build NVRs to filter overrides by.
  • rows_per_page (int) – Limit the results to a certain number of rows per page. (default:None)
  • page (int) – Return a specific page of results. (default:None)
static override_str(override, minimal=True)[source]

Return a string representation of a given override dictionary.

Parameters:
  • override (dict) – An override dictionary.
  • minimal (bool) – If True, return a minimal one-line representation of the override. Otherwise, return a more verbose string. Defaults to True.
Returns:

A human readable string describing the given override.

Return type:

basestring

parse_file(input_file)[source]

Parse an update template file.

Parameters:input_file (basestring) – The filename of the update template.
Returns:
A list of dictionaries of parsed update values which
can be directly passed to the save method.
Return type:list
Raises:ValueError – If the input_file does not exist, or if it cannot be parsed.
password

Return the user’s password.

If the user’s password is not known, prompt the user for their password.

Returns:The user’s password.
Return type:basestring
query(**kwargs)[source]

Query bodhi for a list of updates.

Parameters:
  • title (basestring) – The update title.
  • alias (basestring) – The update alias.
  • updateid (basestring) – The update ID (eg: FEDORA-2015-0001).
  • content_type (basestring) – A content type (rpm, module) to limit the query to.
  • releases (basestring) – A comma separated list of releases that you wish to query updates for.
  • active_releases (bool) – A boolean to filter only updates for active releases.
  • status (basestring) – The update status (pending, testing, stable, obsolete, unpushed, processing)
  • type (basestring) – The type of the update: security, bugfix, enhancement, and newpackage.
  • bugs (basestring) – A comma separated list of Red Hat Bugzilla IDs.
  • request (basestring) – An update request to query for testing, stable, unpush, obsolete or None.
  • mine (bool) – If True, only query the users updates. Default: False.
  • packages (basestring) – A space or comma delimited list of package names.
  • limit (int) – A deprecated argument, sets rows_per_page. See its docstring for more info.
  • approved_before (basestring) – A datetime string.
  • approved_since (basestring) – A datetime string.
  • builds (basestring) – A space or comma delimited string of build nvrs.
  • critpath (bool) – A boolean to query only critical path updates.
  • cves (basestring) – Filter by CVE IDs.
  • locked (bool) – A boolean to filter only locked updates.
  • modified_before (basestring) – A datetime string to query updates that have been modified before a certain time.
  • modified_since (basestring) – A datetime string to query updates that have been modified since a certain time.
  • pushed (bool) – A boolean to filter only pushed updates.
  • pushed_before (basestring) – A datetime string to filter updates pushed before a certain time.
  • pushed_since (basestring) – A datetime string to filter updates pushed since a certain time.
  • severity (basestring) – A severity type to filter by (unspecified, urgent, high, medium, low).
  • submitted_before (basestring) – A datetime string to filter updates submitted before a certain time.
  • submitted_since (basestring) – A datetime string to filter updates submitted after a certain time.
  • suggest (basestring) – Query for updates that suggest a user restart (logout, reboot).
  • user (basestring) – Query for updates submitted by a specific user.
  • rows_per_page (int) – Limit the results to a certain number of rows per page (min:1 max: 100 default: 20).
  • page (int) – Return a specific page of results.
Returns:

The response from Bodhi describing the query results.

Return type:

munch.Munch

request(update, request)[source]

Request an update state change.

Parameters:
  • update (basestring) – The title of the update.
  • request (basestring) – The request (testing, batched, stable, obsolete, unpush, revoke).
Returns:

The response from Bodhi to the request.

Return type:

munch.Munch

Raises:

UpdateNotFound – If the server returns a 404 error code.

save(**kwargs)[source]

Save an update.

This entails either creating a new update, or editing an existing one. To edit an existing update, you must specify the update title in the edited keyword argument.

Parameters:
  • builds (basestring) – A list of koji builds for this update.
  • type (basestring) – The type of this update: security, bugfix, enhancement, and newpackage.
  • bugs (basestring) – A list of Red Hat Bugzilla ID’s associated with this update.
  • notes (basestring) – Details as to why this update exists.
  • request (basestring) – Request for this update to change state, either to testing, stable, unpush, obsolete or None.
  • close_bugs (bool) – Close bugs when update is stable.
  • suggest (basestring) – Suggest that the user reboot or logout after update. (reboot, logout).
  • inheritance (bool) – Follow koji build inheritance, which may result in this update being pushed out to additional releases.
  • autokarma (bool) – Allow bodhi to automatically change the state of this update based on the karma from user feedback. It will push your update to stable once it reaches the stable_karma and unpush your update when reaching unstable_karma.
  • stable_karma (int) – The upper threshold for marking an update as stable.
  • unstable_karma (int) – The lower threshold for unpushing an update.
  • edited (basestring) – The update title of the existing update that we are editing.
  • severity (basestring) – The severity of this update (urgent, high, medium, low).
  • requirements (basestring) – A list of required Taskotron tests that must pass for this update to reach stable. (e.g. dist.rpmdeplint, dist.upgradepath, dist.rpmlint, etc).
  • require_bugs (bool) – A boolean to require that all of the bugs in your update have been confirmed by testers.
  • require_testcases (bool) – A boolean to require that this update passes all test cases before reaching stable.
Returns:

The Bodhi server’s response to the request.

Return type:

munch.Munch

save_override(nvr, duration, notes, edit=False, expired=False)[source]

Save a buildroot override.

This entails either creating a new buildroot override, or editing an existing one.

Parameters:
  • nvr (basestring) – The nvr of a koji build.
  • duration (int) – Number of days from now that this override should expire.
  • notes (basestring) – Notes about why this override is in place.
  • edit (bool) – True if we are editing an existing override, False otherwise. Defaults to False.
  • expired (bool) – Set to True to expire an override. Defaults to False.
Returns:

A dictionary-like representation of the saved override.

Return type:

munch.Munch

testable()[source]

Return a generator that iterates installed testing updates.

This method is a generator that yields packages that you currently have installed that you have yet to test and provide feedback for.

Only works on systems with dnf.

Returns:
An iterable of dictionaries describing updates that match builds installed on
the local system.
Return type:generator
Raises:RuntimeError – If the dnf Python bindings are not installed.
update_str(update, minimal=False)[source]

Return a string representation of a given update dictionary.

Parameters:
  • update (dict) – An update dictionary, acquired by the list method.
  • minimal (bool) – If True, return a minimal one-line representation of the update. Otherwise, return a more verbose representation. Defaults to False.
Returns:

A human readable string describing the given update.

Return type:

basestring

waive(update, comment, tests=None)[source]

Waive unsatisfied requirements on an update.

Parameters:
  • update (basestring) – The title of the update.
  • comment (basestring) – A comment explaining the waiver.
  • tests (tuple(basestring) or None) – The list of unsatisfied requirements to waive. If not specified, all unsatisfied requirements of this update will be waived.
Returns:

The response from Bodhi to the request.

Return type:

munch.Munch

Raises:

UpdateNotFound – If the server returns a 404 error code.

exception bodhi.client.bindings.BodhiClientException[source]

Bases: fedora.client.FedoraClientError

Used to indicate there was an error in the client.

exception bodhi.client.bindings.ComposeNotFound(release, request)[source]

Bases: bodhi.client.bindings.BodhiClientException

Used to indicate that a referenced Compose is not found on the server.

exception bodhi.client.bindings.UpdateNotFound(update)[source]

Bases: bodhi.client.bindings.BodhiClientException

Used to indicate that a referenced Update is not found on the server.

bodhi.client.bindings.errorhandled(method)[source]

Raise exceptions on failure. Used as a decorator for BodhiClient methods.