From 57f26ee700d9f38ab54207b89ff293cc34c7ecbf Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 17 Jul 2022 21:41:50 -0400 Subject: [PATCH] Making name argument optional for transpose store --- CHANGELOG.md | 17 +++++++++++++++++ README.md | 21 +++++++++++++++++++-- pyproject.toml | 2 +- src/transpose/console.py | 10 ++++++---- src/transpose/transpose.py | 5 ++++- tests/test_console.py | 9 ++++----- tests/test_transpose.py | 19 ++++++++++++++++++- 7 files changed, 69 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3678176..9ba33bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +# 1.0.2 (2022-07-17) + +## Features + +* Made `name` argument optional when using the `transpose store` +* Moved `name` argument to end of `transpose store` + +Note: I'm abusing the versioning a bit as I'm the only user of this tool. Normally, this would be considered a breaking change due to the change in argument order. Shouldn't happen again. + + +# 1.0.1 (2022-07-16) + +## Hotfixes + +* Utilize `expanduser` and `~` in cache files to allow for more portable restorations + + # 1.0.0 (2022-07-12) Initial release diff --git a/README.md b/README.md index cc29a58..fef53af 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,21 @@ A tool for moving and symlinking directories to a central location +## Table of Contents + + + +* [Introduction](#introduction) +* [Installation](#installation) +* [Configuration](#configuration) +* [Usage](#usage) + * [Storing a Directory](#storing-a-directory) + * [Restoring a Stored Directory](#restoring-a-stored-directory) + * [Applying a Previously Transpose Managed Directory](#applying-a-previously-transpose-managed-directory) + + + + ## Introduction I've been using linux as my main machine for a while and wanted a central directory to backup as backing up my entire `HOME` directory was a mess. I found moving directories and symlinking worked great. I created a simple project when learning python (I called symlinker) and used it for a while but found it annoying to configure and work with. @@ -47,7 +62,7 @@ Storing a directory will: 3. Create a cache file at `$STORE_PATH/{name}/.transpose.json` to store the original target path ``` -transpose store "My Documents" /home/user/Documents +transpose store /home/user/Documents "My Documents" ``` The above will (assuming using all the defaults): @@ -55,9 +70,11 @@ The above will (assuming using all the defaults): 1. Move `/home/user/Documents` to `$XDG_DATA_HOME/transpose/My Documents` 2. Symlink `/home/user/Documents` to `$XDG_DATA_HOME/transpose/My Documents` +Note: The name on the end (`My Documents` above), can be ommitted. The stored name will use the target name (e.g. `Documents` above) + -### Restoring a Store Directory +### Restoring a Stored Directory Restoring a directory will: diff --git a/pyproject.toml b/pyproject.toml index 8303a8e..39d23b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "transpose" -version = "1.0.1" +version = "1.0.2" description = "Move and symlink a path" authors = ["Ryan Reed"] license = "GPLv3" diff --git a/src/transpose/console.py b/src/transpose/console.py index 795e2b1..4f708cf 100644 --- a/src/transpose/console.py +++ b/src/transpose/console.py @@ -94,14 +94,16 @@ def parse_arguments(args=None): help="Move target and create symlink in place", parents=[base_parser], ) - store_parser.add_argument( - "name", - help="The name of the directory that will be created in the store path", - ) store_parser.add_argument( "target_path", help="The path to the directory that should be moved to storage", ) + store_parser.add_argument( + "name", + nargs="?", + default=None, + help="The name of the directory that will be created in the store path (default: target_path)", + ) return parser.parse_args(args) diff --git a/src/transpose/transpose.py b/src/transpose/transpose.py index e24d7f7..d2e979b 100644 --- a/src/transpose/transpose.py +++ b/src/transpose/transpose.py @@ -86,10 +86,13 @@ class Transpose: new_cache_path = pathlib.Path(original_path).joinpath(self.cache_filename) remove(new_cache_path) - def store(self, name: str) -> None: + def store(self, name: str = None) -> None: """ Moves a directory to a central location and creates a symlink to the old path. """ + if name is None: + name = self.target_path.name + new_location = pathlib.Path(self.store_path).joinpath(name) if not check_path(path=self.target_path): diff --git a/tests/test_console.py b/tests/test_console.py index d87d011..8c2f056 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -49,15 +49,14 @@ def test_parse_arguments_create(): def test_parse_arguments_store(): - # Missing required argument - name + # Missing required argument - target_path with pytest.raises(SystemExit): args = parse_arguments(["store"]) - # Missing required argument - target_path - with pytest.raises(SystemExit): - args = parse_arguments(["store", "My Name"]) + args = parse_arguments(["store", "/tmp/some/path"]) + assert args.name is None - args = parse_arguments(["store", "My Name", "/tmp/some/path"]) + args = parse_arguments(["store", "/tmp/some/path", "My Name"]) assert args.action == "store" assert args.name == "My Name" assert args.target_path == "/tmp/some/path" diff --git a/tests/test_transpose.py b/tests/test_transpose.py index a81e6c0..1d83c26 100644 --- a/tests/test_transpose.py +++ b/tests/test_transpose.py @@ -91,6 +91,23 @@ def test_create(): @setup_store() def test_store(): + t = Transpose( + target_path=TARGET_DIR, + store_path=STORE_DIR, + ) + t.store() + + target_path = pathlib.Path(TARGET_DIR) + store_path = pathlib.Path(STORE_DIR).joinpath(target_path.name) + + # Successful Store + assert store_path.is_dir() and not store_path.is_symlink() + assert target_path.is_dir() and target_path.is_symlink() + assert t.cache_path.is_file() + + +@setup_store() +def test_store_named(): t = Transpose( target_path=TARGET_DIR, store_path=STORE_DIR, @@ -100,7 +117,7 @@ def test_store(): target_path = pathlib.Path(TARGET_DIR) store_path = pathlib.Path(STORE_DIR).joinpath("TestStore") - ## Successful Store + # Successful Store assert store_path.is_dir() and not store_path.is_symlink() assert target_path.is_dir() and target_path.is_symlink() assert t.cache_path.is_file()