API Documentation

Client

Module author: Luke Macken <lmacken@redhat.com>

Module author: Toshio Kuratomi <tkuratom@redhat.com>

exception fedora.client.FedoraServiceError

Base Exception for any problem talking with the Service.

When the Client gets an error talking to the server, an exception of this type is raised. This can be anything in the networking layer up to an error returned from the server itself.

exception fedora.client.ServerError

Unable to talk to the server properly.

This includes network errors and 500 response codes.

exception fedora.client.AuthError
Error during authentication. For instance, invalid password.
exception fedora.client.AppError
Error condition that the server is passing back to the client.
exception fedora.client.FedoraClientError

Base Exception for problems which originate within the Clients.

This should be the base class for any exceptions that the Client generates generate. For instance, if the client performs validation before passing the data on to the Fedora Service.

Problems returned while talking to the Services should be returned via a FedoraServiceError instead.

class fedora.client.DictContainer

dict whose members can be accessed via attribute lookup.

One thing to note: You can have an entry in your container that is visible instead of a standard dict method. So, for instance, you can have this happen:

>>> d = DictContainer({'keys': 'key'})
>>> d.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

So, as a safety precaution, you should be sure to access things via the dict methods:

>>> d = DictContainer({'keys': 'key'})
>>> dict.keys(d)
['keys']

The special methods like __getitem__(), __getattr__(), setattr(), etc that are invoked through alternate syntax rather than called directly as a method are immune to this so you can do this with no ill effects:

>>> d.__setattr__ = 1000
>>> d.__getattr__ = 10
>>> print d.__setattr__
1000
>>> print d.__getattr__
10
exception fedora.client.FASError
FAS Error
exception fedora.client.CLAError
CLA Error
exception fedora.client.BodhiClientException
exception fedora.client.PackageDBError
Errors generated by the PackageDB Client.
class fedora.client.ProxyClient(base_url, useragent=None, session_name='tg-visit', session_as_cookie=True, debug=False)

A client to a Fedora Service. This class is optimized to proxy multiple users to a service. ProxyClient is designed to be threadsafe so that code can instantiate one instance of the class and use it for multiple requests for different users from different threads.

If you want something that can manage one user’s connection to a Fedora Service, then look into using BaseClient instead.

debug
When True, we log extra debugging statements. When False, we only log errors.
send_request(method, req_params=None, auth_params=None)

Make an HTTP request to a server method.

The given method is called with any parameters set in req_params. If auth is True, then the request is made with an authenticated session cookie. Note that path parameters should be set by adding onto the method, not via req_params.

Parameters:
  • method – Method to call on the server. It’s a url fragment that comes after the base_url set in __init__(). Note that any parameters set as extra path information should be listed here, not in req_params.
  • req_params – dict containing extra parameters to send to the server
  • auth_params

    dict containing one or more means of authenticating to the server. Valid entries in this dict are:

    cookie:Deprecated Use session_id instead. If both cookie and session_id are set, only session_id will be used. A Cookie.SimpleCookie to send as a session cookie to the server
    session_id:Session id to put in a cookie to construct an identity for the server
    username:Username to send to the server
    password:Password to use with username to send to the server

    Note that cookie can be sent alone but if one of username or password is set the other must as well. Code can set all of these if it wants and all of them will be sent to the server. Be careful of sending cookies that do not match with the username in this case as the server can decide what to do in this case.

Returns:

If ProxyClient is created with session_as_cookie=True (the default), a tuple of session cookie and data from the server. If ProxyClient was created with session_as_cookie=False, a tuple of session_id and data instead.

Return type:

tuple of session information and data from server

class fedora.client.BaseClient(base_url, useragent=None, debug=False, username=None, password=None, session_cookie=None, session_id=None, session_name='tg-visit', cache_session=True)

A client for interacting with web services.

logout()
Logout from the server.
send_request(method, req_params=None, auth=False, **kwargs)

Make an HTTP request to a server method.

