mirror of
https://github.com/aclist/dztui.git
synced 2026-11-11 20:40:38 +01:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5374d1f1a | ||
|
|
dcc4cb494b | ||
|
|
ff1e150eb1 | ||
|
|
c7ef91f02e | ||
|
|
95bc05eab5 | ||
|
|
52c126ff8c | ||
|
|
3677b01fdc | ||
|
|
4f6223f90b | ||
|
|
441066a1a0 | ||
|
|
fa1ac8fa31 |
No files matched your search
+7
-5
@@ -2,9 +2,10 @@ import hashlib
|
||||
import logging
|
||||
import re
|
||||
|
||||
from concurrent.futures import wait
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from concurrent.futures import ThreadPoolExecutor, wait
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from dzgui.api.steam import get_app_path
|
||||
from dzgui.api.servers import get_rules, fqip_to_record
|
||||
@@ -17,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)
|
||||
|
||||
@@ -116,10 +116,12 @@ def remove_stale_signatures(
|
||||
config: Path, versions: Path, ids: list[int] | None = None
|
||||
) -> None:
|
||||
if versions.is_file() is False:
|
||||
logger.warning("Creating new version signatures file")
|
||||
logger.debug("Creating new version signatures file")
|
||||
versions.touch()
|
||||
return
|
||||
|
||||
clean_legacy_versions_file(versions)
|
||||
|
||||
path = lookup(config, Preferences.DEFAULT)
|
||||
steam_path = Path(path)
|
||||
if ids is None:
|
||||
|
||||
+1
-1
@@ -18,8 +18,8 @@ from dzgui.config.query import lookup
|
||||
from dzgui.config.userprefs import UserPrefs
|
||||
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||
from dzgui.init.migrate import (
|
||||
has_new_config,
|
||||
copy_state_files,
|
||||
has_new_config,
|
||||
migrate_cols_file,
|
||||
)
|
||||
from dzgui.init.prereqs import has_flatpak_client, has_steam_client
|
||||
|
||||
@@ -6,7 +6,8 @@ if TYPE_CHECKING:
|
||||
from dzgui.util.ip import Coords
|
||||
|
||||
|
||||
# NOTE: mutable dataclass, 'use_miles' key changes on demand
|
||||
# NOTE: mutable dataclass: 'use_miles' key changes on demand
|
||||
# 'frozen' cannot be True
|
||||
@dataclass(slots=True)
|
||||
class UserPrefs:
|
||||
is_steam_deck: bool
|
||||
|
||||
+22
-1
@@ -1,12 +1,21 @@
|
||||
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 +79,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 as e:
|
||||
logger.warning(e)
|
||||
@@ -46,6 +46,15 @@ class ConfigManager:
|
||||
ips.append(record)
|
||||
self.update_config(Preferences.IP_LIST, ips)
|
||||
|
||||
def remove_from_history_file(self, fqip: str) -> None:
|
||||
try:
|
||||
history = self.prefs.paths.history
|
||||
ips = [line.rstrip() for line in history.read_text().splitlines()]
|
||||
ips.remove(fqip)
|
||||
history.write_text("\n".join(ips))
|
||||
except Exception as e:
|
||||
logger.critical(e)
|
||||
|
||||
def update_history_file(self, fqip: str) -> None:
|
||||
try:
|
||||
with open(self.prefs.paths.history, "r") as f:
|
||||
|
||||
@@ -281,6 +281,10 @@ class ServerModelManager:
|
||||
def remove_from_history(self, record: Servers.Record) -> None:
|
||||
proxy_man = self._get_proxy_man()
|
||||
proxy_man.remove_row_from_control(record)
|
||||
|
||||
fqip = Servers.record_to_fqip(record)
|
||||
config_man = self.controller.get_config_man()
|
||||
config_man.remove_from_history_file(fqip)
|
||||
self.update_history()
|
||||
|
||||
@call_on_thread(dialog.querying)
|
||||
|
||||
@@ -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