#8 Move store_path to store action only

Merged
ryanreed merged 2 commits from move-store-path into master 2 years ago
  1. +1
    -1
      README.md
  2. +9
    -10
      src/transpose/console.py
  3. +2
    -4
      src/transpose/transpose.py
  4. +2
    -2
      tests/test_console.py
  5. +9
    -29
      tests/test_transpose.py

+ 1
- 1
README.md View File

@ -49,7 +49,7 @@ transpose restore ~/.local/share/transpose/zsh # Remove symlink, move ~/.local/
transpose apply ~/.local/share/transpose/zsh # Recreate symlink in cache location
transpose create ~/.config/zsh ~/.local/share/transpose/zsh # Recreate cache file
transpose -s /mnt/backups store ~/.config/zsh zsh_config # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache
transpose store ~/.config/zsh zsh_config -s /mnt/backups # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache
transpose --cache-filename .mycache.json restore /mnt/backups/zsh_config # Use /mnt/backup/.zsh_config.json for restoring a stored directory
```


+ 9
- 10
src/transpose/console.py View File

@ -9,7 +9,6 @@ def entry_point() -> None:
t = Transpose(
target_path=args.target_path,
store_path=args.store_path,
cache_filename=args.cache_filename,
)
@ -20,7 +19,7 @@ def entry_point() -> None:
elif args.action == "restore":
t.restore()
elif args.action == "store":
t.store(name=args.name)
t.store(store_path=args.store_path, name=args.name)
def parse_arguments(args=None):
@ -43,14 +42,6 @@ def parse_arguments(args=None):
""",
)
parser.add_argument("--version", action="version", version=f"Transpose {version}")
parser.add_argument(
"-s",
"--store-path",
dest="store_path",
nargs="?",
default=store_path,
help="The path to where the targets should be stored (default: %(default)s)",
)
subparsers = parser.add_subparsers(
help="Transpose Action", dest="action", required=True
@ -105,6 +96,14 @@ def parse_arguments(args=None):
default=None,
help="The name of the directory that will be created in the store path (default: target_path)",
)
store_parser.add_argument(
"-s",
"--store-path",
dest="store_path",
nargs="?",
default=store_path,
help="The path to where the targets should be stored (default: %(default)s)",
)
return parser.parse_args(args)


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

@ -8,11 +8,9 @@ class Transpose:
def __init__(
self,
target_path: str,
store_path: str,
cache_filename: str = None,
) -> None:
self.target_path = pathlib.Path(target_path)
self.store_path = pathlib.Path(store_path)
if not cache_filename:
cache_filename = ".transpose.json"
@ -86,14 +84,14 @@ class Transpose:
new_cache_path = pathlib.Path(original_path).joinpath(self.cache_filename)
remove(new_cache_path)
def store(self, name: str = None) -> None:
def store(self, store_path: str, 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)
new_location = pathlib.Path(store_path).joinpath(name)
if not check_path(path=self.target_path):
raise TransposeError(


+ 2
- 2
tests/test_console.py View File

@ -10,13 +10,13 @@ def test_parse_arguments():
args = parse_arguments(
[
"--store-path",
"/mnt/store",
"store",
"--cache-filename",
"test-cache-file.json",
"MyTarget",
"/tmp/some/path",
"--store-path",
"/mnt/store",
]
)
assert args.cache_filename == "test-cache-file.json"


+ 9
- 29
tests/test_transpose.py View File

@ -16,16 +16,11 @@ from .utils import (
def test_init():
t = Transpose(
target_path=TARGET_DIR,
store_path=STORE_DIR,
)
t = Transpose(target_path=TARGET_DIR)
assert t.cache_filename == ".transpose.json"
assert t.cache_path == pathlib.Path(TARGET_DIR).joinpath(".transpose.json")
t = Transpose(
target_path=TARGET_DIR, store_path=STORE_DIR, cache_filename=".transpose.txt"
)
t = Transpose(target_path=TARGET_DIR, cache_filename=".transpose.txt")
assert t.cache_filename == ".transpose.txt"
assert t.cache_path == pathlib.Path(TARGET_DIR).joinpath(".transpose.txt")
@ -35,10 +30,7 @@ def test_apply():
store_path = pathlib.Path(STORE_DIR)
target_path = pathlib.Path(TARGET_DIR)
t = Transpose(
target_path=STORE_DIR,
store_path=STORE_DIR,
)
t = Transpose(target_path=STORE_DIR)
with open(t.cache_path, "r") as f:
cache = json.load(f)
@ -65,10 +57,7 @@ def test_create():
target_path = pathlib.Path(TARGET_DIR)
stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR)
t = Transpose(
target_path=str(target_path),
store_path=str(stored_path),
)
t = Transpose(target_path=str(target_path))
# Missing stored path
stored_path.rename("tmp")
@ -91,11 +80,8 @@ def test_create():
@setup_store()
def test_store():
t = Transpose(
target_path=TARGET_DIR,
store_path=STORE_DIR,
)
t.store()
t = Transpose(target_path=TARGET_DIR)
t.store(store_path=STORE_DIR)
target_path = pathlib.Path(TARGET_DIR)
store_path = pathlib.Path(STORE_DIR).joinpath(target_path.name)
@ -108,11 +94,8 @@ def test_store():
@setup_store()
def test_store_named():
t = Transpose(
target_path=TARGET_DIR,
store_path=STORE_DIR,
)
t.store("TestStore")
t = Transpose(target_path=TARGET_DIR)
t.store(store_path=STORE_DIR, name="TestStore")
target_path = pathlib.Path(TARGET_DIR)
store_path = pathlib.Path(STORE_DIR).joinpath("TestStore")
@ -128,10 +111,7 @@ def test_restore():
target_path = pathlib.Path(TARGET_DIR)
stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR)
t = Transpose(
target_path=str(stored_path),
store_path=STORE_DIR,
)
t = Transpose(target_path=str(stored_path))
# Missing Cache File
cache = t.cache_path.read_text()


Loading…
Cancel
Save