fix: use list comprehension

This commit is contained in:
aclist committed 2026-06-22 17:01:45 +09:00
1 parent 27136a0906
commit e41bef7b00
1 file changed
+17 -7
+17 -7
View File
@@ -49,6 +49,7 @@ def get_local_mods(workshop_path: Path) -> list[Path]:
mods = [file for file in workshop_path.iterdir() if file.is_dir()] mods = [file for file in workshop_path.iterdir() if file.is_dir()]
return mods return mods
def is_mission(path: Path) -> bool: def is_mission(path: Path) -> bool:
# TODO: parse integrity of other files # TODO: parse integrity of other files
parent = path.parent.name parent = path.parent.name
@@ -57,9 +58,10 @@ def is_mission(path: Path) -> bool:
file = path / "init.c" file = path / "init.c"
return file.exists() return file.exists()
def tokenize(mod: Path) -> dict[str, Any] | None: def tokenize(mod: Path) -> dict[str, Any] | None:
file = mod.joinpath("meta.cpp") file = mod.joinpath("meta.cpp")
delimiter=r"\s*=\s*" delimiter = r"\s*=\s*"
modmeta = {} modmeta = {}
try: try:
with open(file, "r", encoding="utf-8") as f: with open(file, "r", encoding="utf-8") as f:
@@ -76,6 +78,7 @@ def tokenize(mod: Path) -> dict[str, Any] | None:
logger.critical(e) logger.critical(e)
return None return None
def get_mod_size(path: Path) -> float: def get_mod_size(path: Path) -> float:
s = 0 s = 0
for f in path.rglob("*"): for f in path.rglob("*"):
@@ -123,20 +126,27 @@ def _hash(uid: str, use_custom: bool = False) -> str:
return prefix + md5.hexdigest()[:8] return prefix + md5.hexdigest()[:8]
def remove_stale_signatures(config: Path, versions: Path) -> None: def remove_stale_signatures(
config: Path, versions: Path, ids: list[int] | None = None
) -> None:
if versions.is_file() is False: if versions.is_file() is False:
logger.warning("Creating new version signatures file") logger.warning("Creating new version signatures file")
versions.touch() versions.touch()
return return
path = lookup(config, Preferences.DEFAULT) path = lookup(config, Preferences.DEFAULT)
steam_path = Path(path) steam_path = Path(path)
ids = get_local_mod_ids(steam_path) if ids is None:
local_ids = get_local_mod_ids(steam_path)
with open(versions, "r") as f: with open(versions, "r") as f:
lines = f.readlines() lines = f.readlines()
for line in lines:
uid = int(line.split(",")[0]) if ids is None:
if uid not in ids: lines = [line for line in lines if int(line.split(",")[0]) in local_ids]
lines.remove(line) else:
lines = [line for line in lines if int(line.split(",")[0]) not in ids]
with open(versions, "w") as f: with open(versions, "w") as f:
for line in lines: for line in lines:
f.write(line) f.write(line)