diff --git a/cobrakbase/Workspace/baseclient.py b/cobrakbase/Workspace/baseclient.py index a9a4ee5..8ca1a4d 100644 --- a/cobrakbase/Workspace/baseclient.py +++ b/cobrakbase/Workspace/baseclient.py @@ -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) diff --git a/cobrakbase/io/read_kbase_zip.py b/cobrakbase/io/read_kbase_zip.py index cb10655..241a4c0 100644 --- a/cobrakbase/io/read_kbase_zip.py +++ b/cobrakbase/io/read_kbase_zip.py @@ -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) diff --git a/cobrakbase/kbase_catalog.py b/cobrakbase/kbase_catalog.py index d13e90d..85e57d3 100644 --- a/cobrakbase/kbase_catalog.py +++ b/cobrakbase/kbase_catalog.py @@ -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' diff --git a/cobrakbase/kbaseapi.py b/cobrakbase/kbaseapi.py index e8027cc..830dc08 100755 --- a/cobrakbase/kbaseapi.py +++ b/cobrakbase/kbaseapi.py @@ -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) @@ -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: