mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
chore: merge main
This commit is contained in:
commit
3cdc36c78b
@ -13,6 +13,7 @@
|
||||
- Documentation ships with source
|
||||
- Open filepicker when generating system log
|
||||
- Developers page (and -d flag)
|
||||
- Redact API key in log table
|
||||
|
||||
## Changed
|
||||
- Reduce padding on keys button
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import threading
|
||||
import textwrap
|
||||
@ -43,6 +44,8 @@ from dzgui.util import cooldown, strings
|
||||
from dzgui.util._json import read_json, write_json
|
||||
from dzgui.util.open_links import open_workshop_page
|
||||
from dzgui.util.format import format_mods
|
||||
from dzgui.util.redact import redact_log
|
||||
|
||||
from dzgui.views.dialogs.filepicker import FilePicker
|
||||
from dzgui.views.dialogs.generic import GenericDialog
|
||||
|
||||
@ -437,7 +440,8 @@ class Controller:
|
||||
with open(log, "r") as f:
|
||||
lines = [line.split(strings.delimiter) for line in f.read().splitlines()]
|
||||
for record in lines:
|
||||
store.append(record)
|
||||
clean = redact_log(record)
|
||||
store.append(clean)
|
||||
self.open_page(NotebookPage.LOG)
|
||||
|
||||
def select_colorized(self) -> None:
|
||||
|
||||
@ -1,25 +1,80 @@
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository.Gtk import ListStore
|
||||
from gi.repository import GObject
|
||||
|
||||
from dzgui.const.enum import FilterMode
|
||||
|
||||
from dataclasses import dataclass, fields
|
||||
|
||||
@dataclass
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class ServerColumns:
|
||||
name: str
|
||||
_map: str
|
||||
perspective: str
|
||||
gametime: str
|
||||
players: int
|
||||
_max: int
|
||||
queue: int
|
||||
ip: str
|
||||
qport: int
|
||||
ping: int
|
||||
provider: str
|
||||
modded: bool
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class ModCols:
|
||||
name: str
|
||||
symlink: str
|
||||
directory: str
|
||||
size: float
|
||||
color: str
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class LogCols:
|
||||
timestamp: str
|
||||
flag: str
|
||||
traceback: str
|
||||
msg: str
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class ServerModCols:
|
||||
name: str
|
||||
uid: GObject.TYPE_INT64
|
||||
installed: str
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class MenuCols:
|
||||
name: str
|
||||
hidden: GObject.TYPE_PYOBJECT
|
||||
|
||||
|
||||
class ModelManager:
|
||||
"""
|
||||
Manages access to cached ListStore resources and
|
||||
performs filtering on behalf of TreeViews.
|
||||
|
||||
Not thread-safe.
|
||||
Methods are not thread-safe in themselves.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# NOTE: packed ListStores
|
||||
self.filter_cache = {}
|
||||
self.ping_cache = {}
|
||||
|
||||
self.mod_store = ListStore(str, str, str, float, str)
|
||||
self.map_store = ListStore(str)
|
||||
self.row_store = self.new_model_from_class(MenuCols)
|
||||
self.help_store = self.new_model_from_class(MenuCols)
|
||||
|
||||
# NOTE: stringwise (list) representation of the model
|
||||
self.mod_store = self.new_model_from_class(ModCols)
|
||||
self.log_store = self.new_model_from_class(LogCols)
|
||||
self.modlist_store = self.new_model_from_class(ServerModCols)
|
||||
|
||||
#self.mod_store = ListStore(str, str, str, float, str)
|
||||
self.control_model = None
|
||||
self.filtered = None
|
||||
self.success = True
|
||||
@ -29,6 +84,10 @@ class ModelManager:
|
||||
cls.instance = super(ModelManager, cls).__new__(cls)
|
||||
return cls.instance
|
||||
|
||||
def new_model_from_class(self, cls: type) -> ListStore:
|
||||
store = ListStore(*[ftype for field, ftype in cls.__annotations__.items()])
|
||||
return store
|
||||
|
||||
def get_mod_store(self) -> ListStore:
|
||||
return self.mod_store
|
||||
|
||||
@ -200,9 +259,8 @@ class ModelManager:
|
||||
self.filter_cache[filters] = (model, rows)
|
||||
|
||||
def new_model(self) -> ListStore:
|
||||
return ListStore(
|
||||
str, str, str, str, int, int, int, str, int, int, str, bool
|
||||
)
|
||||
store = self.new_model_from_class(ServerColumns)
|
||||
return store
|
||||
|
||||
def resync_model(self, addr: str, qport: int) -> None:
|
||||
"""
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
- Documentation ships with source
|
||||
- Open filepicker when generating system log
|
||||
- Developers page (and -d flag)
|
||||
- Redact API key in log table
|
||||
|
||||
## Changed
|
||||
- Reduce padding on keys button
|
||||
|
||||
@ -11,6 +11,7 @@ def migrate_legacy_conf(config: Path) -> None:
|
||||
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
||||
if old_conf.is_file():
|
||||
j = rc2json(old_conf)
|
||||
# FIXME: superfluous use of Path()
|
||||
Path(config).parent.mkdir(parents=True, exist_ok=True)
|
||||
config.write_text(j)
|
||||
else:
|
||||
|
||||
@ -4,3 +4,17 @@ def redact(text: str) -> str:
|
||||
r = r"(/home/)([^/])*"
|
||||
cleaned = re.sub(r, r"/home/REDACTED", text)
|
||||
return cleaned
|
||||
|
||||
def redact_log(record: list) -> list[str]:
|
||||
"""
|
||||
requests library includes Steam API key in URL params
|
||||
"""
|
||||
clean = []
|
||||
for item in record:
|
||||
if "&key=" in item:
|
||||
pat = r"(.*&key=)(\S+)(.*)"
|
||||
scrubbed = re.sub(pat, r"\1REDACTED\3", item)
|
||||
clean.append(scrubbed)
|
||||
else:
|
||||
clean.append(item)
|
||||
return clean
|
||||
|
||||
@ -487,8 +487,11 @@ class Options(Gtk.Box):
|
||||
|
||||
|
||||
active_combo = 1 if config["branch"] == BETA_REPO else 0
|
||||
|
||||
self.controller.suppress_signal(self, self.branch_combo, "_on_branch_changed", True)
|
||||
self.branch_combo.set_active(active_combo)
|
||||
self.branch_combo.set_sensitive(prefs.allow_updates)
|
||||
self.controller.suppress_signal(self, self.branch_combo, "_on_branch_changed", False)
|
||||
|
||||
if prefs.allow_updates is True:
|
||||
msg = strings.options.self_update
|
||||
|
||||
Loading…
Reference in New Issue
Block a user