The given method is called with any parameters set in req_params. If auth is True, then the request is made with an authenticated session cookie.

Parameters:
  • method – Method to call on the server. It’s a url fragment that comes after the base_url set in __init__().
  • req_params – Extra parameters to send to the server.
  • auth – If True perform auth to the server, else do not.
Returns:

The data from the server

Return type:

DictContainer

Deprecated The session_cookie.

The session cookie is saved in a file in case it is needed in consecutive runs of BaseClient.

session_id

The session_id.

The session id is saved in a file in case it is needed in consecutive runs of BaseClient.

class fedora.client.AccountSystem(base_url='https://admin.fedoraproject.org/accounts/', *args, **kwargs)

An object for querying the Fedora Account System.

The Account System object provides a python API for talking to the Fedora Account System. It abstracts the http requests, cookie handling, and other details so you can concentrate on the methods that are important to your program.

get_config(username, application, attribute)

Return the config entry for the key values.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • attribute – Attribute key to lookup
Raises AppError:
 

if the server returns an exception

Returns:

The unicode string that describes the value. If no entry matched the username, application, and attribute then None is returned.

get_configs_like(username, application, pattern=u'*')

Return the config entries that match the keys and the pattern.

Note: authentication on the server will prevent anyone but the user or a fas admin from viewing or changing their configs.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • pattern – A pattern to select values for. This accepts * as a wildcard character. Default=’*’
Raises AppError:
 

if the server returns an exception

Returns:

A dict mapping attribute to value.

group_by_id(group_id)
Returns a group object based on its id
group_by_name(groupname)
Returns a group object based on its name
group_data()

Return the administrators/sponsors/users and group type for all groups.

Raises AppError:
 if the query failed on the server
Returns:A dict mapping group names to the group type and the user IDs of the administrator, sponsors, and users of the group.
group_members(groupname)

Return a list of people approved for a group.

This method returns a list of people who are in the requested group. The people are all approved in the group. Unapproved people are not shown. The format of data is:

\[{'username': 'person1', 'role_type': 'user'},
\{'username': 'person2', 'role_type': 'sponsor'}]

role_type can be one of ‘user’, ‘sponsor’, or ‘administrator’.

people_by_groupname(groupname)

Return a list of persons for the given groupname.

Parameters:
  • groupname – Name of the group to look up
Returns:

A list of person objects from the group. If the group contains no entries, then an empty list is returned.

people_by_id()

Deprecated Use people_by() instead.

Returns a dict relating user IDs to human_name, email, username, and bugzilla email

people_by_key(key=u'username', search=u'*', fields=None)

Return a dict of people

Parameters:
  • key – Key by this field. Valid values are ‘id’, ‘username’, or ‘email’. Default is ‘username’
  • search – Pattern to match usernames against. Defaults to the ‘*’ wildcard which matches everyone.
  • fields

    Limit the data returned to a specific list of fields. The default is to retrieve all fields. Valid fields are:

    • username
    • certificate_serial
    • locale
    • creation
    • telephone
    • status_change
    • id
    • password_changed
    • privacy
    • comments
    • latitude
    • email
    • status
    • gpg_keyid
    • internal_comments
    • postal_address
    • unverified_email
    • ssh_key
    • passwordtoken
    • ircnick
    • password
    • emailtoken
    • longitude
    • facsimile
    • human_name
    • last_seen
    • bugzilla_email

    Note that for most users who access this data, many of these fields will be set to None due to security or privacy settings.

Returns:

a dict relating the key value to the fields.

person_by_id(person_id)
Returns a person object based on its id
person_by_username(username)
Returns a person object based on its username
set_config(username, application, attribute, value)

Set a config entry in FAS for the user.

Note: authentication on the server will prevent anyone but the user or a fas admin from viewing or changing their configs.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • attribute – The name of the config key that we’re setting
  • value – The value to set this to
Raises AppError:
 

if the server returns an exception

user_data()

Return user data for all users in FAS

