Skip to content

Commit

Permalink
Remove old bfabric properties (#61)
Browse files Browse the repository at this point in the history
Removes usage of the deprecated compatibility properties.
  • Loading branch information
leoschwarz authored Mar 20, 2024
1 parent d55775b commit 47fc1da
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
64 changes: 17 additions & 47 deletions bfabric/bfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.")
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions bfabric/scripts/bfabric_save_importresource_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bfabric/tests/test_bfabric_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 47fc1da

Please sign in to comment.