Browse Source

Adding upgrade script and removing unnecessary checks

master
Ryan Reed 1 year ago
parent
commit
112db3e542
2 changed files with 30 additions and 4 deletions
  1. +26
    -0
      scripts/upgrade-2.2.py
  2. +4
    -4
      src/transpose/transpose.py

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

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

@ -140,9 +140,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 +197,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 +229,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)


Loading…
Cancel
Save