Note: If the user is not authorized to see password hashes, ‘*’ is returned for the hash.

Raises AppError:
 if the query failed on the server
Returns:A dict mapping user IDs to a username, password hash, SSH public key, email address, and status.
user_gencert()
Generate a cert for a user
user_id()
Returns a dict relating user IDs to usernames
verify_password(username, password)

Return whether the username and password pair are valid.

Parameters:
  • username – username to try authenticating
  • password – password for the user
Returns:

True if the username/password are valid. False otherwise.

class fedora.client.PackageDB(base_url='https://admin.fedoraproject.org/pkgdb/', *args, **kwargs)

Provide an easy to use interface to the PackageDB.

add_edit_package(pkg, owner=None, description=None, branches=None, cc_list=None, comaintainers=None, groups=None)

Add or edit a package to the database.

Parameters:
  • pkg – Name of the package to edit
  • owner – If set, make this person the owner of both branches
  • description – If set, make this the description of both branches
  • branches – List of branches to operate on
  • cc_list – If set, list or tuple of usernames to watch the package.
  • comaintainers – If set, list or tuple of usernames to comaintain the package.
  • groups – If set, list or tuple of group names that can commit to the package.
Raises AppError:
 

If the server returns an error

This method takes information about a package and either edits the package to reflect the changes to information or adds the package to the database.

Note: This method will be going away in favor of methods that do smaller chunks of work:

  1. A method to add a new package
  2. A method to add a new branch
  3. A method to edit an existing package
  4. A method to edit and existing branch
canonical_branch_name(branch)

Change a branch abbreviation into a name and version.

Parameters:
  • branch – branch abbreviation
Return type:

tuple

Returns:

tuple of branch name and branch version.

Example: >>> name, version = canonical_branch_name(‘FC-6’) >>> name Fedora >>> version 6

clone_branch(pkg, branch, master, email_log=True)

Set a branch’s permissions from a pre-existing branch.

Parameters:
  • pkg – Name of the package to branch
  • branch

    Branch to clone to. Allowed branch names are listed in COLLECTIONMAP

  • master – Short branch name to clone from. Allowed branch names are listed in COLLECTIONMAP
  • email_log – If False, do not email a copy of the log.
Raises AppError:
 

If the server returns an exceptiom

get_owners(package, collection=None, collection_ver=None)

Retrieve the ownership information for a package.

Parameters:
  • package – Name of the package to retrieve package information about.
  • collection – Limit the returned information to this collection (‘Fedora’, ‘Fedora EPEL’, Fedora OLPC’, etc)
  • collection_ver – If collection is specified, further limit to this version of the collection.
Raises AppError:
 

If the server returns an error

Return type:

DictContainer

Returns:

dict of ownership information for the package

get_package_info(pkg, branch=None)

Get information about the package.

Parameters:
  • pkg – Name of the package
  • branch – If given, restrict information returned to this branch Allowed branches are listed in COLLECTIONMAP
Raises AppError:
 

If the server returns an exceptiom

Returns:

Package ownership information

Return type:

fedora.client.DictContainer

mass_branch(branch)

Branch all unblocked packages for a new release.

Mass branching always works against the devel branch.

Parameters:
  • branch – Branch name to create branches for. Names are listed in COLLECTIONMAP
Raises AppError:
 

If the server returns an exceptiom. The ‘extras’ attribute will contain a list of unbranched packages if some of the packages were branched

class fedora.client.BodhiClient(base_url='https://admin.fedoraproject.org/updates/', useragent='Fedora Bodhi Client/0.5.1', *args, **kwargs)
candidates()

Get a list list of update candidates.

This method is a generator that returns a list of koji builds that could potentially be pushed as updates.

comment(update, comment, karma=0)

Add a comment to an update.

Parameters:
  • update – The title of the update comment on.
  • comment – The text of the comment.
  • karma – The karma of this comment (-1, 0, 1)
delete(update)

Delete an update.

Parameters:
  • update – The title of the update to delete
