Compare commits
3 Commits
34eac82c7a
...
b3cd28471e
| Author | SHA1 | Date | |
|---|---|---|---|
| b3cd28471e | |||
| b15648a17c | |||
| bfb79e573d |
28
run.py
28
run.py
@@ -267,6 +267,15 @@ 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 +286,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 +300,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 +317,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 +404,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 = (
|
||||
@@ -541,7 +552,7 @@ def register(location: str):
|
||||
@click.option(
|
||||
"--force", "-f", is_flag=True, help="Overwrite existing file if it already exists"
|
||||
)
|
||||
def create(target: str, completed: bool, template: bool, force: bool):
|
||||
def create(target: str, completed: bool, no_template: bool, force: bool):
|
||||
"""
|
||||
지정된 location을 storage에 생성하는 명령어
|
||||
"""
|
||||
@@ -563,10 +574,10 @@ def create(target: str, completed: bool, template: bool, force: bool):
|
||||
if not force:
|
||||
return
|
||||
|
||||
if not template:
|
||||
if no_template:
|
||||
content = b""
|
||||
else:
|
||||
template_path = TEMPLATES_DIR / f"{lang.value}.txt"
|
||||
template_path = TEMPLATES_DIR / f"template.{lang.value}"
|
||||
if template_path.is_file():
|
||||
content = template_path.read_bytes()
|
||||
click.secho(f"Using template: {template_path}", fg="cyan")
|
||||
@@ -761,6 +772,7 @@ def export(from_: tuple[str, ...], all_: bool, force: bool):
|
||||
StorageManager().save_file(
|
||||
s_loc, from_language, s_file, content, s_is_completed
|
||||
)
|
||||
StateManager().clear_space(from_language)
|
||||
click.secho(
|
||||
f"Exported '{s_file}.{from_language.value}' to location '{s_loc}'",
|
||||
fg="cyan",
|
||||
@@ -1062,9 +1074,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