Package schrodinger :: Package test :: Package scival :: Module utils
[hide private]
[frames] | no frames]

Module utils

'URI' vs 'URL'

You see these terms used somewhat interchangeably on the web, but there is a distinction. URIs are a superset of URLs and also include URNs (Uniform Resource Name). URLs must specify the location of a resource and the manner in which it can be accessed. So, http://sahba:8000/api/v1/ssp/test/1 is a URL, but a bare path like /api/v1/ssp/test/1 is not. (Technically, it's not a URI, either, but we can treat it like a unique name in our local namespace.)

The upshot: if a variable name has 'url', expect that it already has an http://, if a variable name has 'uri' it may need an http:// and a server name.

Classes [hide private]
  Item
  FileItem
Provide functionality to a de-serialized File instance.
  URLItem
An Item with a base_url property.
  JsonItem
Provide general functionality for a de-serialized object.
Functions [hide private]
 
get_schrodinger()
Gets SCHRODINGER from the environment.
 
get_content_id(fileobj)
Get the content ID for an open file object.
 
get_standard_url(uri)
Given a URL or just a path, return a canonical URL that can be used to grab a resource from the server.
 
item_get_or_add(uri, **kwargs)
Return the single item matching the keyword arguments, or add the item to the database.
 
item_query(uri, **kwargs)
Get one or more items matching the keyword arguments as a list of IDs.
 
item_add(uri, **kwargs)
Add an item with properties set from the keyword arguments.
 
item_get(uri, **kwargs)
Return the deserialized item from the provided URL.
 
item_delete(uri)
Return the deserialized item from the provided URL.
 
save_files(item, compress=None, file_dir='.', overwrite=True, create_dir=False)
Iterate over the values in the provided item (which must have a values method) and write all files to disk.
 
format_HTTPError(err)
Print the exception; this should contain information about the HTTP Error and message.
 
run_client(main, last_stage, **kwargs)
Run the provided 'main' function, nicely display any errors that result.
Variables [hide private]
  logger = log.get_logger("scivalclient.utils")
  __package__ = 'schrodinger.test.scival'
Function Details [hide private]

get_schrodinger()

 

Gets SCHRODINGER from the environment. Also checks the path to assure it exists and is a directory.

Returns:
Path to the SCHRODINGER env variable
Raises:
  • RunTimeError - If the env does not have a valid SCHRODINGER set.

get_content_id(fileobj)

 

Get the content ID for an open file object. The object must have seek, tell, and read methods.

Parameters:
  • fileobj (An open python file object.)

item_get_or_add(uri, **kwargs)

 

Return the single item matching the keyword arguments, or add the item to the database.

The URI specified must be able to accept a POST with form-encoded values and redirect to a URL that returns the representation of the added item.

Parameters:
  • uri - Can be a full URL or just a pathname, in which case it will be joined with the 'web_url' attribute of the package to form a URL.
Returns:
A list of deserialized matching items.
Raises:
  • RuntimeError - If more than one item matches.

item_query(uri, **kwargs)

 

Get one or more items matching the keyword arguments as a list of IDs.

File arguments should be passed in as open python file objects. If the value of one of the keys is a list, it will be split into multiple key=value pairs.

Parameters:
  • uri - Can be a full URL or just a pathname, in which case it will be joined with the 'web_url' attribute of the package to form a URL.
Returns:
A list of deserialized matching items.

item_add(uri, **kwargs)

 

Add an item with properties set from the keyword arguments.

The URI specified must be able to accept a POST with form-encoded values and redirect to a URL that returns the representation of the added item.

Parameters:
  • uri - Can be a full URL or just a pathname, in which case it will be joined with the 'web_url' attribute of the package to form a URL.
Returns:
The deserialized representation of the newly created item.

item_get(uri, **kwargs)

 

Return the deserialized item from the provided URL. If there is an error, a urllib2.HTTPError is raised.

Parameters:
  • uri - Can be a full URL or just a pathname, in which case it will be joined with the 'web_url' attribute of the package to form a URL.
  • kwargs - Additional keyword arguments are passed on to the urllib2.Request constructor.

item_delete(uri)

 

Return the deserialized item from the provided URL. If there is an error, a urllib2.HTTPError is raised.

Parameters:
  • uri - Can be a full URL or just a pathname, in which case it will be joined with the 'web_url' attribute of the package to form a URL.

format_HTTPError(err)

 

Print the exception; this should contain information about the HTTP Error and message. Make the content of the response available

run_client(main, last_stage, **kwargs)

 

Run the provided 'main' function, nicely display any errors that result. Exit with the error code returned by the main function, or 1 in case of an HTTPError.