Clean up review findings
This commit is contained in:
+2
-85
@@ -358,14 +358,6 @@ def ensure_project_app_root():
|
||||
return PROJECT_APP_ROOT
|
||||
|
||||
|
||||
def legacy_state_root():
|
||||
return Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state")) / APP_NAME
|
||||
|
||||
|
||||
def legacy_config_root():
|
||||
return Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / APP_NAME
|
||||
|
||||
|
||||
def project_state_path(*parts):
|
||||
return PROJECT_APP_ROOT.joinpath(*parts)
|
||||
|
||||
@@ -374,53 +366,6 @@ def project_state_dir(*parts):
|
||||
return PROJECT_APP_ROOT.joinpath(*parts)
|
||||
|
||||
|
||||
def migrate_legacy_file(project_path, legacy_path, label):
|
||||
if project_path.exists() or not legacy_path.exists():
|
||||
return project_path
|
||||
project_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
shutil.move(str(legacy_path), str(project_path))
|
||||
debug_log("state.migrated", label=label, from_path=legacy_path, to_path=project_path)
|
||||
except OSError as exc:
|
||||
debug_log("state.migrate_failed", label=label, from_path=legacy_path, to_path=project_path, error=exc)
|
||||
return project_path
|
||||
|
||||
|
||||
def migrate_legacy_dir(project_dir, legacy_dir, label):
|
||||
if not legacy_dir.exists():
|
||||
return project_dir
|
||||
project_dir.mkdir(parents=True, exist_ok=True)
|
||||
moved = 0
|
||||
for child in legacy_dir.iterdir():
|
||||
target = project_dir / child.name
|
||||
if target.exists():
|
||||
if child.is_dir() and target.is_dir():
|
||||
migrate_legacy_dir(target, child, f"{label}/{child.name}")
|
||||
continue
|
||||
try:
|
||||
shutil.move(str(child), str(target))
|
||||
moved += 1
|
||||
except OSError as exc:
|
||||
debug_log("state.migrate_failed", label=label, from_path=child, to_path=target, error=exc)
|
||||
try:
|
||||
legacy_dir.rmdir()
|
||||
except OSError:
|
||||
pass
|
||||
if moved:
|
||||
debug_log("state.migrated", label=label, from_path=legacy_dir, to_path=project_dir, entries=moved)
|
||||
return project_dir
|
||||
|
||||
|
||||
LEGACY_STATE_ROOT = legacy_state_root()
|
||||
LEGACY_CONFIG_ROOT = legacy_config_root()
|
||||
LEGACY_CONFIG_PATH = LEGACY_CONFIG_ROOT / "config.json"
|
||||
LEGACY_QUEUE_PATH = LEGACY_STATE_ROOT / "queue.json"
|
||||
LEGACY_QUEUE_DB_PATH = LEGACY_STATE_ROOT / "queue.sqlite3"
|
||||
LEGACY_STAGING_ROOT = LEGACY_STATE_ROOT / "staging"
|
||||
LEGACY_WATCHLIST_JSON_PATH = LEGACY_STATE_ROOT / "watchlist.json"
|
||||
LEGACY_THUMBNAIL_ROOT = LEGACY_STATE_ROOT / "thumbnails"
|
||||
LEGACY_ANIDB_TITLES_PATH = LEGACY_STATE_ROOT / "anidb-anime-titles.xml.gz"
|
||||
|
||||
CONFIG_PATH = project_state_path("config.json")
|
||||
QUEUE_PATH = project_state_path("queue.json")
|
||||
STATE_DB_PATH = project_state_path("state.sqlite3")
|
||||
@@ -439,17 +384,6 @@ ANIDB_TITLES_CACHE = {
|
||||
}
|
||||
|
||||
|
||||
def migrate_legacy_state_storage():
|
||||
ensure_project_app_root()
|
||||
migrate_legacy_file(CONFIG_PATH, LEGACY_CONFIG_PATH, "config.json")
|
||||
migrate_legacy_file(QUEUE_PATH, LEGACY_QUEUE_PATH, "queue.json")
|
||||
migrate_legacy_file(STATE_DB_PATH, PROJECT_APP_ROOT / "queue.sqlite3", "queue.sqlite3")
|
||||
migrate_legacy_file(STATE_DB_PATH, LEGACY_QUEUE_DB_PATH, "queue.sqlite3")
|
||||
migrate_legacy_file(WATCHLIST_JSON_PATH, LEGACY_WATCHLIST_JSON_PATH, "watchlist.json")
|
||||
migrate_legacy_file(ANIDB_TITLES_PATH, LEGACY_ANIDB_TITLES_PATH, "anidb-anime-titles.xml.gz")
|
||||
migrate_legacy_dir(STAGING_ROOT, LEGACY_STAGING_ROOT, "staging")
|
||||
migrate_legacy_dir(THUMBNAIL_ROOT, LEGACY_THUMBNAIL_ROOT, "thumbnails")
|
||||
|
||||
def load_json(path, fallback):
|
||||
try:
|
||||
with path.open("r", encoding="utf-8") as handle:
|
||||
@@ -580,7 +514,7 @@ def _env_remote_path_roots():
|
||||
if not raw:
|
||||
return []
|
||||
roots = []
|
||||
for part in raw.split(os.pathsep):
|
||||
for part in re.split(rf"[{re.escape(os.pathsep)},]", raw):
|
||||
text = str(part or "").strip()
|
||||
if not text:
|
||||
continue
|
||||
@@ -660,20 +594,7 @@ def thumbnail_file_path(name):
|
||||
filename = Path(str(name or "")).name
|
||||
if not filename:
|
||||
return None
|
||||
project_path = THUMBNAIL_ROOT / filename
|
||||
if project_path.exists():
|
||||
return project_path
|
||||
legacy_path = LEGACY_THUMBNAIL_ROOT / filename
|
||||
if legacy_path.exists():
|
||||
THUMBNAIL_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
shutil.move(str(legacy_path), str(project_path))
|
||||
debug_log("thumbnail.cache.migrated", from_path=legacy_path, to_path=project_path)
|
||||
return project_path
|
||||
except OSError as exc:
|
||||
debug_log("thumbnail.cache.migrate_failed", from_path=legacy_path, to_path=project_path, error=exc)
|
||||
return legacy_path
|
||||
return project_path
|
||||
return THUMBNAIL_ROOT / filename
|
||||
|
||||
|
||||
def _discord_file_part(boundary, field_name, attachment_name, content_type, payload):
|
||||
@@ -1017,10 +938,6 @@ def cli_executable_exists(command):
|
||||
return bool(shutil.which(text) or (Path(text).exists() and os.access(text, os.X_OK)))
|
||||
|
||||
|
||||
def cli_executable_exists_any(*commands):
|
||||
return any(cli_executable_exists(command) for command in commands)
|
||||
|
||||
|
||||
def printable_command(command):
|
||||
return " ".join(sh_quote(part) for part in command)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user