6 Commits

7 changed files with 57 additions and 57 deletions
Split View
  1. +0
    -40
      CHANGELOG.md
  2. +1
    -1
      pyproject.toml
  3. +26
    -0
      scripts/upgrade-2.2.py
  4. +0
    -4
      src/transpose/__init__.py
  5. +0
    -6
      src/transpose/logger.py
  6. +11
    -6
      src/transpose/transpose.py
  7. +19
    -0
      tests/test_transpose.py

+ 0
- 40
CHANGELOG.md View File

@ -1,40 +0,0 @@
# Change Log
## 1.1.0 (2022-07-26)
### Breaking Changes
* Moving store_path to only the store action
Note: I know I said this shouldn't happen again but I couldn't help myself. This time....for sure.
### Features
* Allow for short -s for --store-path
### Documentation
* Add Quick Reference section
### Tests
* Updating tests to support moving store_path to store action
## 1.0.2 (2022-07-17)
### Added
* The `name` argument is now optional when using the `transpose store`
### Changed
* 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)
### Fixed
* Utilize `expanduser` and `~` in cache files to allow for more portable restorations
## 1.0.0 (2022-07-12)
Initial release

+ 1
- 1
pyproject.toml View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "transpose"
version = "2.2.0"
version = "2.2.2"
description = "Move and symlink a path to a central location"
authors = ["Ryan Reed"]
license = "GPLv3"


+ 26
- 0
scripts/upgrade-2.2.py View File

@ -0,0 +1,26 @@
"""
Loop through entries and ensure using the latest 2.2 entities
This means adding the following new fields to each entry:
* created (2.1)
* enabled (2.2)
"""
import json
from transpose import DEFAULT_STORE_PATH, TransposeConfig
def main() -> None:
config_file = f"{DEFAULT_STORE_PATH}/transpose.json"
with open(config_file, "r") as f:
d = json.load(f)
config = TransposeConfig()
for entry_name in d["entries"]:
config.add(entry_name, d["entries"][entry_name]["path"])
config.save(config_file)
if __name__ == "__main__":
main()

+ 0
- 4
src/transpose/__init__.py View File

@ -2,14 +2,10 @@ import os
from importlib.metadata import version
from .logger import create_logger
DEFAULT_XDG_PATH = os.environ.get("XDG_DATA_HOME", f"{os.environ['HOME']}/.local/share")
STORE_PATH = f"{DEFAULT_XDG_PATH}/transpose"
DEFAULT_STORE_PATH = os.environ.get("TRANSPOSE_STORE_PATH", STORE_PATH)
version = version("transpose")
logger = create_logger(__package__)
from .transpose import Transpose, TransposeConfig, TransposeEntry # noqa: E402

+ 0
- 6
src/transpose/logger.py View File

@ -1,6 +0,0 @@
import logging
def create_logger(logger_name: str) -> logging:
logger = logging.getLogger(logger_name)
return logger

+ 11
- 6
src/transpose/transpose.py View File

@ -111,7 +111,7 @@ class TransposeConfig:
def update(self, name: str, field_key: str, field_value: Any) -> None:
"""
Update an entry by name
Update an entry's field (attribute) value
Args:
name: The name of the entry (must exist)
@ -122,16 +122,21 @@ class TransposeConfig:
None
"""
try:
setattr(self.entries[name], field_key, field_value)
if not hasattr(self.entries[name], field_key):
raise TransposeError(f"Unknown TransposeEntry field: {field_key}")
except KeyError:
raise TransposeError(f"'{name}' does not exist in Transpose config entries")
setattr(self.entries[name], field_key, field_value)
@staticmethod
def load(config_path: str): # -> Self:
try:
in_config = json.load(open(config_path, "r"))
except json.decoder.JSONDecodeError as e:
raise TransposeError(f"Invalid JSON format for '{config_path}': {e}")
except FileNotFoundError:
in_config = {"entries": {}}
config = TransposeConfig()
try:
@ -140,9 +145,9 @@ class TransposeConfig:
config.add(
name,
entry["path"],
created=entry.get("created"),
created=entry["created"],
)
if "enabled" in entry and not entry["enabled"]:
if not entry["enabled"]:
config.disable(name)
except (KeyError, TypeError) as e:
raise TransposeError(f"Unrecognized Transpose config file format: {e}")
@ -197,7 +202,7 @@ class Transpose:
raise TransposeError(f"Entry does not exist: '{name}'")
entry = self.config.entries[name]
if hasattr(entry, "enabled") and not entry.enabled and not force:
if not entry.enabled and not force:
raise TransposeError(f"Entry '{name}' is not enabled in the config")
entry_path = Path(entry.path)
@ -229,7 +234,7 @@ class Transpose:
raise TransposeError(f"Could not locate entry by name: '{name}'")
entry = self.config.entries[name]
if hasattr(entry, "enabled") and not entry.enabled and not force:
if not entry.enabled and not force:
raise TransposeError(f"Entry '{name}' is not enabled in the config")
entry_path = Path(entry.path)


+ 19
- 0
tests/test_transpose.py View File

@ -196,6 +196,9 @@ def test_config_update():
):
config.update("UnknownEntry", "path", "/some/new/path")
with pytest.raises(TransposeError, match="Unknown TransposeEntry field"):
config.update(ENTRY_NAME, "UnknownField", "Some Value")
config.update(ENTRY_NAME, "path", "/some/new/path")
assert config.entries[ENTRY_NAME].path == "/some/new/path"
@ -213,6 +216,22 @@ def test_config_save():
)
@setup_store()
def test_config_save_fresh():
"""
Verify creation of transpose config when doesn't initially exist
"""
TRANSPOSE_CONFIG_PATH.unlink()
config = TransposeConfig.load(TRANSPOSE_CONFIG_PATH)
assert len(config.entries) == 0
config.add("TestEntry", TARGET_PATH)
config.save(TRANSPOSE_CONFIG_PATH)
config = TransposeConfig.load(TRANSPOSE_CONFIG_PATH)
assert config.entries.get("TestEntry")
@setup_store()
def test_config_load():
config = TransposeConfig.load(TRANSPOSE_CONFIG_PATH)


Loading…
Cancel
Save