def listParameterValues(samweb, param): """ list the values for the given parameter arguments: param: parameter name """ result = samweb.getURL('/values/parameters/%s?format=json' % escape_url_path(param)) return convert_from_unicode(result.json())
def getMultipleMetadata(samweb, filenameorids, locations=False, asJSON=False): """ Return a list of metadata dictionaries (This method does not return an error if a file does not exist; instead it returns no result for that file) arguments: list of file names or ids locations: if True include location information asJSON: return the undecoded JSON string instead of python objects """ file_names = [] file_ids = [] for filenameorid in filenameorids: try: file_ids.append(long(filenameorid)) except ValueError: file_names.append(filenameorid) params = {} if file_names: params["file_name"] = file_names if file_ids: params["file_id"] = file_ids if locations: params["locations"] = 1 response = samweb.getURL("/files/metadata", params=params) if asJSON: return response.text.rstrip() else: return convert_from_unicode(response.json())
def descDefinitionDict(samweb, defname): """ Describe a dataset definition arguments: definition name """ result = samweb.getURL(_descDefinitionURL(defname)) return convert_from_unicode(result.json())
def locateFile(samweb, filenameorid): """ return locations for this file arguments: name or id of file """ url = _make_file_path(filenameorid) + '/locations' result = samweb.getURL(url) return convert_from_unicode(result.json())
def getFileLineage(samweb, lineagetype, filenameorid): """ Return lineage information for a file arguments: lineagetype (ie "parents", "children") name or id of file """ result = samweb.getURL(_make_file_path(filenameorid) + '/lineage/' + escape_url_component(lineagetype)) return convert_from_unicode(result.json())
def listValues(samweb, vtype): """ list values from database. This method tries to be generic, so vtype is passed directly to the web server arguments: vtype: string with values to return (ie data_tiers, groups) """ try: return convert_from_unicode(samweb.getURL('/values/%s' % escape_url_path(vtype)).json()) except HTTPNotFound, ex: raise Error("Unknown value type '%s'" % vtype)
def listFilesSummary(samweb, dimensions=None, defname=None): """ return summary of files matching either a dataset definition or a dimensions string arguments: dimensions: string (default None) defname: string definition name (default None)""" if defname is not None: result = samweb.getURL('/definitions/name/%s/files/summary' % escape_url_component(defname)) else: result = samweb._callDimensions('/files/summary', dimensions) return convert_from_unicode(result.json())
def getMetadata(samweb, filenameorid, locations=False): """ Return metadata as a dictionary arguments: name or id of file locations: if True, also return file locations """ params = {} if locations: params['locations'] = True response = samweb.getURL(_make_file_path(filenameorid) + '/metadata', params=params) return convert_from_unicode(response.json())
def getFileLineage(samweb, lineagetype, filenameorid): """ Return lineage information for a file arguments: lineagetype (ie "parents", "children") name or id of file """ result = samweb.getURL( _make_file_path(filenameorid) + '/lineage/' + escape_url_component(lineagetype)) return convert_from_unicode(result.json())
def listValues(samweb, vtype): """ list values from database. This method tries to be generic, so vtype is passed directly to the web server arguments: vtype: string with values to return (ie data_tiers, groups) """ try: return convert_from_unicode( samweb.getURL('/values/%s' % escape_url_path(vtype)).json()) except HTTPNotFound, ex: raise Error("Unknown value type '%s'" % vtype)
def getFileAccessUrls(samweb, filenameorid, schema, locationfilter=None): """ return urls by which this file may be accessed arguments: name or id of file schema locationfilter (default None) """ params = { "schema": schema } if locationfilter: params["location"] = locationfilter response = samweb.getURL(_make_file_path(filenameorid) + '/locations/url', params=params) return convert_from_unicode(response.json())
def getFileAccessUrls(samweb, filenameorid, schema, locationfilter=None): """ return urls by which this file may be accessed arguments: name or id of file schema locationfilter (default None) """ params = {"schema": schema} if locationfilter: params["location"] = locationfilter response = samweb.getURL(_make_file_path(filenameorid) + '/locations/url', params=params) return convert_from_unicode(response.json())
def projectRecoveryDimension(samweb, projectnameorurl, useFileStatus=None, useProcessStatus=None): """Get the dimensions to create a recovery dataset arguments: projectnameorurl : name or url of the project useFileStatus : use the status of the last file seen by a process (default unset) useProcessStatus : use the status of the process (default unset) """ if not "://" in projectnameorurl: projectnameorurl = "/projects/name/%s" % escape_url_path(projectnameorurl) params = {"format": "plain"} if useFileStatus is not None: params["useFiles"] = useFileStatus if useProcessStatus is not None: params["useProcess"] = useProcessStatus return convert_from_unicode(samweb.getURL(projectnameorurl + "/recovery_dimensions", params=params).text.rstrip())
def locateFiles(samweb, filenameorids): """ return the locations of multiple files The return value is a dictionary of { file_name_or_id : location } pairs """ file_names = [] file_ids = [] for filenameorid in filenameorids: try: file_ids.append(long(filenameorid)) except ValueError: file_names.append(filenameorid) params = {} if file_names: params["file_name"] = file_names if file_ids: params["file_id"] = file_ids response = samweb.getURL("/files/locations", params=params) return convert_from_unicode(response.json())
def projectRecoveryDimension(samweb, projectnameorurl, useFileStatus=None, useProcessStatus=None): """Get the dimensions to create a recovery dataset arguments: projectnameorurl : name or url of the project useFileStatus : use the status of the last file seen by a process (default unset) useProcessStatus : use the status of the process (default unset) """ if not '://' in projectnameorurl: projectnameorurl = "/projects/name/%s" % escape_url_path( projectnameorurl) params = {"format": "plain"} if useFileStatus is not None: params['useFiles'] = useFileStatus if useProcessStatus is not None: params['useProcess'] = useProcessStatus return convert_from_unicode( samweb.getURL(projectnameorurl + "/recovery_dimensions", params=params).text.rstrip())
def listParameters(samweb): """ list defined parameters """ return convert_from_unicode(samweb.getURL('/values/parameters').json())
def projectSummary(samweb, projecturl): if not "://" in projecturl: projecturl = "/projects/name/%s" % escape_url_path(projecturl) return convert_from_unicode(samweb.getURL(projecturl + "/summary").json())
def listDataDisks(samweb): """ list defined data disks """ return convert_from_unicode(samweb.getURL('/values/data_disks').json())
def projectSummary(samweb, projecturl): if not '://' in projecturl: projecturl = '/projects/name/%s' % escape_url_path(projecturl) return convert_from_unicode(samweb.getURL(projecturl + "/summary").json())
def listApplications(samweb, **queryCriteria): result = samweb.getURL('/values/applications', queryCriteria) return convert_from_unicode(result.json())
def getAvailableDimensions(samweb): """ List the available dimensions """ result = samweb.getURL('/files/list/dimensions?format=json&descriptions=1') return convert_from_unicode(result.json())
def getAvailableValues(samweb): """ get the available names that can be used with listValues, addValues """ return convert_from_unicode(samweb.getURL('/values?list=generic').json())
def describeUser(samweb, username): result = samweb._describeUser(username) return convert_from_unicode(result.json())
def listUsers(samweb): result = samweb.getURL('/users') return convert_from_unicode(result.json())