koji_session
Return an authenticated koji session
latest_builds(package)

Get a list of the latest builds for this package.

Parameters:
  • package – package name to find builds for.
Returns:

a dictionary of the release dist tag to the latest build.

masher()
Return the status of bodhi’s masher
parse_file(input_file)

Parse an update template file.

Parameters:
  • input_file – The filename of the update template.

Returns an array of dictionaries of parsed update values which can be directly passed to the save method.

push()
Return a list of requests
push_updates(updates)

Push a list of updates.

Parameters:
  • updates – A list of update titles to push.
query(release=None, status=None, type_=None, bugs=None, request=None, mine=None, package=None, username=None, limit=10)

Query bodhi for a list of updates.

Parameters:
  • release – The release that you wish to query updates for.
  • status – The update status (pending, testing, stable, obsolete)
  • type – The type of this update: security, bugfix, enhancement, and newpackage.
  • bugs – A list of Red Hat Bugzilla ID’s
  • request – An update request to query for testing, stable, unpush, obsolete or None.
  • mine – If True, only query the users updates. Default: False.
  • package – A package name or a name-version-release.
  • limit – The maximum number of updates to display. Default: 10.
request(update, request)

Request an update state change.

Parameters:
  • update – The title of the update
  • request – The request (testing, stable, obsolete, revoke)
save(builds='', type_='', bugs='', notes='', request='testing', close_bugs=True, suggest_reboot=False, inheritance=False, autokarma=True, stable_karma=3, unstable_karma=-3, edited='')

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 – A list of koji builds for this update.
  • type_ – The type of this update: security, bugfix, enhancement, and newpackage.
  • bugs – A list of Red Hat Bugzilla ID’s associated with this update.
  • notes – Details as to why this update exists.
  • request – Request for this update to change state, either to testing, stable, unpush, obsolete or None.
  • close_bugs – Close bugs when update is stable
  • suggest_reboot – Suggest that the user reboot after update.
  • inheritance – Follow koji build inheritance, which may result in this update being pushed out to additional releases.
  • autokarma – 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 – The upper threshold for marking an update as stable.
  • unstable_karma – The lower threshold for unpushing an update.
  • edited – The update title of the existing update that we are editing.
testable()

Get a list of installed testing updates.

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

update_str(update, minimal=False)

Return a string representation of a given update dictionary.

Parameters:
  • update – An update dictionary, acquired by the list method.
  • minimal – Return a minimal one-line representation of the update.
class fedora.client.Wiki(base_url='http://fedoraproject.org/w/', *args, **kw)
get_recent_changes(now, then, limit=500)
Get recent wiki changes from now until then
login(username, password)
print_recent_changes(days=7, show=10)
exception fedora.client.FASError
FAS Error
exception fedora.client.CLAError
CLA Error
exception fedora.client.BodhiClientException

Generic Clients

BaseClient

class fedora.client.BaseClient(base_url, useragent=None, debug=False, username=None, password=None, session_cookie=None, session_id=None, session_name='tg-visit', cache_session=True)

A client for interacting with web services.

logout()
Logout from the server.
send_request(method, req_params=None, auth=False, **kwargs)

Make an HTTP request to a server method.

The given method is called with any parameters set in req_params. If auth is True, then the request is made with an authenticated session cookie.

Parameters:
  • method – Method to call on the server. It’s a url fragment that comes after the base_url set in __init__().
  • req_params – Extra parameters to send to the server.
  • auth – If True perform auth to the server, else do not.
Returns:

The data from the server

Return type:

DictContainer

session_cookie

Deprecated The session_cookie.

The session cookie is saved in a file in case it is needed in consecutive runs of BaseClient.

session_id

The session_id.

The session id is saved in a file in case it is needed in consecutive runs of BaseClient.

ProxyClient

class fedora.client.ProxyClient(base_url, useragent=None, session_name='tg-visit', session_as_cookie=True, debug=False)

