diff --git a/owilix/cmd/base.py b/owilix/cmd/base.py index f0987ce..d1dd0d1 100644 --- a/owilix/cmd/base.py +++ b/owilix/cmd/base.py @@ -473,13 +473,12 @@ class BaseCommand(metaclass=SubCommandMeta): for value in data: table.add_row(Text("".join([""]*indent) + str(value))) - # Print the table - self.console.print(table) + # Print the table self.console.print(table) def dataset_stats(self, dataset): """calculates the dataset statistics counting files and leaf directory as group""" statistics = defaultdict(dict) - obj_count = dataset.metadata["objectCount"] + obj_count = dataset.metadata.get("objectCount",0) file_details = dataset.repository.files_details(dataset) for f in file_details: _parts = f.get("path", "").split(dataset.repository.pathsep) @@ -488,7 +487,7 @@ class BaseCommand(metaclass=SubCommandMeta): statistics[_parts[-2]]["fileCount"]=statistics[_parts[-2]].get("fileCount",0)+1 total_size = sum([v["fileSize"] for v in statistics.values()]) for k,v in statistics.items(): - statistics[k]["objectCount"] = obj_count/total_size*statistics[k]["fileSize"] + statistics[k]["objectCount"] = obj_count/total_size*statistics[k]["fileSize"] if total_size>0 else 0 return {"statistics": statistics}|dataset.metadata.as_json_dict()|{"datacenter":dataset.dataCenter,"access":dataset.access} diff --git a/owilix/core/repository.py b/owilix/core/repository.py index 6bb8f3b..1b57e40 100644 --- a/owilix/core/repository.py +++ b/owilix/core/repository.py @@ -703,11 +703,18 @@ class AbstractRepository: """ return self._repo_name + def _add_details_to_status(self, _d): + _d.update({"description": "not implemented", + "tags":["main"], "backend": "irods"}) + return _d + def status(self) -> dict: """ Returns a basic status of the repository's health or connection. """ - return {"status":False, "message": "not implemented", "public":False, "user":False, "project":False} + return self._add_details_to_status({"status":False, + "message": "not implemented", + "public":False, "user":False, "project":False}) @abstractmethod def list( @@ -990,13 +997,13 @@ class FileBasedRepository(AbstractRepository): user_exists = any( self.fs.exists(p) for p in self._get_collection_paths("user") ) - return {"status":True, + return self._add_details_to_status({"status":True, "message": f"connected", - "public":public_exists, "user":user_exists, "project":project_exists} + "public":public_exists, "user":user_exists, "project":project_exists}) except Exception as e: - return {"status":False, + return self._add_details_to_status({"status":False, "message": f"Repository or path not available with implementation {str(self.__class__)}. Reason: {str(e)}", - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) def exists(self, dataset: Dataset) -> bool: """ @@ -1797,20 +1804,20 @@ class IRODSRepository(FileBasedRepository): """ try: if self._host is None and self.session is None: - return {"status":False, + return self._add_details_to_status({"status":False, "message": f"iRODS connection not established to host {self._host}", - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) status, msg = check_server(self._host, self._port) if self._host is not None else (True, "connection via session") if status: return super().status() else: - return {"status":False, + return self._add_details_to_status({"status":False, "message": f"Connection to server {self._host}:{self._port} failed: {msg}", - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) except Exception as e: - return {"status":False, + return self._add_details_to_status({"status":False, "message": f"Session could not be obtained for {self.project_name}/{self.zone}: " + str(e), - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) def create( self, @@ -2063,13 +2070,13 @@ class LEXISIrodsHTTPRepository(IRODSRepository): if status: return super().status() else: - return {"status":False, + return self._add_details_to_status({"status":False, "message": f"Connection to http server {self._lexis_ds_api.dataset_get_url} failed: {msg}", - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) except Exception as e: - return {"status":False, + return self._add_details_to_status({"status":False, "message":f"Session could not be obtained for {self.project_name}/{self.zone}: " + str(e), - "public":False, "user":False, "project":False} + "public":False, "user":False, "project":False}) def _list(