Make path upon instantiation

This commit is contained in:
Eric Torres 2019-04-17 10:00:54 -07:00
parent 4d81405400
commit 17db66a85e

View File

@ -21,15 +21,12 @@ METADATA_WRITE = "w"
class Hierarchy(PathLike): class Hierarchy(PathLike):
"""A general class for organizing a hierarchy of data. """A general class for organizing a hierarchy of data.
Hierarchy objects are non-intrusive in that they do not affect
the filesystem upon creation. It is up to the caller
to call either :func:`shutil.mkdir` or related method to create
the directory structure it emulates.
**Implementation Details** **Implementation Details**
* For consistency, ``Hierarchy`` objects always store and return absolute paths * For consistency, ``Hierarchy`` objects always store and return absolute paths
* Data for all ``Hierarchy`` objects and subclassed objects use JSON for serialization * Data for all ``Hierarchy`` objects and subclassed objects use JSON for serialization
* ``Hierarchy`` objects create their directories upon instantiation
* This may result in a ``PermissionError``
""" """
def __init__(self, dest): def __init__(self, dest):
@ -37,11 +34,14 @@ class Hierarchy(PathLike):
:param dest: the root directory of the backup hierarchy :param dest: the root directory of the backup hierarchy
:type dest: str or path-like object :type dest: str or path-like object
:raises PermissionError: if process does not have permission to write at dest
""" """
self._path = Path(dest).resolve() self._path = Path(dest).resolve()
self._metadata_path = self._path / ".metadata" self._metadata_path = self._path / ".metadata"
self._name = self._path.name self._name = self._path.name
self.path.mkdir(DIRMODE, parents=True, exist_ok=True)
def __fspath__(self): def __fspath__(self):
return str(self._path) return str(self._path)