From 04fdb231beb5b48b44b32eebc3898b73f02b74ee Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 1 Dec 2020 16:47:34 -0500 Subject: [PATCH] WIP: Establish ``sharable`` abstraction on Dataset. --- lib/galaxy/model/__init__.py | 19 ++++++++++++++++--- lib/galaxy/objectstore/__init__.py | 13 +++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 5513c9a220c1..17a42c0aa314 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2394,11 +2394,20 @@ def is_new(self): def in_ready_state(self): return self.state in self.ready_states + @property + def sharable(self): + """Return True if placed into an objectstore not labeled as ``private``.""" + if not self.external_filename: + return True + else: + object_store = self._assert_object_store_set() + return not object_store.is_private(self) + def get_file_name(self): if not self.external_filename: - assert self.object_store is not None, "Object Store has not been initialized for dataset %s" % self.id - if self.object_store.exists(self): - return self.object_store.get_filename(self) + object_store = self._assert_object_store_set() + if object_store.exists(self): + return object_store.get_filename(self) else: return '' else: @@ -2413,6 +2422,10 @@ def set_file_name(self, filename): self.external_filename = filename file_name = property(get_file_name, set_file_name) + def _assert_object_store_set(self): + assert self.object_store is not None, "Object Store has not been initialized for dataset %s" % self.id + return self.object_store + def get_extra_files_path(self): # Unlike get_file_name - external_extra_files_path is not backed by an # actual database column so if SA instantiates this object - the diff --git a/lib/galaxy/objectstore/__init__.py b/lib/galaxy/objectstore/__init__.py index 01dd56ff953a..a62dc74c7607 100644 --- a/lib/galaxy/objectstore/__init__.py +++ b/lib/galaxy/objectstore/__init__.py @@ -198,6 +198,10 @@ def get_concrete_store_description_markdown(self, obj): be returned for the ConcreteObjectStore corresponding to the object. """ + @abc.abstractmethod + def is_private(self, obj): + """Return True iff supplied object is stored in private ConcreteObjectStore.""" + @abc.abstractmethod def get_store_usage_percent(self): """Return the percentage indicating how full the store is.""" @@ -334,6 +338,9 @@ def get_store_usage_percent(self): def get_store_by(self, obj, **kwargs): return self._invoke('get_store_by', obj, **kwargs) + def is_private(self, obj): + return self._invoke('is_private', obj) + @classmethod def parse_private_from_config_xml(clazz, config_xml): private = DEFAULT_PRIVATE @@ -385,6 +392,9 @@ def _get_concrete_store_description_markdown(self, obj): def _get_store_by(self, obj): return self.store_by + def _is_private(self, obj): + return self.private + class DiskObjectStore(ConcreteObjectStore): """ @@ -726,6 +736,9 @@ def _get_concrete_store_name(self, obj): def _get_concrete_store_description_markdown(self, obj): return self._call_method('_get_concrete_store_description_markdown', obj, None, True) + def _is_private(self, obj): + return self._call_method('_is_private', obj, None, True) + def _get_store_by(self, obj): return self._call_method('_get_store_by', obj, None, False)