fix StateManager to save the state
This commit is contained in:
20
run.py
20
run.py
@@ -267,6 +267,14 @@ class StateManager:
|
||||
with open(STATE_PATH, "w", encoding="utf-8") as f:
|
||||
yaml.safe_dump(self._state, f)
|
||||
|
||||
@staticmethod
|
||||
def _auto_save(func):
|
||||
def wrapper(self, *args, **kwargs):
|
||||
result = func(self, *args, **kwargs)
|
||||
self.save()
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
def check_space(self, lang: Language) -> bool:
|
||||
state = self._load()
|
||||
return lang.value in state.get("space", {}) and bool(state["space"][lang.value])
|
||||
@@ -277,6 +285,7 @@ class StateManager:
|
||||
raise ValueError(f"No space found for language: {lang}")
|
||||
return state["space"][lang.value]
|
||||
|
||||
@_auto_save
|
||||
def add_space(
|
||||
self, lang: Language, file: str, location: str, is_completed: bool
|
||||
) -> None:
|
||||
@@ -290,12 +299,14 @@ class StateManager:
|
||||
}
|
||||
self._state = state
|
||||
|
||||
@_auto_save
|
||||
def remove_space(self, lang: Language) -> None:
|
||||
state = self._load()
|
||||
if "space" in state and lang.value in state["space"]:
|
||||
state["space"][lang.value] = {}
|
||||
self._state = state
|
||||
|
||||
@_auto_save
|
||||
def clear_space(self, lang: Language) -> None:
|
||||
state = self._load()
|
||||
if "space" in state and lang.value in state["space"]:
|
||||
@@ -305,6 +316,7 @@ class StateManager:
|
||||
def reload(self) -> None:
|
||||
self._state = None
|
||||
|
||||
@_auto_save
|
||||
def set_completed(self, lang: Language, is_completed: bool) -> None:
|
||||
state = self._load()
|
||||
if lang.value not in state.get("space", {}):
|
||||
@@ -391,9 +403,7 @@ class StorageManager:
|
||||
raise FileNotFoundError(
|
||||
f"File not found in storage: {location}/{filename}.{lang.value}"
|
||||
)
|
||||
file_path = f"{path}/{filename}"
|
||||
if os.path.isfile(file_path):
|
||||
os.remove(file_path)
|
||||
os.remove(path)
|
||||
|
||||
def mark_completed(self, location: str, lang: Language, filename: str) -> None:
|
||||
uncompleted_file = (
|
||||
@@ -1062,9 +1072,7 @@ def status():
|
||||
click.secho(" not completed", fg="cyan", bold=False, nl=False)
|
||||
click.secho(")", fg="white", bold=False)
|
||||
for lang_name, counts in sorted(langs.items()):
|
||||
click.echo(
|
||||
f" {lang_name}: {counts['completed']}/{counts['total']}"
|
||||
)
|
||||
click.echo(f" {lang_name}: {counts['completed']}/{counts['total']}")
|
||||
click.echo()
|
||||
|
||||
click.secho(
|
||||
|
||||
Reference in New Issue
Block a user