|
@ -6,7 +6,11 @@ from .utils import check_path, create_cache, get_cache, move, remove, symlink |
|
|
|
|
|
|
|
|
class Transpose: |
|
|
class Transpose: |
|
|
def __init__( |
|
|
def __init__( |
|
|
self, target_path: str, store_path: str, cache_filename: str = None |
|
|
|
|
|
|
|
|
self, |
|
|
|
|
|
target_path: str, |
|
|
|
|
|
store_path: str, |
|
|
|
|
|
cache_filename: str = None, |
|
|
|
|
|
force: bool = False, |
|
|
) -> None: |
|
|
) -> None: |
|
|
self.target_path = Path(target_path) |
|
|
self.target_path = Path(target_path) |
|
|
self.store_path = Path(store_path) |
|
|
self.store_path = Path(store_path) |
|
@ -16,6 +20,8 @@ class Transpose: |
|
|
self.cache_filename = cache_filename |
|
|
self.cache_filename = cache_filename |
|
|
self.cache_path = Path(self.target_path).joinpath(cache_filename) |
|
|
self.cache_path = Path(self.target_path).joinpath(cache_filename) |
|
|
|
|
|
|
|
|
|
|
|
self.force = force |
|
|
|
|
|
|
|
|
def restore(self) -> None: |
|
|
def restore(self) -> None: |
|
|
""" |
|
|
""" |
|
|
Restores a previously Transpose managed directory to it's previous location. |
|
|
Restores a previously Transpose managed directory to it's previous location. |
|
@ -37,6 +43,13 @@ class Transpose: |
|
|
f"Original path in cache file already exists: {original_path}" |
|
|
f"Original path in cache file already exists: {original_path}" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
original_path.parent.mkdir(parents=self.force, exist_ok=True) |
|
|
|
|
|
except FileNotFoundError: |
|
|
|
|
|
raise TransposeError( |
|
|
|
|
|
f"The parent directory for the original path, {original_path.parent} does not exist. Use '-f' to force the creation of this directory" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
move(source=self.target_path, destination=original_path) |
|
|
move(source=self.target_path, destination=original_path) |
|
|
|
|
|
|
|
|
new_cache_path = Path(original_path).joinpath(self.cache_filename) |
|
|
new_cache_path = Path(original_path).joinpath(self.cache_filename) |
|
|