Module author: Luke Macken <lmacken@redhat.com>
Module author: Toshio Kuratomi <tkuratom@redhat.com>
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.
Unable to talk to the server properly.
This includes network errors and 500 response codes.
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.
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
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.
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: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
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 |
A client for interacting with web services.
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: |
|
---|---|
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.
The session_id.
The session id is saved in a file in case it is needed in consecutive runs of BaseClient.
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.
Return the config entry for the key values.
Parameters: |
|
---|---|
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. |
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: |
|
---|---|
Raises AppError: | |
if the server returns an exception |
|
Returns: | A dict mapping attribute to value. |
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. |
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’.
Return a list of persons for the given groupname.
Parameters: |
|
---|---|
Returns: | A list of person objects from the group. If the group contains no entries, then an empty list is returned. |
Deprecated Use people_by() instead.
Returns a dict relating user IDs to human_name, email, username, and bugzilla email
Return a dict of people
Parameters: |
|
---|---|
Returns: | a dict relating the key value to the fields. |
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: |
|
---|---|
Raises AppError: | |
if the server returns an exception |
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. |
Return whether the username and password pair are valid.
Parameters: |
|
---|---|
Returns: | True if the username/password are valid. False otherwise. |
Provide an easy to use interface to the PackageDB.
Add or edit a package to the database.
Parameters: |
|
---|---|
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:
Change a branch abbreviation into a name and version.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | tuple of branch name and branch version. |
Example: >>> name, version = canonical_branch_name(‘FC-6’) >>> name Fedora >>> version 6
Set a branch’s permissions from a pre-existing branch.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an exceptiom |
Retrieve the ownership information for a package.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an error |
|
Return type: | DictContainer |
Returns: | dict of ownership information for the package |
Get information about the package.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an exceptiom |
|
Returns: | Package ownership information |
Return type: | fedora.client.DictContainer |
Branch all unblocked packages for a new release.
Mass branching always works against the devel branch.
Parameters: |
|
---|---|
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 |
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.
Add a comment to an update.
Parameters: |
|
---|
Delete an update.
Parameters: |
|
---|
Get a list of the latest builds for this package.
Parameters: |
|
---|---|
Returns: | a dictionary of the release dist tag to the latest build. |
Parse an update template file.
Parameters: |
|
---|
Returns an array of dictionaries of parsed update values which can be directly passed to the save method.
Push a list of updates.
Parameters: |
|
---|
Query bodhi for a list of updates.
Parameters: |
|
---|
Request an update state change.
Parameters: |
|
---|
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: |
|
---|
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.
Return a string representation of a given update dictionary.
Parameters: |
|
---|
A client for interacting with web services.
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: |
|
---|---|
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.
The session_id.
The session id is saved in a file in case it is needed in consecutive runs of BaseClient.
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.
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: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
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 |
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.
Return the config entry for the key values.
Parameters: |
|
---|---|
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. |
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: |
|
---|---|
Raises AppError: | |
if the server returns an exception |
|
Returns: | A dict mapping attribute to value. |
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. |
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’.
Return a list of persons for the given groupname.
Parameters: |
|
---|---|
Returns: | A list of person objects from the group. If the group contains no entries, then an empty list is returned. |
Deprecated Use people_by() instead.
Returns a dict relating user IDs to human_name, email, username, and bugzilla email
Return a dict of people
Parameters: |
|
---|---|
Returns: | a dict relating the key value to the fields. |
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: |
|
---|---|
Raises AppError: | |
if the server returns an exception |
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. |
Return whether the username and password pair are valid.
Parameters: |
|
---|---|
Returns: | True if the username/password are valid. False otherwise. |
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.
Add a comment to an update.
Parameters: |
|
---|
Delete an update.
Parameters: |
|
---|
Get a list of the latest builds for this package.
Parameters: |
|
---|---|
Returns: | a dictionary of the release dist tag to the latest build. |
Parse an update template file.
Parameters: |
|
---|
Returns an array of dictionaries of parsed update values which can be directly passed to the save method.
Push a list of updates.
Parameters: |
|
---|
Query bodhi for a list of updates.
Parameters: |
|
---|
Request an update state change.
Parameters: |
|
---|
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: |
|
---|
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.
Return a string representation of a given update dictionary.
Parameters: |
|
---|
Provide an easy to use interface to the PackageDB.
Add or edit a package to the database.
Parameters: |
|
---|---|
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:
Change a branch abbreviation into a name and version.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | tuple of branch name and branch version. |
Example: >>> name, version = canonical_branch_name(‘FC-6’) >>> name Fedora >>> version 6
Set a branch’s permissions from a pre-existing branch.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an exceptiom |
Retrieve the ownership information for a package.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an error |
|
Return type: | DictContainer |
Returns: | dict of ownership information for the package |
Get information about the package.
Parameters: |
|
---|---|
Raises AppError: | |
If the server returns an exceptiom |
|
Returns: | Package ownership information |
Return type: | fedora.client.DictContainer |
Branch all unblocked packages for a new release.
Mass branching always works against the devel branch.
Parameters: |
|
---|---|
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 |
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: |
|
---|---|
Returns: | list representation of the Query with each element in it given a json_props attributes |
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: |
|
---|---|
Returns: | list of jsonified elements |
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: |
|
---|---|
Returns: | list of jsonified elements |
Transform a set into a list.
simplejson doesn’t handle sets natively so transform a set into a list.
Parameters: |
|
---|---|
Returns: | list representation of the set |
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:
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']}
Return an error for json if validation failed.
This function checks for two things:
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. |
---|
If json is wanted, return a dict, otherwise redirect.
Parameters: |
|
---|
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.