Coverage for /Users/fab/Documents/rdlm-py/rdlmpy/client : 63%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*- # # This file is part of rdlm-py released under the MIT license. # See the LICENSE file for more information.
''' Class which defines a client object '''
default_lifetime=300, default_wait=10): ''' @summary: constructor @param server: rdlm server hostname @param port: rdlm server port @param default_title: default title for locks @param default_lifetime: default lifetime for locks (in seconds) @param default_wait: default wait time for locks (in seconds) @result: client object ''' self._default_title = default_title else: getpass.getuser(), os.getpid(), sys.argv[0], VERSION, socket.gethostname())
title=None): ''' @summary: acquires a lock @param resource_name: name of the resource to lock @param lifetime: lifetime for the lock (in seconds) @param wait: wait time for the lock (in seconds) @param title: title @result: lock url (if the lock is acquired)
If the lock is not acquired, this function can raise : - a RDLMLockWaitExceededException: can't acquire the lock after "wait" seconds - a RDLMLockDeletedException: the request has been deleted by an delete request - a RDLMServerException: unknown error from the RDLM server - a RDLMClientException: unknown error from the RDLM client ''' if lifetime is None else lifetime except: raise RDLMServerException() raise RDLMClientException()
''' @summary: releases a lock @param lock_url: the lock url to release @result: True (if ok), False (else)
The lock url is the return value of lock_acquire() method ''' except: raise RDLMServerException()
''' @summary: gets informations about a lock @param lock_url: the lock url @result: informations dict (or None) ''' except: raise RDLMServerException()
''' @summary: delete all locks on a resource @param resource_name: name of the resource @param username: admin http username @param password: admin http password @result: True if there were some locks on the resource, False else ''' else:
''' @summary: delete all locks on all resources @param username: admin http username @param password: admin http password @result: True if ok, False else ''' else:
''' @summary: get resources list (with locks) @param username: admin http username @param password: admin http password @result: list of resource names ''' if username and password: auth = HTTPBasicAuth(username, password) r = requests.get("%s/resources" % self._base_url, auth=auth) else: r = requests.get("%s/resources" % self._base_url) if r.status_code != 200: raise RDLMServerException("Impossible to get all resources\ (unknown error") try: json_hal = json.loads(r.content) except: raise RDLMServerException("Impossible to get all resources\ (can't unserialize result") if '_embedded' not in json_hal or \ 'resources' not in json_hal['_embedded']: return [] return [x['name'] for x in json_hal['_embedded']['resources']]
''' @summary: get locks list for a given resource @param resource_name: name of the resource @param username: admin http username @param password: admin http password @result: list of lock objects ''' if username and password: auth = HTTPBasicAuth(username, password) r = requests.get("%s/resources/%s" % (self._base_url, resource_name), auth=auth) else: r = requests.get("%s/resources/%s" % (self._base_url, resource_name)) if r.status_code != 200: raise RDLMServerException("Impossible to get all locks\ (unknown error") try: json_hal = json.loads(r.content.decode('utf-8')) except: raise RDLMServerException("Impossible to get all locks\ (can't unserialize result") if '_embedded' not in json_hal or \ 'locks' not in json_hal['_embedded']: return [] out = [] for x in json_hal['_embedded']['locks']: lock_url = "%s%s" % (self._base_url, x['_links']['self']['href']) out.append(RDLMLock.factory(lock_url, json.dumps(x))) return out |