base_non_rdf_layout.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import logging
  2. import os
  3. from abc import ABCMeta, abstractmethod
  4. from lakesuperior.util.toolbox import get_tree_size
  5. logger = logging.getLogger(__name__)
  6. class BaseNonRdfLayout(metaclass=ABCMeta):
  7. """
  8. Abstract class for setting the non-RDF (bitstream) store layout.
  9. Differerent layouts can be created by implementing all the abstract methods
  10. of this class. A non-RDF layout is not necessarily restricted to a
  11. traditional filesystem—e.g. a layout persisting to HDFS can be written too.
  12. """
  13. def __init__(self, config):
  14. """
  15. Initialize the base non-RDF store layout.
  16. """
  17. self.config = config
  18. self.root = config['location']
  19. @property
  20. def store_size(self):
  21. """Calculated the store size on disk."""
  22. return get_tree_size(self.root)
  23. @property
  24. def file_ct(self):
  25. """Calculated the store size on disk."""
  26. return sum([len(files) for r, d, files in os.walk(self.root)])
  27. ## INTERFACE METHODS ##
  28. @abstractmethod
  29. def persist(self, stream):
  30. """Store the stream in the designated persistence layer."""
  31. pass
  32. @abstractmethod
  33. def delete(self, id):
  34. """Delete a stream by its identifier (i.e. checksum)."""
  35. pass
  36. @abstractmethod
  37. def local_path(self, uuid):
  38. """Return the local path of a file."""
  39. pass