Browse Source

Making name argument optional for transpose store

pull/7/head
Ryan Reed 2 years ago
parent
commit
57f26ee700
7 changed files with 69 additions and 14 deletions
  1. +17
    -0
      CHANGELOG.md
  2. +19
    -2
      README.md
  3. +1
    -1
      pyproject.toml
  4. +6
    -4
      src/transpose/console.py
  5. +4
    -1
      src/transpose/transpose.py
  6. +4
    -5
      tests/test_console.py
  7. +18
    -1
      tests/test_transpose.py

+ 17
- 0
CHANGELOG.md View File

@ -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

+ 19
- 2
README.md View File

@ -3,6 +3,21 @@
A tool for moving and symlinking directories to a central location
## Table of Contents
<!-- vim-markdown-toc GFM -->
* [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)
<!-- vim-markdown-toc -->
## 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:


+ 1
- 1
pyproject.toml View File

@ -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"


+ 6
- 4
src/transpose/console.py View File

@ -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)


+ 4
- 1
src/transpose/transpose.py View File

@ -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):


+ 4
- 5
tests/test_console.py View File

@ -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"


+ 18
- 1
tests/test_transpose.py View File

@ -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()


Loading…
Cancel
Save