A client to a Fedora Service. This class is optimized to proxy multiple users to a service. ProxyClient is designed to be threadsafe so that code can instantiate one instance of the class and use it for multiple requests for different users from different threads.

If you want something that can manage one user’s connection to a Fedora Service, then look into using BaseClient instead.

debug
When True, we log extra debugging statements. When False, we only log errors.
send_request(method, req_params=None, auth_params=None)

Make an HTTP request to a server method.

The given method is called with any parameters set in req_params. If auth is True, then the request is made with an authenticated session cookie. Note that path parameters should be set by adding onto the method, not via req_params.

Parameters:
  • method – Method to call on the server. It’s a url fragment that comes after the base_url set in __init__(). Note that any parameters set as extra path information should be listed here, not in req_params.
  • req_params – dict containing extra parameters to send to the server
  • auth_params

    dict containing one or more means of authenticating to the server. Valid entries in this dict are:

    cookie:Deprecated Use session_id instead. If both cookie and session_id are set, only session_id will be used. A Cookie.SimpleCookie to send as a session cookie to the server
    session_id:Session id to put in a cookie to construct an identity for the server
    username:Username to send to the server
    password:Password to use with username to send to the server

    Note that cookie can be sent alone but if one of username or password is set the other must as well. Code can set all of these if it wants and all of them will be sent to the server. Be careful of sending cookies that do not match with the username in this case as the server can decide what to do in this case.

Returns:

If ProxyClient is created with session_as_cookie=True (the default), a tuple of session cookie and data from the server. If ProxyClient was created with session_as_cookie=False, a tuple of session_id and data instead.

Return type:

tuple of session information and data from server

Clients for Specific Services

Fedora Account System

class fedora.client.AccountSystem(base_url='https://admin.fedoraproject.org/accounts/', *args, **kwargs)

An object for querying the Fedora Account System.

The Account System object provides a python API for talking to the Fedora Account System. It abstracts the http requests, cookie handling, and other details so you can concentrate on the methods that are important to your program.

get_config(username, application, attribute)

Return the config entry for the key values.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • attribute – Attribute key to lookup
Raises AppError:
 

if the server returns an exception

Returns:

The unicode string that describes the value. If no entry matched the username, application, and attribute then None is returned.

get_configs_like(username, application, pattern=u'*')

Return the config entries that match the keys and the pattern.

Note: authentication on the server will prevent anyone but the user or a fas admin from viewing or changing their configs.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • pattern – A pattern to select values for. This accepts * as a wildcard character. Default=’*’
Raises AppError:
 

if the server returns an exception

Returns:

A dict mapping attribute to value.

group_by_id(group_id)
Returns a group object based on its id
group_by_name(groupname)
Returns a group object based on its name
group_data()

Return the administrators/sponsors/users and group type for all groups.

Raises AppError:
 if the query failed on the server
Returns:A dict mapping group names to the group type and the user IDs of the administrator, sponsors, and users of the group.
group_members(groupname)

Return a list of people approved for a group.

This method returns a list of people who are in the requested group. The people are all approved in the group. Unapproved people are not shown. The format of data is:

\[{'username': 'person1', 'role_type': 'user'},
\{'username': 'person2', 'role_type': 'sponsor'}]

role_type can be one of ‘user’, ‘sponsor’, or ‘administrator’.

people_by_groupname(groupname)

Return a list of persons for the given groupname.

Parameters:
  • groupname – Name of the group to look up
Returns:

A list of person objects from the group. If the group contains no entries, then an empty list is returned.

people_by_id()

Deprecated Use people_by() instead.

Returns a dict relating user IDs to human_name, email, username, and bugzilla email

people_by_key(key=u'username', search=u'*', fields=None)

Return a dict of people

