midas_handler

class midas_handler.MidasHandler(MIDAS_BASE_URL='http://midas3.kitware.com/midas', MIDAS_COMMUNITY='geojs')

Bases: object

Contains several utility function for interacting with MIDAS by wrapping api methods and caching the results.

community()

Get the id of the GeoJS community.

>>> midas.community()
{
    u'admingroup_id': u'121',
    u'can_join': u'1',
    u'community_id': u'40',
    u'creation': u'2014-06-02 11:38:38',
    u'description': u'',
    u'folder_id': u'11361',
    u'membergroup_id': u'123',
    u'moderatorgroup_id': u'122',
    u'name': u'GeoJS',
    u'privacy': u'0',
    u'uuid': u'538c9a7ead4a21c3b3e4e52724b3e6949487279edfad3',
    u'view': u'68'
}
Returns:MIDAS response object.
Return type:dict
getFolder(name, root=None)

Get a folder named name under root. If no root is given, use the community root.

>>> midas.getFolder('Testing')
u'11364'
>>> midas.getFolder('data', '11364')
u'11373'
Parameters:
  • name (string) – The folder name to find.
  • root (string) – The id of the root folder.
Returns:

The id of the folder.

Return type:

string

Raises:

Exception – If the folder is not found.

getImages(path, revision)

Download images in an item at the given path and revision.

>>> .getImages(('Testing', 'test', 'selenium', 'osmLayer', 'firefox', 'osmDraw.png'), 2)
[<PIL.PngImagePlugin.PngImageFile image mode=RGBA size=640x390 at 0x1019E9200>]
Parameters:
  • path (tuple) – The relative path from the community root.
  • revision (int) – The item revision to download.
Returns:

List of Image.

Raises:

Exception – If the path or revision is not found.

getItem(path, root=None)

Get an item at the given path. If no root is specified, use the community root.

>>> midas.getItem(('Testing', 'data', 'cities.csv'))
{
    u'date_creation': u'2014-06-02 15:26:12',
    ...
    u'view': u'2'
}
Parameters:
  • path (tuple) – The relative path from root.
  • root (string) – The id of the root folder.
Returns:

MIDAS response object

Return type:

dict

Raises:

Exception – If the item is not found.

getOrCreateItem(path)

Create an empty item at the given path if none exists otherwise return the item. This method will create folders as necessary while traversing the path.

Parameters:path (tuple) – The relative path from the community root.
Returns:MIDAS response object
Return type:dict
login(email=None, password=None, apiKey=None)

Log into midas and return a token. If email or password are not provided, they must be entered in stdin. The token is cached internally, so the user will only be prompted once after a successful login. Alternatively, an apiKey can be provided as login credentials.

Parameters:
  • email (string) – The user’s email address.
  • password (string) – The user’s password.
  • apiKey (string) – The user’s api key.
Return type:

string

Returns:

The login token.

uploadFile(fileData, path, revision=None)

Uploads a file to the midas server to the given path. If revision is not specified, it will create a new revision. Otherwise, append the file to the given revision number.

Parameters:
  • fileData (string) – The raw file contents to upload.
  • path (tuple) – The relative path to the item.
  • revision (int) – The revision number to append the file to.
Raises:

Exception – If the upload fails for any reason.

Returns:

MIDAS response object

Return type:

dict