Bases: suds.client.Client
A client accessing an ICAT service.
Client is a subclass of suds.client.Client and inherits most of its behavior. It adds methods for the instantiation of ICAT entities and implementations of the ICAT API methods.
Instance attributes:
Version of the ICAT server this client connects to.
Flag whether the client should logout automatically on exit.
The icat.ids.IDSClient instance used for IDS calls.
The session id as returned from icat.client.Client.login().
The ssl.SSLContext instance that has been used to establish the HTTPS conection to the ICAT and IDS server. This is None for old Python versions that do not have the ssl.SSLContext class.
A dict that maps type names from the ICAT WSDL schema to the corresponding classes in the icat.entity.Entity hierarchy.
The URL to the web service description of the ICAT server.
Class and instance methods:
Cleanup all class instances.
Call icat.client.Client.cleanup() on all registered class instances, e.g. on all clients that have not yet been cleaned up.
Release resources allocated by the client.
Logout from the active ICAT session (if self.autoLogout is True). The client should not be used any more after calling this method.
Add the URL to an ICAT Data Service.
Instantiate a new icat.entity.Entity object.
If obj is a string, take it as the name of an instance type. Create a new instance object of this type and lookup the class for the object in the self.typemap using this type name. If obj is an instance object, look up its class name in the typemap to determine the class. If obj is None, do nothing and return None.
| Parameters: |
|
|---|---|
| Returns: | the new entity object or None. |
| Return type: | |
| Raises TypeError: | |
if obj is neither a valid instance object, nor a valid name of an entity type, nor None. |
|
Return the Entity class corresponding to a BeanName.
Get the corresponding icat.entity.Entity for an object.
If obj is a Suds instance object, create a new object with icat.client.Client.new(). Otherwise do nothing and return obj unchanged.
| Parameters: | obj (suds.sudsobject.Object or any type) – either a Suds instance object or anything. |
|---|---|
| Returns: | the new entity object or obj. |
| Return type: | icat.entity.Entity or any type |
These methods implement the ICAT API calls. Please refer to the ICAT Java Client documentation for details.
Search with an assertion on the result.
Perform a search and verify that the number of items found lies within the bounds of assertmin and assertmax. Raise an error if this assertion fails.
| Parameters: |
|
|---|---|
| Returns: | search result. |
| Return type: | list |
| Raises: |
|
Search the ICAT server.
Call the ICAT icat.client.Client.search() API method, limiting the number of results in each call and repeat the call as often as needed to retrieve all the results.
This can be used as a drop in replacement for the search API method most of the times. It avoids the error if the number of items in the result exceeds the limit imposed by the ICAT server. There are a few subtle differences though: the query must not contain a LIMIT clause (use the skip and count arguments instead) and should contain an ORDER BY clause. The return value is an iterator over the items in the search result rather then a list. The individual search calls are done lazily, e.g. they are not done until needed to yield the next item from the iterator. The result may be defective (omissions, duplicates) if the content in the ICAT server changes between individual search calls in a way that would affect the result.
| Parameters: |
|
|---|---|
| Returns: | a generator that iterates over the items in the search result. |
| Return type: | generator |
Search the object that belongs to a unique key.
This is in a sense the inverse method to icat.entity.Entity.getUniqueKey(), the key must previously have been generated by it. This method searches the Entity object that the key has been generated for from the server.
if objindex is not None, it is used as a cache of previously retrieved objects. It must be a dict that maps keys to Entity objects. The object retrieved by this method call will be added to this index.
This method uses the JPQL inspired query syntax introduced with ICAT 4.3.0. It won’t work with older ICAT servers.
| Parameters: |
|
|---|---|
| Returns: | the object corresponding to the key. |
| Return type: | |
| Raises: |
|
Search the matching object.
Search the object from the ICAT server that matches the given object in the uniqueness constraint.
>>> dataset = client.new("dataset", investigation=inv, name=dsname)
>>> dataset = client.searchMatching(dataset)
>>> dataset.id
172383L
| Parameters: |
|
|---|---|
| Returns: | the corresponding object. |
| Return type: | |
| Raises: |
|
Search a user by name or Create a new user.
If search is True search a user by the given name. If search is False or no user is found, create a new user.
| Parameters: |
|
|---|---|
| Returns: | the user. |
| Return type: |
Create a group and add users to it.
| Parameters: |
|
|---|---|
| Returns: | the group. |
| Return type: |
Create access rules.
| Parameters: |
|
|---|---|
| Returns: | list of the ids of the created rules. |
| Return type: | list of long |
Upload a datafile to IDS.
The content of the file to upload is read from infile, either directly if it is an open file, or a file by that named will be opened for reading.
The datafile object must be initialized but not yet created at the ICAT server. It will be created by the IDS. The ids of the Dataset and the DatafileFormat as well as the attributes description, doi, datafileCreateTime, and datafileModTime will be taken from datafile. If datafileModTime is not set, the method will try to os.fstat() infile and use the last modification time from the file system, if available. If datafileCreateTime is not set, it will be set to datafileModTime.
Note that only the attributes datafileFormat, dataset, description, doi, datafileCreateTime, and datafileModTime of datafile will be taken into account as described above. All other attributes are ignored and the Datafile object created in the ICAT server might end up with different values for those other attribues.
| Parameters: |
|
|---|---|
| Returns: | The Datafile object created by IDS. |
| Return type: |
Retrieve the requested data from IDS.
The data objects to retrieve are given in objs. This can be any combination of single Datafiles, Datasets, or complete Investigations.
| Parameters: |
|
|---|---|
| Returns: | a file-like object as returned by urllib2.OpenerDirector.open(). |
Get the URL to retrieve the requested data from IDS.
The data objects to retrieve are given in objs. This can be any combination of single Datafiles, Datasets, or complete Investigations.
Note that the URL contains the session id of the current ICAT session. It will become invalid if the client logs out.
| Parameters: |
|
|---|---|
| Returns: | the URL for tha data at the IDS. |
| Return type: | str |
Prepare data at IDS to be retrieved in subsequent calls.
The data objects to retrieve are given in objs. This can be any combination of single Datafiles, Datasets, or complete Investigations.
| Parameters: |
|
|---|---|
| Returns: | preparedId, an opaque string which may be used as an argument to icat.client.Client.isDataPrepared() and icat.client.Client.getPreparedData() calls. |
| Return type: | str |
Check if prepared data is ready at IDS.
| Parameters: | preparedId (str) – the id returned by icat.client.Client.prepareData(). |
|---|---|
| Returns: | True if the data is ready, otherwise False. |
| Return type: | bool |
Retrieve prepared data from IDS.
| Parameters: |
|
|---|---|
| Returns: | a file-like object as returned by urllib2.OpenerDirector.open(). |
Get the URL to retrieve prepared data from IDS.
| Parameters: |
|
|---|---|
| Returns: | the URL for tha data at the IDS. |
| Return type: | str |
Delete data from IDS.
The data objects to delete are given in objs. This can be any combination of single Datafiles, Datasets, or complete Investigations.
| Parameters: | objs (dict, list of icat.entity.Entity, or icat.ids.DataSelection) – either a dict having some of the keys investigationIds, datasetIds, and datafileIds with a list of object ids as value respectively, or a list of entity objects, or a data selection. |
|---|