Parameters:
  • key – Key by this field. Valid values are ‘id’, ‘username’, or ‘email’. Default is ‘username’
  • search – Pattern to match usernames against. Defaults to the ‘*’ wildcard which matches everyone.
  • fields

    Limit the data returned to a specific list of fields. The default is to retrieve all fields. Valid fields are:

    • username
    • certificate_serial
    • locale
    • creation
    • telephone
    • status_change
    • id
    • password_changed
    • privacy
    • comments
    • latitude
    • email
    • status
    • gpg_keyid
    • internal_comments
    • postal_address
    • unverified_email
    • ssh_key
    • passwordtoken
    • ircnick
    • password
    • emailtoken
    • longitude
    • facsimile
    • human_name
    • last_seen
    • bugzilla_email

    Note that for most users who access this data, many of these fields will be set to None due to security or privacy settings.

Returns:

a dict relating the key value to the fields.

person_by_id(person_id)
Returns a person object based on its id
person_by_username(username)
Returns a person object based on its username
set_config(username, application, attribute, value)

Set a config entry in FAS for the user.

Note: authentication on the server will prevent anyone but the user or a fas admin from viewing or changing their configs.

Parameters:
  • username – Username of the person
  • application – Application for which the config is set
  • attribute – The name of the config key that we’re setting
  • value – The value to set this to
Raises AppError:
 

if the server returns an exception

user_data()

Return user data for all users in FAS

Note: If the user is not authorized to see password hashes, ‘*’ is returned for the hash.

Raises AppError:
 if the query failed on the server
Returns:A dict mapping user IDs to a username, password hash, SSH public key, email address, and status.
user_gencert()
Generate a cert for a user
user_id()
Returns a dict relating user IDs to usernames
verify_password(username, password)

Return whether the username and password pair are valid.

Parameters:
  • username – username to try authenticating
  • password – password for the user
Returns:

True if the username/password are valid. False otherwise.

Bodhi

class fedora.client.BodhiClient(base_url='https://admin.fedoraproject.org/updates/', useragent='Fedora Bodhi Client/0.5.1', *args, **kwargs)
candidates()

Get a list list of update candidates.

This method is a generator that returns a list of koji builds that could potentially be pushed as updates.

comment(update, comment, karma=0)

Add a comment to an update.

Parameters:
  • update – The title of the update comment on.
  • comment – The text of the comment.
  • karma – The karma of this comment (-1, 0, 1)
delete(update)

Delete an update.

Parameters:
  • update – The title of the update to delete
koji_session
Return an authenticated koji session
latest_builds(package)

Get a list of the latest builds for this package.

Parameters:
  • package – package name to find builds for.
Returns:

a dictionary of the release dist tag to the latest build.

masher()
Return the status of bodhi’s masher
parse_file(input_file)

Parse an update template file.

Parameters:
  • input_file – The filename of the update template.

Returns an array of dictionaries of parsed update values which can be directly passed to the save method.

push()
Return a list of requests
push_updates(updates)

Push a list of updates.

Parameters:
  • updates – A list of update titles to push.
query(release=None, status=None, type_=None, bugs=None, request=None, mine=None, package=None, username=None, limit=10)

Query bodhi for a list of updates.

Parameters:
  • release – The release that you wish to query updates for.
  • status – The update status (pending, testing, stable, obsolete)
  • type – The type of this update: security, bugfix, enhancement, and newpackage.
  • bugs – A list of Red Hat Bugzilla ID’s
  • request – An update request to query for testing, stable, unpush, obsolete or None.
  • mine – If True, only query the users updates. Default: False.
  • package – A package name or a name-version-release.
  • limit – The maximum number of updates to display. Default: 10.
request(update, request)

Request an update state change.

Parameters:
  • update – The title of the update
  • request – The request (testing, stable, obsolete, revoke)
