feat: use functools.wraps

This commit is contained in:
aclist committed 2026-02-13 02:43:08 +09:00
1 parent c786ba2c9a
commit 82c585a195
2 files changed
+19 -13

No files matched your search

+3
View File
@@ -22,6 +22,7 @@ from typing import Any
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@dataclass @dataclass
class ModMeta: class ModMeta:
protocol: str protocol: str
@@ -41,6 +42,7 @@ def get_local_mod_path(steam_path: Path) -> Path:
workshop_path = p / WORKSHOP_PATH workshop_path = p / WORKSHOP_PATH
return workshop_path return workshop_path
def get_local_mods(workshop_path: Path) -> list[Path]: 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
@@ -148,6 +150,7 @@ def find_stale_mods(config: Path) -> list[int]:
steam = lookup(config, Preferences.DEFAULT) steam = lookup(config, Preferences.DEFAULT)
steam_path = Path(steam) steam_path = Path(steam)
# TODO: use concurrency
local = get_local_mod_ids(steam_path) local = get_local_mod_ids(steam_path)
servers = lookup(config, Preferences.IP_LIST) servers = lookup(config, Preferences.IP_LIST)
+16 -13
View File
@@ -7,6 +7,7 @@ from warnings import deprecated
from concurrent.futures import wait from concurrent.futures import wait
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from functools import wraps
from pathlib import Path from pathlib import Path
from typing import Any, Callable, TYPE_CHECKING from typing import Any, Callable, TYPE_CHECKING
@@ -101,15 +102,17 @@ class Controller(GObject.GObject):
def get_emitter(self) -> Emitter: def get_emitter(self) -> Emitter:
return self.emitter return self.emitter
def call_on_thread(func: Callable) -> Callable: def call_on_thread(dialog_str: str) -> Callable:
def wrapper(*args, **kwargs): def decorator(func: Callable) -> Callable:
self = args[0] @wraps(func)
# TODO: get dialog string from own attribute def wrapper(*args, **kwargs):
self.wait_dialog = WaitDialog(self, strings.dialog.filtering) self = args[0]
self.wait_dialog.show_all() self.wait_dialog = WaitDialog(self, dialog_str)
thread = threading.Thread(target=func, args=args) self.wait_dialog.show_all()
thread.start() thread = threading.Thread(target=func, args=args)
return wrapper thread.start()
return wrapper
return decorator
def register_widget(self, attr: str, widget: Gtk.Widget) -> None: def register_widget(self, attr: str, widget: Gtk.Widget) -> None:
try: try:
@@ -693,7 +696,7 @@ class Controller(GObject.GObject):
treeview.set_loaded(True) treeview.set_loaded(True)
GLib.idle_add(self.cleanup) GLib.idle_add(self.cleanup)
@call_on_thread @call_on_thread(strings.dialog.working)
def highlight_stale(self) -> None: def highlight_stale(self) -> None:
self.colorize_mods() self.colorize_mods()
@@ -746,7 +749,7 @@ class Controller(GObject.GObject):
dialog = ExceptionDialog(self, strings.api_error) dialog = ExceptionDialog(self, strings.api_error)
dialog.run() dialog.run()
@call_on_thread @call_on_thread(strings.dialog.working)
# FIXME: entire process is behind thread, including destroy_on_idle() # FIXME: entire process is behind thread, including destroy_on_idle()
def update_api_key(self, text: str, key: Preferences) -> None: def update_api_key(self, text: str, key: Preferences) -> None:
self.test_api_response(text, key) self.test_api_response(text, key)
@@ -794,11 +797,11 @@ class Controller(GObject.GObject):
def get_statusbar(self) -> None: def get_statusbar(self) -> None:
return self.mediator.statusbar return self.mediator.statusbar
@call_on_thread @call_on_thread(strings.dialog.fetching)
def run_query_func(self, func: Callable) -> None: def run_query_func(self, func: Callable) -> None:
func() func()
@call_on_thread @call_on_thread(strings.dialog.filtering)
def filter_threaded(self, mode: FilterMode, label: str) -> None: def filter_threaded(self, mode: FilterMode, label: str) -> None:
tv = self.get_active_treeview() tv = self.get_active_treeview()
tv.filter_man.filter(mode, label) tv.filter_man.filter(mode, label)