mirror of
https://github.com/aclist/dztui.git
synced 2026-11-09 19:40:38 +01:00
fix: strip invalid values from versions file
This commit is contained in:
1 parent
441066a1a0
commit
4f6223f90b
3 files changed
+45
-3
No files matched your search
+3
-2
@@ -18,8 +18,7 @@ from dzgui.const.constants import (
|
||||
|
||||
from dzgui.config.query import lookup
|
||||
from dzgui.const.enum import Preferences
|
||||
|
||||
from typing import Any
|
||||
from dzgui.init.migrate import clean_legacy_versions_file
|
||||
|
||||
logger = logging.getLogger(APP_NAME)
|
||||
|
||||
@@ -133,6 +132,8 @@ def remove_stale_signatures(
|
||||
versions.touch()
|
||||
return
|
||||
|
||||
clean_legacy_versions_file(versions)
|
||||
|
||||
path = lookup(config, Preferences.DEFAULT)
|
||||
steam_path = Path(path)
|
||||
if ids is None:
|
||||
|
||||
+17
-1
@@ -1,12 +1,16 @@
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from dzgui.const.constants import LEGACY_CONFIG_PATH, LEGACY_COLS_PATH, LEGACY_IPS_PATH
|
||||
from dzgui.const.constants import APP_NAME, LEGACY_CONFIG_PATH, LEGACY_COLS_PATH, LEGACY_IPS_PATH
|
||||
from dzgui.config.convert import rc2json
|
||||
from dzgui.util._json import read_json, write_json
|
||||
|
||||
logger = logging.getLogger(APP_NAME)
|
||||
|
||||
|
||||
def migrate_legacy_conf(config: Path) -> Any:
|
||||
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
||||
@@ -70,3 +74,15 @@ def copy_ipdb(ips_path: Path) -> None:
|
||||
return
|
||||
# TODO: ensure that month file is copied
|
||||
shutil.copy(legacy, ips_path)
|
||||
|
||||
|
||||
def clean_legacy_versions_file(versions: Path) -> None:
|
||||
# NOTE: handling for #523
|
||||
try:
|
||||
pat = r"^(\d+),(\d+)$"
|
||||
lines = versions.read_text().splitlines()
|
||||
clean = [line for line in lines if re.match(pat, line)]
|
||||
concat = "\n".join(clean)
|
||||
versions.write_text(concat)
|
||||
except Exception:
|
||||
logger.warning(e)
|
||||
@@ -0,0 +1,25 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dzgui.init.migrate import clean_legacy_versions_file
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_null_signature_stripping(tmp_path: "Path") -> None:
|
||||
tmp = tmp_path.joinpath("dzg.versions")
|
||||
lines = [
|
||||
"1111,2222",
|
||||
"3333,4444",
|
||||
"5555,null",
|
||||
"foo",
|
||||
",4555",
|
||||
"1111",
|
||||
" ",
|
||||
",,,",
|
||||
"-1",
|
||||
]
|
||||
expect = ["1111,2222", "3333,4444"]
|
||||
tmp.write_text("\n".join(lines))
|
||||
clean_legacy_versions_file(tmp)
|
||||
assert expect == tmp.read_text().splitlines()
|
||||
Reference in new issue
Block a user