save(builds='', type_='', bugs='', notes='', request='testing', close_bugs=True, suggest_reboot=False, inheritance=False, autokarma=True, stable_karma=3, unstable_karma=-3, edited='')

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 – A list of koji builds for this update.
  • type_ – The type of this update: security, bugfix, enhancement, and newpackage.
  • bugs – A list of Red Hat Bugzilla ID’s associated with this update.
  • notes – Details as to why this update exists.
  • request – Request for this update to change state, either to testing, stable, unpush, obsolete or None.
  • close_bugs – Close bugs when update is stable
  • suggest_reboot – Suggest that the user reboot after update.
  • inheritance – Follow koji build inheritance, which may result in this update being pushed out to additional releases.
  • autokarma – 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 – The upper threshold for marking an update as stable.
  • unstable_karma – The lower threshold for unpushing an update.
  • edited – The update title of the existing update that we are editing.
testable()

Get a list of installed testing updates.

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

update_str(update, minimal=False)

Return a string representation of a given update dictionary.

Parameters:
  • update – An update dictionary, acquired by the list method.
  • minimal – Return a minimal one-line representation of the update.

Package Database

class fedora.client.PackageDB(base_url='https://admin.fedoraproject.org/pkgdb/', *args, **kwargs)

Provide an easy to use interface to the PackageDB.

add_edit_package(pkg, owner=None, description=None, branches=None, cc_list=None, comaintainers=None, groups=None)

Add or edit a package to the database.

Parameters:
  • pkg – Name of the package to edit
  • owner – If set, make this person the owner of both branches
  • description – If set, make this the description of both branches
  • branches – List of branches to operate on
  • cc_list – If set, list or tuple of usernames to watch the package.
  • comaintainers – If set, list or tuple of usernames to comaintain the package.
  • groups – If set, list or tuple of group names that can commit to the package.
Raises AppError:
 

If the server returns an error

This method takes information about a package and either edits the package to reflect the changes to information or adds the package to the database.

Note: This method will be going away in favor of methods that do smaller chunks of work:

  1. A method to add a new package
  2. A method to add a new branch
  3. A method to edit an existing package
  4. A method to edit and existing branch
canonical_branch_name(branch)

Change a branch abbreviation into a name and version.

Parameters:
  • branch – branch abbreviation
Return type:

tuple

Returns:

tuple of branch name and branch version.

Example: >>> name, version = canonical_branch_name(‘FC-6’) >>> name Fedora >>> version 6

clone_branch(pkg, branch, master, email_log=True)

Set a branch’s permissions from a pre-existing branch.

Parameters:
  • pkg – Name of the package to branch
  • branch – Branch to clone to. Allowed branch names are listed in COLLECTIONMAP
  • master – Short branch name to clone from. Allowed branch names are listed in COLLECTIONMAP
  • email_log – If False, do not email a copy of the log.
Raises AppError:
 

If the server returns an exceptiom

get_owners(package, collection=None, collection_ver=None)

Retrieve the ownership information for a package.

Parameters:
  • package – Name of the package to retrieve package information about.
  • collection – Limit the returned information to this collection (‘Fedora’, ‘Fedora EPEL’, Fedora OLPC’, etc)
  • collection_ver – If collection is specified, further limit to this version of the collection.
Raises AppError:
 

If the server returns an error

Return type:

DictContainer

Returns:

dict of ownership information for the package

get_package_info(pkg, branch=None)

Get information about the package.

Parameters:
  • pkg – Name of the package
  • branch – If given, restrict information returned to this branch Allowed branches are listed in COLLECTIONMAP
Raises AppError:
 

If the server returns an exceptiom

Returns:

Package ownership information

Return type:

fedora.client.DictContainer

mass_branch(branch)

Branch all unblocked packages for a new release.

Mass branching always works against the devel branch.

Parameters:
  • branch – Branch name to create branches for. Names are listed in COLLECTIONMAP
Raises AppError:
 

If the server returns an exceptiom. The ‘extras’ attribute will contain a list of unbranched packages if some of the packages were branched

Service

Transforming SQLAlchemy Objects into JSON

fedora.tg.json.jsonify_sa_select_results(obj)

Transform selectresults into lists.

The one special thing is that we bind the special json_props into each descendent. This allows us to specify a json_props on the toplevel query result and it will pass to all of its children.

Parameters:
  • obj – sqlalchemy Query object to jsonify
