Skip to content

Commit

Permalink
WIP: Establish sharable abstraction on Dataset.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Dec 1, 2020
1 parent 961089e commit 04fdb23
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/galaxy/objectstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 04fdb23

Please sign in to comment.