From 47fc1da8c09a202f9dc59528ae872d7d876f6447 Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Wed, 20 Mar 2024 12:06:48 +0100 Subject: [PATCH] Remove old bfabric properties (#61) Removes usage of the deprecated compatibility properties. --- bfabric/bfabric.py | 64 +++++-------------- .../bfabric_save_importresource_sample.py | 11 ++-- bfabric/tests/test_bfabric_functional.py | 4 +- 3 files changed, 24 insertions(+), 55 deletions(-) diff --git a/bfabric/bfabric.py b/bfabric/bfabric.py index df085562..d8bc14c6 100755 --- a/bfabric/bfabric.py +++ b/bfabric/bfabric.py @@ -126,29 +126,6 @@ def __init__(self, login=None, password=None, webbase=None, externaljobid=None, msg = f"\033[93m--- webbase {self.config.base_url}; login; {self.config.login} ---\033[0m\n" sys.stderr.write(msg) - @property - def bflogin(self): - # TODO remove after refactoring is complete - return self.config.login - - @property - def bfpassword(self): - # TODO remove after refactoring is complete - return self.config.password - - @property - def webbase(self): - # TODO remove after refactoring is complete - return self.config.base_url - - @property - def application(self): - # TODO remove after refactoring is complete - return self.config.application_ids - - def get_para(self): - return {'bflogin': self.bflogin, 'webbase': self.webbase} - def read_object(self, endpoint, obj, login=None, password=None, page=1, plain=False, idonly=False): """ A generic method which can connect to any endpoint, e.g., workunit, project, order, @@ -157,10 +134,10 @@ def read_object(self, endpoint, obj, login=None, password=None, page=1, plain=Fa for the "query". """ if login is None: - login = self.bflogin + login = self.config.login if password is None: - password = self.bfpassword + password = self.config.password if len(login) >= 32: raise ValueError("Sorry, login >= 32 characters.") @@ -174,7 +151,7 @@ def read_object(self, endpoint, obj, login=None, password=None, page=1, plain=Fa try: if not endpoint in self.cl: - self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None) + self.cl[endpoint] = Client("".join((self.config.base_url, '/', endpoint, "?wsdl")), cache=None) except Exception as e: print (e) raise @@ -203,10 +180,10 @@ def readid_object(self, endpoint, obj, login=None, password=None, page=1, plain= obj is a python dictionary which contains only the id of the endpoint for the "query". """ if login is None: - login = self.bflogin + login = self.config.login if password is None: - password = self.bfpassword + password = self.config.password if len(login) >= 32: raise ValueError("Sorry, login >= 32 characters.") @@ -219,7 +196,7 @@ def readid_object(self, endpoint, obj, login=None, password=None, page=1, plain= try: if not endpoint in self.cl: - self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None) + self.cl[endpoint] = Client("".join((self.config.base_url, '/', endpoint, "?wsdl")), cache=None) except Exception as e: print (e) raise @@ -245,12 +222,12 @@ def save_object(self, endpoint, obj, debug=None): same as read_object above but uses the save method. """ self.query_counter = self.query_counter + 1 - QUERY = dict(login=self.bflogin, password=self.bfpassword) + QUERY = dict(login=self.config.login, password=self.config.password) QUERY[endpoint] = obj try: if not endpoint in self.cl: - self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None) + self.cl[endpoint] = Client("".join((self.config.base_url, '/', endpoint, "?wsdl")), cache=None) except: raise @@ -269,12 +246,12 @@ def checkandinsert_object(self, endpoint, obj, debug=None): """ self.query_counter = self.query_counter + 1 - QUERY = dict(login=self.bflogin, password=self.bfpassword) + QUERY = dict(login=self.config.login, password=self.config.password) QUERY[endpoint] = obj try: if not endpoint in self.cl: - self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None) + self.cl[endpoint] = Client("".join((self.config.base_url, '/', endpoint, "?wsdl")), cache=None) except: raise @@ -294,11 +271,11 @@ def delete_object(self, endpoint, id=None, debug=None): """ self.query_counter = self.query_counter + 1 - QUERY = dict(login=self.bflogin, password=self.bfpassword, id=id) + QUERY = dict(login=self.config.login, password=self.config.password, id=id) try: if not endpoint in self.cl: - self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None) + self.cl[endpoint] = Client("".join((self.config.base_url, '/', endpoint, "?wsdl")), cache=None) except: raise @@ -357,13 +334,6 @@ def print_yaml(queryres=None): res = yaml.dump(res_json, default_flow_style=False, encoding=None, default_style=None) print(res) - def set_bfabric_credentials(self, login, password): - self.bflogin = login - self.bfpassword = password - - def set_bfabric_webbase(self, url): - self.webbase = url - def get_sampleid(self, resourceid=None): """ determines the sample_id of a given resource_id. @@ -544,8 +514,8 @@ def __init__(self, login=None, password=None, externaljobid=None, self.user = user self.scheduler = scheduler - print((self.B.bflogin)) - print((self.B.externaljobid)) + print(self.B.config.login) + print(self.B.externaljobid) self.workunitid = self.B.get_workunitid_of_externaljob() @@ -960,12 +930,12 @@ def write_yaml(self, data_serializer=lambda x: yaml.dump(x, default_flow_style= sample_id = self.get_sampleid(int(resource_iterator._id)) _resource_sample = {'resource_id': int(resource_iterator._id), - 'resource_url': "{0}/userlab/show-resource.html?id={1}".format(self.webbase,resource_iterator._id)} + 'resource_url': "{0}/userlab/show-resource.html?id={1}".format(self.config.base_url,resource_iterator._id)} if not sample_id is None: _resource_sample['sample_id'] = int(sample_id) - _resource_sample['sample_url'] = "{0}/userlab/show-sample.html?id={1}".format(self.webbase, sample_id) + _resource_sample['sample_url'] = "{0}/userlab/show-sample.html?id={1}".format(self.config.base_url, sample_id) resource_ids[_application_name].append(_resource_sample) except: @@ -1060,7 +1030,7 @@ def write_yaml(self, data_serializer=lambda x: yaml.dump(x, default_flow_style= }, 'workunit_id': int(workunit._id), 'workunit_createdby': str(workunit.createdby), - 'workunit_url': "{0}/userlab/show-workunit.html?workunitId={1}".format(self.webbase, workunit._id), + 'workunit_url': "{0}/userlab/show-workunit.html?workunitId={1}".format(self.config.base_url, workunit._id), 'external_job_id': int(yaml_workunit_externaljob._id), 'order_id': order_id, 'project_id': project_id, diff --git a/bfabric/scripts/bfabric_save_importresource_sample.py b/bfabric/scripts/bfabric_save_importresource_sample.py index ef386ebb..12611806 100755 --- a/bfabric/scripts/bfabric_save_importresource_sample.py +++ b/bfabric/scripts/bfabric_save_importresource_sample.py @@ -38,12 +38,11 @@ bfabric_storageid = 2 bfapp = Bfabric() -# TODO(cp): should go into a config file, e.g., bfabricrc -# the hash maps the 'real world' to the BFabric application._id -if bfapp.application is None: - raise RuntimeError("No bfapp.application variable configured. check '~/.bfabricrc.py' file!") -print (bfapp.application) -bfabric_application_ids = bfapp.application +# maps the 'real world' to the BFabric application._id +if bfapp.config.application_ids is None: + raise RuntimeError("No bfapp.config.application_ids variable configured. check '~/.bfabricrc.py' file!") +print(bfapp.config.application_ids) +bfabric_application_ids = bfapp.config.application_ids def save_importresource(line): """ reads, splits and submit the input line to the bfabric system diff --git a/bfabric/tests/test_bfabric_functional.py b/bfabric/tests/test_bfabric_functional.py index 7aef9041..38d0fc43 100755 --- a/bfabric/tests/test_bfabric_functional.py +++ b/bfabric/tests/test_bfabric_functional.py @@ -38,10 +38,10 @@ def test_wrappercreator_submitter(self): logging.info("Running functional test on bfabricPy") msg = "This test case requires user 'pfeeder'." - self.assertEqual(B.bflogin, 'pfeeder', msg) + self.assertEqual(B.config.login, 'pfeeder', msg) msg = "This test case requires a bfabric test system!" - self.assertIn("bfabric-test", B.webbase, msg) + self.assertIn("bfabric-test", B.config.base_url, msg) # TODO # create input resource