Returns:

list representation of the Query with each element in it given a json_props attributes

fedora.tg.json.jsonify_salist(obj)

Transform SQLAlchemy InstrumentedLists into json.

The one special thing is that we bind the special json_props into each descendent. This allows us to specify a json_props on the toplevel query result and it will pass to all of its children.

Parameters:
  • obj – One of the sqlalchemy list types to jsonify
Returns:

list of jsonified elements

fedora.tg.json.jsonify_saresult(obj)

Transform SQLAlchemy ResultProxy into json.

The one special thing is that we bind the special json_props into each descendent. This allows us to specify a json_props on the toplevel query result and it will pass to all of its children.

Parameters:
  • obj – sqlalchemy ResultProxy to jsonify
Returns:

list of jsonified elements

fedora.tg.json.jsonify_set(obj)

Transform a set into a list.

simplejson doesn’t handle sets natively so transform a set into a list.

Parameters:
  • obj – set to jsonify
Returns:

list representation of the set

class fedora.tg.json.SABase

Base class for SQLAlchemy mapped objects.

This base class makes sure we have a __json__() method on each SQLAlchemy mapped object that knows how to:

  1. Return json for the object.
  2. Selectively add tables pulled in from the table to the data we’re returning.
__json__()

Transform any SA mapped class into json.

This method takes an SA mapped class and turns the “normal” python attributes into json. The properties (from properties in the mapper) are also included if they have an entry in json_props. You make use of this by setting json_props in the controller.

Example controller:

john = model.Person.get_by(name='John')
# Person has a property, addresses, linking it to an Address class.
# Address has a property, phone_nums, linking it to a Phone class.
john.json_props = {'Person': ['addresses'],
      'Address': ['phone_nums']}
return dict(person=john)

json_props is a dict that maps class names to lists of properties you want to output. This allows you to selectively pick properties you are interested in for one class but not another. You are responsible for avoiding loops. ie: don’t do this:

john.json_props = {'Person': ['addresses'], 'Address': ['people']}

TurboGears Helpers

fedora.tg.util.request_format()
Return the output format that was requested.
fedora.tg.util.jsonify_validation_errors()

Return an error for json if validation failed.

This function checks for two things:

  1. We’re expected to return json data.
  2. There were errors in the validation process.

If both of those are true, this function constructs a response that will return the validation error messages as json data.

All controller methods that are error_handlers need to use this:

@expose(template='templates.numberform')
def enter_number(self, number):
    errors = fedora.tg.util.jsonify_validation_errors()
    if errors:
        return errors
    [...]

@expose(allow_json=True)
@error_handler(enter_number)
@validate(form=number_form)
def save(self, number):
    return dict(success=True)
Returns:None if there are no validation errors or json isn’t requested, otherwise returns a dictionary with the error that’s suitable for return from the controller. The error message is set in tg_flash regardless.
fedora.tg.util.json_or_redirect(forward_url)

If json is wanted, return a dict, otherwise redirect.

Parameters:
  • forward_url – If json was not requested, redirect to this URL after.

This is a decorator to use with a method that returns json by default. If json is requested, then it will return the dict from the method. If json is not requested, it will redirect to the given URL. The method that is decorated should be constructed so that it calls turbogears.flash() with a message that will be displayed on the forward_url page.

Use it like this:

import turbogears

@json_or_redirect('http://localhost/calc/')
@expose(allow_json=True)
def divide(self, dividend, divisor):
    try:
        answer = dividend * 1.0 / divisor
    except ZeroDivisionError:
        turbogears.flash('Division by zero not allowed')
        return dict(exc='ZeroDivisionError')
    turbogears.flash('The quotient is %s' % answer)
    return dict(quotient=answer)

In the example, we return either an exception or an answer, using turbogears.flash() to tell people of the result in either case. If json data is requested, the user will get back a json string with the proper information. If html is requested, we will be redirected to ‘http://localhost/calc/‘ where the flashed message will be displayed.