diff --git a/lib/query.py b/lib/query.py index f1eae290b73fe890c9d7c25ba7f21c7ce560e1b6..4c4394e764afc70b47fca1b1a2302cb8c38e268a 100644 --- a/lib/query.py +++ b/lib/query.py @@ -8,13 +8,11 @@ import xml.etree.ElementTree as ET import xmlrpc.client import uuid import copy -import logging -logger = logging.getLogger(__name__) path = expanduser("~/.siplibrc") user = None passw = None -#host = "lta-ingest-test.lofar.eu:19443" +# host = "lta-ingest-test.lofar.eu:19443" host = "lofar-ingest.target.rug.nl:9443" if not exists(path): @@ -24,55 +22,56 @@ if not exists(path): file.write("password=\n") file.write("host=\n") -with open(path,'r') as file: - logger.info("Parsing user credentials from %s" % path) - for line in file: - if line.startswith("user"): - user = line.split('=')[1].strip() - if line.startswith("password"): - passw = line.split('=')[1].strip() - if line.startswith("host"): - host = line.split('=')[1].strip() +with open(path, 'r') as file: + print("Parsing user credentials from", path) + for line in file: + if line.startswith("user"): + user = line.split('=')[1].strip() + if line.startswith("password"): + passw = line.split('=')[1].strip() + if line.startswith("host"): + host = line.split('=')[1].strip() login_data = { - 'j_username' : user, - 'j_password' : passw - } + 'j_username': user, + 'j_password': passw +} -url = 'https://'+user+':'+passw+'@'+host +url = 'https://' + user + ':' + passw + '@' + host client = xmlrpc.client.ServerProxy(url) + # id_cache = {} def _call_idservice(source, userlabel=None): - if userlabel is not None: response = client.GetUniqueIDForLabel(source, userlabel) else: response = client.GetUniqueID(source) return response + # for testing: - # if userlabel in id_cache: - # print "using existing", userlabel - # response = id_cache.get(userlabel) - # else: - # print "creating new", userlabel - # response = {"version": "version", - # "result": "ok", - # "id": uuid.uuid1().int>>64, - # "user_label": userlabel, - # "data_type": "type", - # "identifier_source": source, - # "is_new": True, - # "error": ''} - # if userlabel is not None: - # print "keeping copy", userlabel - # keeper = copy.deepcopy(response) - # keeper["is_new"] = False - # id_cache[userlabel] = keeper - # - # return response +# if userlabel in id_cache: +# print "using existing", userlabel +# response = id_cache.get(userlabel) +# else: +# print "creating new", userlabel +# response = {"version": "version", +# "result": "ok", +# "id": uuid.uuid1().int>>64, +# "user_label": userlabel, +# "data_type": "type", +# "identifier_source": source, +# "is_new": True, +# "error": ''} +# if userlabel is not None: +# print "keeping copy", userlabel +# keeper = copy.deepcopy(response) +# keeper["is_new"] = False +# id_cache[userlabel] = keeper +# +# return response def create_unique_id(source, userlabel=None): @@ -83,9 +82,9 @@ def create_unique_id(source, userlabel=None): """ response = _call_idservice(source, userlabel) if not response.get("result") == "ok": - raise Exception('An identifier for this userlabel could not be created -> '+str(response.get("error"))) + raise Exception('An identifier for this userlabel could not be created -> ' + str(response.get("error"))) if not response.get("is_new"): - raise Exception('An identifier for this userlabel already exists -> '+str(userlabel)) + raise Exception('An identifier for this userlabel already exists -> ' + str(userlabel)) return response.get('id') @@ -97,15 +96,15 @@ def get_unique_id(source, userlabel): """ response = _call_idservice(source, userlabel) if not response.get("result") == "ok": - raise Exception('An identifier for this userlabel could not be retrieved -> '+str(response.get("error"))) + raise Exception('An identifier for this userlabel could not be retrieved -> ' + str(response.get("error"))) if response.get("is_new"): - raise Exception('An identifier for this userlabel does not exist -> '+str(userlabel)) + raise Exception('An identifier for this userlabel does not exist -> ' + str(userlabel)) return response.get('id') +def get_dataproduct_sip(projectname, dataproductid): + return client.GetSip(projectname, dataproductid).get("sip") -def get_dataproduct_sip(projectname,dataproductid): - return client.GetSip(projectname,dataproductid).get("sip") def get_dataproduct_ids(projectname, sasid): - return client.GetDataProductIDS(projectname,sasid).get("ids") + return client.GetDataProductIDS(projectname, sasid).get("ids")