MIL-011: Menu bar

Review record RC-066 (Go, autonomous mode, not independent).

Task: MIL-011#1
Task: MIL-011#2
Task: MIL-011#3
Task: MIL-011#4
Task: MIL-011#5
Task: MIL-011#6
Task: MIL-011#7
Task: MIL-011#8
This commit is contained in:
2026-10-15 09:06:47 +08:00
parent 5d626dc890
commit ce4aacb4bc
28 changed files with 1450 additions and 35 deletions
@@ -42,3 +42,11 @@ class CsvProgressRepository:
@return Nothing.
"""
write_word_list(self._path, deck.language_pair, deck.cards)
def reset(self) -> None:
"""Delete the words to learn file; nothing happens when it is absent.
@return Nothing.
@throws OSError When the file cannot be deleted.
"""
self._path.unlink(missing_ok=True)
@@ -67,7 +67,8 @@ def read_word_list(path: Path) -> tuple[LanguagePair, tuple[Card, ...]]:
@param path The CSV file: a header of two language codes, then one card a row.
@return The language pair and the cards in file order.
@throws VocabularyNotFoundError When the file does not exist.
@throws VocabularyFormatError When the file is empty or a row is malformed.
@throws VocabularyFormatError When the file is empty, not UTF-8 text, cannot
be read or a row is malformed.
"""
pair: LanguagePair | None = None
cards: list[Card] = []
@@ -83,6 +84,10 @@ def read_word_list(path: Path) -> tuple[LanguagePair, tuple[Card, ...]]:
cards.append(_parse_card(path, reader.line_num, row))
except FileNotFoundError as error:
raise VocabularyNotFoundError(f"word list not found: {path}") from error
except UnicodeDecodeError as error:
raise VocabularyFormatError(f"{path}: file is not UTF-8 text") from error
except OSError as error:
raise VocabularyFormatError(f"{path}: cannot be read: {error}") from error
if pair is None:
raise _format_error(path, 1, "file is empty")
return pair, tuple(cards)
@@ -0,0 +1,30 @@
"""Name of the words to learn file of a word list.
@file progress_file_name.py
@brief Keeps the progress of every word list in a file of its own.
"""
import re
from pathlib import Path
from flash_card.constants import (
PROGRESS_FILE_NAME,
PROGRESS_FILE_NAME_TEMPLATE,
PROGRESS_STEM_FORBIDDEN,
PROGRESS_STEM_REPLACEMENT,
VOCABULARY_FILE_NAME,
)
def progress_file_name(list_path: Path) -> str:
"""Name the words to learn file of a word list.
@param list_path Path of the word list file.
@return The default file name for the delivered list, else a name made of
the list's file name stem with other characters than letters, digits,
hyphen and underscore replaced by an underscore.
"""
if list_path.name == VOCABULARY_FILE_NAME:
return PROGRESS_FILE_NAME
stem = re.sub(PROGRESS_STEM_FORBIDDEN, PROGRESS_STEM_REPLACEMENT, list_path.stem)
return PROGRESS_FILE_NAME_TEMPLATE.format(stem=stem)