mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 23:22:44 +01:00
chore: clear typehinting errors
This commit is contained in:
1 parent
fe0a6711f0
commit
866c88fbb0
14 files changed
+65
-43
No files matched your search
+2
-2
@@ -33,8 +33,8 @@ def map_id_to_record(key: str, uid: int) -> Optional["Record"]:
|
|||||||
try:
|
try:
|
||||||
record = get_attributes(key, uid)
|
record = get_attributes(key, uid)
|
||||||
ip = record["ip"]
|
ip = record["ip"]
|
||||||
port = record["port"]
|
port = int(record["port"])
|
||||||
qport = record["portQuery"]
|
qport = int(record["portQuery"])
|
||||||
return Record(ip, port, qport)
|
return Record(ip, port, qport)
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
+3
-1
@@ -49,7 +49,7 @@ def get_local_mods(workshop_path: Path) -> list[Path]:
|
|||||||
return mods
|
return mods
|
||||||
|
|
||||||
|
|
||||||
def parse_meta(file: Path) -> ModMeta:
|
def parse_meta(file: Path) -> ModMeta | None:
|
||||||
mod = file / "meta.cpp"
|
mod = file / "meta.cpp"
|
||||||
if mod.exists() is False:
|
if mod.exists() is False:
|
||||||
return None
|
return None
|
||||||
@@ -135,6 +135,8 @@ def remove_stale_signatures(config: Path, versions: Path) -> None:
|
|||||||
def find_stale_mods(config: Path) -> list[int]:
|
def find_stale_mods(config: Path) -> list[int]:
|
||||||
def push_record(rec: str) -> list:
|
def push_record(rec: str) -> list:
|
||||||
record = fqip_to_record(rec)
|
record = fqip_to_record(rec)
|
||||||
|
if record is None:
|
||||||
|
return []
|
||||||
try:
|
try:
|
||||||
mods = get_rules(record)
|
mods = get_rules(record)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
+12
-11
@@ -33,35 +33,35 @@ class VersionMatch(Enum):
|
|||||||
SAME_VERSION = 3
|
SAME_VERSION = 3
|
||||||
|
|
||||||
|
|
||||||
class u8:
|
class u8(int):
|
||||||
fmt = "B"
|
fmt = "B"
|
||||||
|
|
||||||
|
|
||||||
class u16:
|
class u16(int):
|
||||||
fmt = "H"
|
fmt = "H"
|
||||||
|
|
||||||
|
|
||||||
class u32:
|
class u32(int):
|
||||||
fmt = "L"
|
fmt = "L"
|
||||||
|
|
||||||
|
|
||||||
class u64:
|
class u64(int):
|
||||||
fmt = "Q"
|
fmt = "Q"
|
||||||
|
|
||||||
|
|
||||||
class i8:
|
class i8(int):
|
||||||
fmt = "b"
|
fmt = "b"
|
||||||
|
|
||||||
|
|
||||||
class i16:
|
class i16(int):
|
||||||
fmt = "h"
|
fmt = "h"
|
||||||
|
|
||||||
|
|
||||||
class i32:
|
class i32(int):
|
||||||
fmt = "l"
|
fmt = "l"
|
||||||
|
|
||||||
|
|
||||||
class i64:
|
class i64(int):
|
||||||
fmt = "q"
|
fmt = "q"
|
||||||
|
|
||||||
|
|
||||||
@@ -330,6 +330,7 @@ def get_version(file: Path) -> FileVersion:
|
|||||||
magic = hex(struct.unpack("<H", (blob[0:2]))[0])
|
magic = hex(struct.unpack("<H", (blob[0:2]))[0])
|
||||||
f.seek(pos)
|
f.seek(pos)
|
||||||
|
|
||||||
|
OBJW: OPTIONAL_HDR_WIN_X86 | OPTIONAL_HDR_WIN_X64
|
||||||
if magic == PE32_x86:
|
if magic == PE32_x86:
|
||||||
OPTIONAL_HDR_X86.unpack(f)
|
OPTIONAL_HDR_X86.unpack(f)
|
||||||
OBJW = OPTIONAL_HDR_WIN_X86.unpack(f)
|
OBJW = OPTIONAL_HDR_WIN_X86.unpack(f)
|
||||||
@@ -363,7 +364,7 @@ def get_version(file: Path) -> FileVersion:
|
|||||||
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
|
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
|
||||||
total = table.number_of_name_entries + table.number_of_id_entries
|
total = table.number_of_name_entries + table.number_of_id_entries
|
||||||
|
|
||||||
for entry in range(total):
|
for _iter in range(total):
|
||||||
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
|
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
|
||||||
if entry.name_or_id == VERSION_RESOURCE:
|
if entry.name_or_id == VERSION_RESOURCE:
|
||||||
while entry.data_or_subdir & (1 << 31):
|
while entry.data_or_subdir & (1 << 31):
|
||||||
@@ -371,7 +372,7 @@ def get_version(file: Path) -> FileVersion:
|
|||||||
seek_to_hex(hex(offset + shift), f)
|
seek_to_hex(hex(offset + shift), f)
|
||||||
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
|
table = RESOURCE_DIRECTORY_TABLE.unpack(f)
|
||||||
total = table.number_of_name_entries + table.number_of_id_entries
|
total = table.number_of_name_entries + table.number_of_id_entries
|
||||||
for entry in range(total):
|
for _iter in range(total):
|
||||||
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
|
entry = RESOURCE_DIRECTORY_ENTRY.unpack(f)
|
||||||
break
|
break
|
||||||
if entry.name_or_id > VERSION_RESOURCE:
|
if entry.name_or_id > VERSION_RESOURCE:
|
||||||
@@ -383,7 +384,7 @@ def get_version(file: Path) -> FileVersion:
|
|||||||
offset = data.data_rva - hdr.virtual_address + hdr.pointer_to_raw_data
|
offset = data.data_rva - hdr.virtual_address + hdr.pointer_to_raw_data
|
||||||
seek_to_hex(hex(offset), f)
|
seek_to_hex(hex(offset), f)
|
||||||
|
|
||||||
hdr = VS_VERSION_INFO_HDR.unpack(f)
|
VS_VERSION_INFO_HDR.unpack(f)
|
||||||
# https://learn.microsoft.com/en-us/windows/win32/menurc/vs-versioninfo
|
# https://learn.microsoft.com/en-us/windows/win32/menurc/vs-versioninfo
|
||||||
byte_len = len(VS_VERSION_INFO_ID.encode("utf-16le"))
|
byte_len = len(VS_VERSION_INFO_ID.encode("utf-16le"))
|
||||||
label = f.read(byte_len).decode("utf-16le")
|
label = f.read(byte_len).decode("utf-16le")
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ class A2SInfo:
|
|||||||
def get_info(self) -> a2s.SourceInfo | None:
|
def get_info(self) -> a2s.SourceInfo | None:
|
||||||
return self.info
|
return self.info
|
||||||
|
|
||||||
def as_row(self) -> dict[str, Any] | None:
|
def as_row(self) -> dict[str, Any]:
|
||||||
if self.info is None:
|
if self.info is None:
|
||||||
return None
|
raise AttributeError("No record to convert")
|
||||||
ip = self.record.ip
|
ip = self.record.ip
|
||||||
qport = self.record.qport
|
qport = self.record.qport
|
||||||
return source_info_to_dict(ip, qport, self.info)
|
return source_info_to_dict(ip, qport, self.info)
|
||||||
@@ -239,7 +239,7 @@ def parse_json(json: list) -> list:
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any]:
|
def source_info_to_dict(ip: str, qport: int, info: "SourceInfo") -> dict[str, Any] | None:
|
||||||
try:
|
try:
|
||||||
name = info.server_name
|
name = info.server_name
|
||||||
mapname = info.map_name
|
mapname = info.map_name
|
||||||
|
|||||||
+9
-9
@@ -28,9 +28,9 @@ def get_local_signatures(version_file: Path) -> dict[str, int]:
|
|||||||
hashes: dict[str, int] = {}
|
hashes: dict[str, int] = {}
|
||||||
lines = version_file.read_text().splitlines()
|
lines = version_file.read_text().splitlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.split(",")
|
data = line.split(",")
|
||||||
_id = line[0]
|
_id = data[0]
|
||||||
_hash = int(line[1])
|
_hash = int(data[1])
|
||||||
hashes[_id] = _hash
|
hashes[_id] = _hash
|
||||||
return hashes
|
return hashes
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ def get_needs_update(
|
|||||||
version_file: Path, remote_hashes: list[tuple[str, str, int, int]]
|
version_file: Path, remote_hashes: list[tuple[str, str, int, int]]
|
||||||
) -> list[tuple[str, str, int, int]]:
|
) -> list[tuple[str, str, int, int]]:
|
||||||
local_hashes = get_local_signatures(version_file)
|
local_hashes = get_local_signatures(version_file)
|
||||||
needs_update: list[tuple[str, str]] = []
|
needs_update: list[tuple[str, str, int, int]] = []
|
||||||
for title, _id, _hash, size in remote_hashes:
|
for title, _id, _hash, size in remote_hashes:
|
||||||
if _id not in local_hashes:
|
if _id not in local_hashes:
|
||||||
needs_update.append((title, _id, _hash, size))
|
needs_update.append((title, _id, _hash, size))
|
||||||
@@ -64,7 +64,7 @@ def get_remote_signatures(mods: list[str]) -> list[tuple[str, str, int, int]]:
|
|||||||
"""
|
"""
|
||||||
Attempts to continue connecting even if signatures are empty
|
Attempts to continue connecting even if signatures are empty
|
||||||
"""
|
"""
|
||||||
payload: dict[str, str] = {}
|
payload: dict[str, str | int] = {}
|
||||||
payload["itemcount"] = len(mods)
|
payload["itemcount"] = len(mods)
|
||||||
for i, mod in enumerate(mods):
|
for i, mod in enumerate(mods):
|
||||||
payload[f"publishedfileids[{i}]"] = mod
|
payload[f"publishedfileids[{i}]"] = mod
|
||||||
@@ -76,13 +76,13 @@ def get_remote_signatures(mods: list[str]) -> list[tuple[str, str, int, int]]:
|
|||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
hashes: list[tuple[str, int, int]] = []
|
hashes: list[tuple[str, str, int, int]] = []
|
||||||
j = r.json()
|
j = r.json()
|
||||||
rows = j["response"]["publishedfiledetails"]
|
rows = j["response"]["publishedfiledetails"]
|
||||||
for row in rows:
|
for row in rows:
|
||||||
title = row["title"]
|
title = str(row["title"])
|
||||||
_id = row["publishedfileid"]
|
_id = str(row["publishedfileid"])
|
||||||
time = row["time_updated"]
|
time = int(row["time_updated"])
|
||||||
size = int(row["file_size"])
|
size = int(row["file_size"])
|
||||||
hashes.append((title, _id, time, size))
|
hashes.append((title, _id, time, size))
|
||||||
return hashes
|
return hashes
|
||||||
|
|||||||
@@ -38,8 +38,15 @@ def rc2json(file: Path) -> str:
|
|||||||
keys: dict[str, Any] = {}
|
keys: dict[str, Any] = {}
|
||||||
ips: list[str] = []
|
ips: list[str] = []
|
||||||
|
|
||||||
toggles = ["auto_install", "fullscreen"]
|
toggles = ["fullscreen"]
|
||||||
deprecated = ["staging_dir", "src_path", "steam_path", "debug", "branch"]
|
deprecated = [
|
||||||
|
"staging_dir",
|
||||||
|
"src_path",
|
||||||
|
"steam_path",
|
||||||
|
"debug",
|
||||||
|
"branch",
|
||||||
|
"auto_install",
|
||||||
|
]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
tok = lex.get_token()
|
tok = lex.get_token()
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ def lookup(path: Path, enum: Preferences) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
def get_config(path: Path) -> dict:
|
def get_config(path: Path) -> dict:
|
||||||
# TODO: is this being called twice?
|
# TODO: is this being called multiple times?
|
||||||
try:
|
try:
|
||||||
json = read_json(path)
|
json = read_json(path)
|
||||||
|
return json
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
return json
|
|
||||||
|
|
||||||
|
|
||||||
def get_favorites(path: Path) -> list[str]:
|
def get_favorites(path: Path) -> list[str]:
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ def is_flatpak_steam_running() -> bool:
|
|||||||
if has_cmd(FLATPAK_CMD) is False:
|
if has_cmd(FLATPAK_CMD) is False:
|
||||||
return False
|
return False
|
||||||
proc = subprocess.check_output([FLATPAK_CMD, "ps"], text=True)
|
proc = subprocess.check_output([FLATPAK_CMD, "ps"], text=True)
|
||||||
lines = proc.stdout.splitlines()
|
lines = proc.splitlines()
|
||||||
if FLATPAK_APPID in lines:
|
if FLATPAK_APPID in lines:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class ProxyModelManager:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, filter_man: "FilterManager") -> None:
|
def __init__(self, filter_man: "FilterManager") -> None:
|
||||||
self.filter_cache = {}
|
self.filter_cache: dict[tuple[str], tuple["FastInsertListStore", list[Any]]] = (
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
self.proxy_model: "FastInsertListStore" = None
|
self.proxy_model: "FastInsertListStore" = None
|
||||||
self.filter_man = filter_man
|
self.filter_man = filter_man
|
||||||
@@ -55,16 +57,18 @@ class ProxyModelManager:
|
|||||||
self.proxy_model[treeiter][4] = playercount.players
|
self.proxy_model[treeiter][4] = playercount.players
|
||||||
self.proxy_model[treeiter][6] = playercount.queue
|
self.proxy_model[treeiter][6] = playercount.queue
|
||||||
|
|
||||||
|
# FIXME: typehint -> tuple
|
||||||
def append_row_to_history(
|
def append_row_to_history(
|
||||||
self, history: list[str, str, str, str, int, int, int, str, int, int, str, bool]
|
self, history: list[str, str, str, str, int, int, int, str, int, int, str, bool]
|
||||||
) -> None:
|
) -> None:
|
||||||
addr = history[7]
|
addr = history[7]
|
||||||
qport = history[8]
|
qport = history[8]
|
||||||
|
|
||||||
|
if self.control_model is None:
|
||||||
|
raise AttributeError("Trying to append row to empty model")
|
||||||
found = False
|
found = False
|
||||||
for i, row in enumerate(self.control_model):
|
for i, row in enumerate(self.control_model):
|
||||||
if addr == row[7] and qport == row[8]:
|
if addr == row[7] and qport == row[8]:
|
||||||
print("record exists in history")
|
|
||||||
item = self.control_model.pop(i)
|
item = self.control_model.pop(i)
|
||||||
self.control_model.append(item)
|
self.control_model.append(item)
|
||||||
found = True
|
found = True
|
||||||
|
|||||||
@@ -268,8 +268,10 @@ class ServerModelManager:
|
|||||||
|
|
||||||
def _parse_single_record(self, response: "A2SInfo", delete: bool = False) -> None:
|
def _parse_single_record(self, response: "A2SInfo", delete: bool = False) -> None:
|
||||||
self.preserve_on_fail = True
|
self.preserve_on_fail = True
|
||||||
row = response.as_row()
|
try:
|
||||||
if row is None:
|
row = response.as_row()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(e)
|
||||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_on_failure))
|
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_on_failure))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -301,7 +303,7 @@ class ServerModelManager:
|
|||||||
return
|
return
|
||||||
config_man.add_saved_server(fqip)
|
config_man.add_saved_server(fqip)
|
||||||
# 2026-05-04
|
# 2026-05-04
|
||||||
# TODO: this is valid if saved servers tab is already open,
|
# FIXME: this is valid if saved servers tab is already open,
|
||||||
# but not if app was just booted
|
# but not if app was just booted
|
||||||
if proxy_man.has_control_model() is False:
|
if proxy_man.has_control_model() is False:
|
||||||
self._get_proxy_man().push(records)
|
self._get_proxy_man().push(records)
|
||||||
@@ -393,7 +395,7 @@ class ServerModelManager:
|
|||||||
# TODO: distinguish signals, e.g. "servers_failed_to_load", "servers_loaded_empty"
|
# TODO: distinguish signals, e.g. "servers_failed_to_load", "servers_loaded_empty"
|
||||||
# customize statusbar and dialog accordingly
|
# customize statusbar and dialog accordingly
|
||||||
self.emitter.emit("servers_loaded", self.enum)
|
self.emitter.emit("servers_loaded", self.enum)
|
||||||
# TODO: destroy wait dialog first
|
# FIXME: destroy wait dialog first
|
||||||
# see threadman.set_cleanup_func(_, destroy_first=True)
|
# see threadman.set_cleanup_func(_, destroy_first=True)
|
||||||
if show_dialog:
|
if show_dialog:
|
||||||
dialog = ExceptionDialog(self.controller, api_warn_msg)
|
dialog = ExceptionDialog(self.controller, api_warn_msg)
|
||||||
|
|||||||
+4
-3
@@ -13,9 +13,10 @@ gi.require_version("Gtk", "3.0")
|
|||||||
from gi.repository import Gtk # noqa E402
|
from gi.repository import Gtk # noqa E402
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from queue import Queue
|
||||||
from dzgui.const.enum import ServerTab
|
from dzgui.const.enum import ServerTab
|
||||||
from dzgui.controllers.mc import Controller
|
from dzgui.controllers.mc import Controller
|
||||||
from queue import Queue
|
from dzgui.util.ip import Coords
|
||||||
|
|
||||||
logger = logging.getLogger(APP_NAME)
|
logger = logging.getLogger(APP_NAME)
|
||||||
|
|
||||||
@@ -74,13 +75,13 @@ class CalcDist:
|
|||||||
dist = self.compare(self.ip)
|
dist = self.compare(self.ip)
|
||||||
self.result_queue.put([self.addr, dist, self.enum])
|
self.result_queue.put([self.addr, dist, self.enum])
|
||||||
|
|
||||||
def compare(self, remote: str) -> int | None:
|
def compare(self, remote_ip: str) -> Haversine | None:
|
||||||
prefs = self.controller.get_prefs()
|
prefs = self.controller.get_prefs()
|
||||||
local = prefs.coords
|
local = prefs.coords
|
||||||
if local is None:
|
if local is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
remote = get_coords(prefs.paths.ips, remote)
|
remote = get_coords(prefs.paths.ips, remote_ip)
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -130,7 +130,7 @@ def is_valid_port(port: str) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
@deprecated("use ips.csv")
|
@deprecated("use ips.csv")
|
||||||
def get_local_coords(ip: str):
|
def get_local_coords(ip: str) -> str:
|
||||||
url = COORDS_API + "/" + ip
|
url = COORDS_API + "/" + ip
|
||||||
# local res=$(curl -Ls "$url" | jq -r '"\(.lat)\n\(.lon)"')
|
# local res=$(curl -Ls "$url" | jq -r '"\(.lat)\n\(.lon)"')
|
||||||
return url
|
return url
|
||||||
@@ -12,11 +12,15 @@ from gi.repository import Gtk, Gdk # noqa E402
|
|||||||
logger = logging.getLogger(APP_NAME)
|
logger = logging.getLogger(APP_NAME)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from dzgui.const.enum import NotebookPage
|
||||||
|
from dzgui.controller.mc import Controller
|
||||||
from dzgui.controllers.emitter import Emitter
|
from dzgui.controllers.emitter import Emitter
|
||||||
|
|
||||||
|
|
||||||
class ContextualButton(Gtk.Button):
|
class ContextualButton(Gtk.Button):
|
||||||
def __init__(self, label, opens, tooltip, context):
|
def __init__(
|
||||||
|
self, label: str, opens: "NotebookPage", tooltip: str, context: ButtonType
|
||||||
|
) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
label=label,
|
label=label,
|
||||||
tooltip_text=tooltip,
|
tooltip_text=tooltip,
|
||||||
@@ -28,7 +32,7 @@ class ContextualButton(Gtk.Button):
|
|||||||
|
|
||||||
|
|
||||||
class ButtonBox(Gtk.Box):
|
class ButtonBox(Gtk.Box):
|
||||||
def __init__(self, controller) -> None:
|
def __init__(self, controller: "Controller") -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
spacing=6,
|
spacing=6,
|
||||||
margin_top=0,
|
margin_top=0,
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class ServerModTreeView(ContextMixin, TreeView): # type: ignore
|
|||||||
path = self.get_focused_row_path()
|
path = self.get_focused_row_path()
|
||||||
model = self.get_model()
|
model = self.get_model()
|
||||||
tree_iter = model.get_iter(path)
|
tree_iter = model.get_iter(path)
|
||||||
|
# FIXME: https://docs.gtk.org/gtk3/method.TreeModel.get.html
|
||||||
mod = model.get(tree_iter, 1)[0]
|
mod = model.get(tree_iter, 1)[0]
|
||||||
return str(mod)
|
return str(mod)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user