|
@ -17,6 +17,7 @@ class TransposeEntry: |
|
|
name: str |
|
|
name: str |
|
|
path: str |
|
|
path: str |
|
|
created: str # Should be datetime.datetime but not really necessary here |
|
|
created: str # Should be datetime.datetime but not really necessary here |
|
|
|
|
|
enabled: bool = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
@dataclass |
|
@ -48,6 +49,36 @@ class TransposeConfig: |
|
|
created=created, |
|
|
created=created, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def disable(self, name: str) -> None: |
|
|
|
|
|
""" |
|
|
|
|
|
Disable an entry by name. This ensures actions are not run against this entry, such as apply and restore |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
name: The name of the entry (must exist) |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
None |
|
|
|
|
|
""" |
|
|
|
|
|
try: |
|
|
|
|
|
self.entries[name].enabled = False |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
raise TransposeError(f"'{name}' does not exist in Transpose config entries") |
|
|
|
|
|
|
|
|
|
|
|
def enable(self, name: str) -> None: |
|
|
|
|
|
""" |
|
|
|
|
|
Enable an entry by name |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
name: The name of the entry (must exist) |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
None |
|
|
|
|
|
""" |
|
|
|
|
|
try: |
|
|
|
|
|
self.entries[name].enabled = True |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
raise TransposeError(f"'{name}' does not exist in Transpose config entries") |
|
|
|
|
|
|
|
|
def get(self, name: str) -> TransposeEntry: |
|
|
def get(self, name: str) -> TransposeEntry: |
|
|
""" |
|
|
""" |
|
|
Get an entry by the name |
|
|
Get an entry by the name |
|
@ -105,11 +136,14 @@ class TransposeConfig: |
|
|
config = TransposeConfig() |
|
|
config = TransposeConfig() |
|
|
try: |
|
|
try: |
|
|
for name in in_config["entries"]: |
|
|
for name in in_config["entries"]: |
|
|
|
|
|
entry = in_config["entries"][name] |
|
|
config.add( |
|
|
config.add( |
|
|
name, |
|
|
name, |
|
|
in_config["entries"][name]["path"], |
|
|
|
|
|
created=in_config["entries"].get("created"), |
|
|
|
|
|
|
|
|
entry["path"], |
|
|
|
|
|
created=entry.get("created"), |
|
|
) |
|
|
) |
|
|
|
|
|
if "enabled" in entry and not entry["enabled"]: |
|
|
|
|
|
config.disable(name) |
|
|
except (KeyError, TypeError) as e: |
|
|
except (KeyError, TypeError) as e: |
|
|
raise TransposeError(f"Unrecognized Transpose config file format: {e}") |
|
|
raise TransposeError(f"Unrecognized Transpose config file format: {e}") |
|
|
|
|
|
|
|
@ -162,7 +196,11 @@ class Transpose: |
|
|
if not self.config.entries.get(name): |
|
|
if not self.config.entries.get(name): |
|
|
raise TransposeError(f"Entry does not exist: '{name}'") |
|
|
raise TransposeError(f"Entry does not exist: '{name}'") |
|
|
|
|
|
|
|
|
entry_path = Path(self.config.entries[name].path) |
|
|
|
|
|
|
|
|
entry = self.config.entries[name] |
|
|
|
|
|
if hasattr(entry, "enabled") and not entry.enabled and not force: |
|
|
|
|
|
raise TransposeError(f"Entry '{name}' is not enabled in the config") |
|
|
|
|
|
|
|
|
|
|
|
entry_path = Path(entry.path) |
|
|
if entry_path.exists(): |
|
|
if entry_path.exists(): |
|
|
if force: # Backup the existing path |
|
|
if force: # Backup the existing path |
|
|
move(entry_path, entry_path.with_suffix(".backup")) |
|
|
move(entry_path, entry_path.with_suffix(".backup")) |
|
@ -190,7 +228,11 @@ class Transpose: |
|
|
if not self.config.entries.get(name): |
|
|
if not self.config.entries.get(name): |
|
|
raise TransposeError(f"Could not locate entry by name: '{name}'") |
|
|
raise TransposeError(f"Could not locate entry by name: '{name}'") |
|
|
|
|
|
|
|
|
entry_path = Path(self.config.entries[name].path) |
|
|
|
|
|
|
|
|
entry = self.config.entries[name] |
|
|
|
|
|
if hasattr(entry, "enabled") and not entry.enabled and not force: |
|
|
|
|
|
raise TransposeError(f"Entry '{name}' is not enabled in the config") |
|
|
|
|
|
|
|
|
|
|
|
entry_path = Path(entry.path) |
|
|
if entry_path.exists(): |
|
|
if entry_path.exists(): |
|
|
if force: # Backup the existing path |
|
|
if force: # Backup the existing path |
|
|
move(entry_path, entry_path.with_suffix(".backup")) |
|
|
move(entry_path, entry_path.with_suffix(".backup")) |
|
|