Skip to content

Commit

Permalink
WS API HOME QL and new+legacy support for KBase zips
Browse files Browse the repository at this point in the history
  • Loading branch information
Fxe committed Aug 5, 2024
1 parent ae4c582 commit fcf6423
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
18 changes: 12 additions & 6 deletions cobrakbase/Workspace/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ def _get_token(user_id, password, auth_svc):
return tok["token"]


def _read_inifile(
file=_os.environ.get( # @ReservedAssignment
"KB_DEPLOYMENT_CONFIG", _os.environ["HOME"] + "/.kbase_config"
)
):
def _read_inifile(file=None):
"""
Filipe: hacked this portion to not crash on machines without HOME env var
@param file:
@return:
"""
# Another bandaid to read in the ~/.kbase_config file if one is present
authdata = None
if _os.path.exists(file):
if file is None:
# @ReservedAssignment
if "HOME" in _os.environ:
file = _os.environ.get("KB_DEPLOYMENT_CONFIG", _os.environ["HOME"] + "/.kbase_config")

if file is not None and _os.path.exists(file):
try:
config = _ConfigParser()
config.read(file)
Expand Down
39 changes: 27 additions & 12 deletions cobrakbase/io/read_kbase_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,30 @@ def _read_kbase_zip(path):

def load_kbase_zip_object(filename):
item_info, item_data = _read_kbase_zip(filename)
data = {
'data': [
{
'info': item_info['metadata'][0],
'provenance': [item_info['provenance'][0]['provenance'][0]],
'data': item_data
}
]
}

factory = KBaseObjectFactory()
return factory.create(data, None)
if item_info is None:
raise ValueError('invalid kbase zip file. unable to detect object workspace info')
if item_data is None:
raise ValueError('invalid kbase zip file. unable to detect object data')
legacy = 'info' not in item_info
if legacy:
data = {
'data': [
{
'info': item_info['metadata'][0],
'provenance': [item_info['provenance'][0]['provenance'][0]],
'data': item_data
}
]
}
KBaseObjectFactory().create(data, None)
else:
data = {
'data': [
{
'info': item_info['info'],
'provenance': [],
'data': item_data
}
]
}
return KBaseObjectFactory().create(data, None)
2 changes: 1 addition & 1 deletion cobrakbase/kbase_catalog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cobrakbase.kbase_object_info import KBaseObjectInfo

PROD_WS_MEDIA = 'KBaseMedia'
PROD_WS_GENOMES = '?'
PROD_WS_GENOMES = 'ReferenceDataManager'
PROD_WS_TEMPLATES = 'NewKBaseModelTemplates'


Expand Down
25 changes: 7 additions & 18 deletions cobrakbase/kbaseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ def save_object(self, object_id, ws, object_type, data, meta=None):
params["workspace"] = ws
return KBaseObjectInfo(self.ws_client.save_objects(params)[0])

def save_model(self, object_id, ws, data):
return self.save_object(object_id, ws, "KBaseFBA.FBAModel", data)

def list_objects(self, ws, object_type=None, include_metadata=False):
"""
List objects of a workspace (i.e., narrative) with either numerical id (e.g., 12345)
Expand All @@ -308,28 +305,20 @@ def list_objects(self, ws, object_type=None, include_metadata=False):
params["includeMetadata"] = 1
return self.ws_client.list_objects(params)

def list_workspace(self, ws, object_type=None, include_metadata=False):
return [KBaseObjectInfo(i) for i in self.list_objects(ws, object_type, include_metadata)]

def get_object_info(self, id_or_ref, workspace=None):
ref_data = self.ws_client.get_object_info3(
{"objects": [self.process_workspace_identifiers(id_or_ref, workspace)],"includeMetadata":1}
{"objects": [self.process_workspace_identifiers(id_or_ref, workspace)], "includeMetadata": 1}
)
return KBaseObjectInfo(ref_data["infos"][0])

# TODO: this now seems obfuscated by get_object_info - can we delete this?
def get_object_info_from_ref(self, ref):
"""
@deprecated get_object_info
"""
return self.get_object_info(ref)

def copy(self, from_id, from_ws, to_id, to_ws):
def copy_object(wclient, from_id, from_ws, to_id, to_ws):
params = {
"from": {"name": from_id, "workspace": from_ws},
"to": {"name": to_id, "workspace": to_ws},
}
return wclient.copy_object(params)
_from = self.process_workspace_identifiers(from_id, from_ws)
_to = self.process_workspace_identifiers(to_id, to_ws)

pass
return KBaseObjectInfo(self.ws_client.copy_object({"from": _from, "to": _to}))

def get_workspace_info(self, ws_id_or_name):
if type(ws_id_or_name) == str:
Expand Down

0 comments on commit fcf6423

Please sign in to comment.