diff --git a/changelog.md b/changelog.md index 77f53ef..42678ce 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,6 @@ * Simple command-line interface for persistent archive manager -### 0.1.3 - 2020-09-21 +### 0.1.3 - 2020-10-05 * Add archive manager that maintains descriptors in a relational database (\#8) diff --git a/histore/archive/manager/base.py b/histore/archive/manager/base.py index e7b9b87..7247e97 100644 --- a/histore/archive/manager/base.py +++ b/histore/archive/manager/base.py @@ -51,7 +51,8 @@ def create( primary_key: Optional[Union[List[str], str]] = None, encoder: Optional[str] = None, decoder: Optional[str] = None ) -> ArchiveDescriptor: - """Create a new archive object. + """Create a new archive object. Raises a ValueError if an archive with + the given name exists. Parameters ---------- @@ -72,6 +73,10 @@ def create( Returns ------- histore.archive.manager.descriptor.ArchiveDescriptor + + Raises + ------ + ValueError """ raise NotImplementedError() diff --git a/histore/archive/manager/db/base.py b/histore/archive/manager/db/base.py index 885ab31..c393687 100644 --- a/histore/archive/manager/db/base.py +++ b/histore/archive/manager/db/base.py @@ -63,9 +63,9 @@ def __init__( if create: # Create a fresh database instance. db.init() - # Delete the base directory if it exists. + # Clear all files in the base directory if it exists. if os.path.isdir(self.basedir): - shutil.rmtree(self.basedir) + util.cleardir(self.basedir) # Create the base directory (if it does not exist). util.createdir(basedir) diff --git a/histore/archive/manager/db/model.py b/histore/archive/manager/db/model.py index 8870348..ea297e8 100644 --- a/histore/archive/manager/db/model.py +++ b/histore/archive/manager/db/model.py @@ -23,9 +23,7 @@ class Archive(Base): - """A workflow group associates a set of users with a workflow template. It - allows to define a group-specific set of parameters for the template. - """ + """ORM for maintaining archive descriptors in a relational database.""" # -- Schema --------------------------------------------------------------- __tablename__ = 'archive' diff --git a/histore/archive/manager/descriptor.py b/histore/archive/manager/descriptor.py index 7ca3794..ddf39fe 100644 --- a/histore/archive/manager/descriptor.py +++ b/histore/archive/manager/descriptor.py @@ -9,8 +9,6 @@ by an archive manager. """ -from __future__ import annotations - import jsonschema from datetime import datetime @@ -71,7 +69,7 @@ def create( description: Optional[str] = None, primary_key: Optional[Union[List[str], str]] = None, encoder: Optional[str] = None, decoder: Optional[str] = None - ) -> ArchiveDescriptor: + ): """Create a new archive descriptor object. Parameters diff --git a/histore/archive/manager/fs.py b/histore/archive/manager/fs.py index 5dfc461..13490b0 100644 --- a/histore/archive/manager/fs.py +++ b/histore/archive/manager/fs.py @@ -48,9 +48,9 @@ def __init__( self.basedir = basedir # Initialize path to file that maintains archive descriptors. if create: - # Delete the base directory if it exists. + # Clear all files in the base directory if it exists. if os.path.isdir(self.basedir): - shutil.rmtree(self.basedir) + util.cleardir(self.basedir) util.createdir(self.basedir) # Initialize the internal cache of archive descriptors self.descriptorfile = os.path.join(basedir, 'archives.json') diff --git a/histore/archive/snapshot.py b/histore/archive/snapshot.py index c4b7d72..424fc20 100644 --- a/histore/archive/snapshot.py +++ b/histore/archive/snapshot.py @@ -7,7 +7,6 @@ """Classes to maintain information about dataset snapshots in an archive.""" -from __future__ import annotations from datetime import datetime from typing import List, Optional @@ -124,7 +123,7 @@ def __len__(self): def append( self, version: int, valid_time: Optional[datetime] = None, description: Optional[str] = None - ) -> SnapshotListing: + ): """Add a new version to the given listing. This will return a modified version listing with the new snapshot as the last element. diff --git a/histore/util.py b/histore/util.py index 357830f..2b11b04 100644 --- a/histore/util.py +++ b/histore/util.py @@ -16,6 +16,7 @@ import errno import gzip import os +import shutil import uuid @@ -103,6 +104,22 @@ def import_obj(import_path): # -- I/O ---------------------------------------------------------------------- +def cleardir(directory): + """Remove all files in the given directory. + + Parameters + ---------- + directory: string + Path to directory that is being created. + """ + for filename in os.listdir(directory): + file = os.path.join(directory, filename) + if os.path.isfile(file) or os.path.islink(file): + os.unlink(file) + elif os.path.isdir(file): + shutil.rmtree(file) + + def createdir(directory, abs=False): """Safely create the given directory path if it does not exist. diff --git a/requirements.txt b/requirements.txt index 796b719..6208db6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -future pandas>=1.0.0 jsonschema>=3.2.0 python-dateutil diff --git a/setup.py b/setup.py index d6555f8..04fb857 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ install_requires = [ - 'future', 'pandas>=1.0.0', 'jsonschema>=3.2.0', 'python-dateutil',