Compare commits

..
Author SHA1 Message Date
aclist cdfe59ce38 chore: revert change 2026-11-22 13:52:37 +09:00
aclist 3f74e71a10 feat: export debug log to a named file 2026-11-22 13:50:13 +09:00
aclist 533a77da23 Merge pull request #545 from aclist/chore/test-typehints
chore: refactor tests
2026-11-22 13:42:53 +09:00
aclist b98172e782 Merge branch 'dzgui7' into chore/test-typehints
Mirror to Codeberg / mirror-to-codeberg (push) Waiting to run
2026-11-22 13:41:52 +09:00
aclist 5febda79ca Merge pull request #544 from aclist/fix/custom_xdg_path
fix: parse custom xdg paths
2026-11-22 13:37:46 +09:00
aclist dee566932a fix: wrap long error labels
Mirror to Codeberg / mirror-to-codeberg (push) Canceled after 0s
2026-11-19 06:10:49 +09:00
aclist 00741b0b60 fix: parse real home in sandbox 2026-11-19 06:10:24 +09:00
aclist 0f28885e7b chore: update thanks page
Mirror to Codeberg / mirror-to-codeberg (push) Canceled after 0s
2026-11-18 16:31:57 +09:00
aclist dfef2cfd75 drop: unused f-string
Mirror to Codeberg / mirror-to-codeberg (push) Canceled after 0s
2026-11-17 02:13:56 +09:00
aclist d47d7075e9 change: move try statement to outer function 2026-11-17 02:13:29 +09:00
aclist ea41503dad change: swallow stderr 2026-11-17 02:10:38 +09:00
aclist d2208787b4 chore: clear typehinting errors in build scripts 2026-11-12 12:01:59 +09:00
aclist 77682cacd4 change: refactor test for readability 2026-11-12 11:37:49 +09:00
aclist e8d7d9eb15 change: abstract flatpak ps command 2026-11-12 11:37:13 +09:00
15 changed files with 164 additions and 115 deletions

No files matched your search

+4 -2
View File
@@ -207,7 +207,8 @@ class RowType(Enum):
CHANGELOG = RowMeta(rows.changelog_label, rows.changelog_status) CHANGELOG = RowMeta(rows.changelog_label, rows.changelog_status)
SHOW_LOG = RowMeta(rows.log_label, rows.log_status) SHOW_LOG = RowMeta(rows.log_label, rows.log_status)
SEPARATOR = RowMeta(rows.separator_label, rows.separator_status) SEPARATOR = RowMeta(rows.separator_label, rows.separator_status)
DUMP_LOG = RowMeta(rows.system_log_label, rows.system_log_status) DUMP_DIAGNOSTIC = RowMeta(rows.system_log_label, rows.system_log_status)
DUMP_DEBUG = RowMeta(rows.debug_log_label, rows.debug_log_status)
DOCS = RowMeta(rows.docs_label, rows.docs_status) DOCS = RowMeta(rows.docs_label, rows.docs_status)
DOCS_FALLBACK = RowMeta(rows.docs_fallback_label, rows.docs_fallback_status) DOCS_FALLBACK = RowMeta(rows.docs_fallback_label, rows.docs_fallback_status)
BUGS = RowMeta(rows.bugs_label, rows.bugs_status) BUGS = RowMeta(rows.bugs_label, rows.bugs_status)
@@ -302,7 +303,8 @@ class ButtonType(Enum):
HELP_MENU_ROWS = ( HELP_MENU_ROWS = (
RowType.CHANGELOG, RowType.CHANGELOG,
RowType.SHOW_LOG, RowType.SHOW_LOG,
RowType.DUMP_LOG, RowType.DUMP_DIAGNOSTIC,
RowType.DUMP_DEBUG,
RowType.SEPARATOR, RowType.SEPARATOR,
RowType.DOCS, RowType.DOCS,
RowType.DOCS_FALLBACK, RowType.DOCS_FALLBACK,
+24 -9
View File
@@ -2,6 +2,7 @@ import gi
import logging import logging
import threading import threading
from pathlib import Path
from typing import Any, TYPE_CHECKING, Union from typing import Any, TYPE_CHECKING, Union
from dzgui.config.userprefs import UserPrefs from dzgui.config.userprefs import UserPrefs
@@ -23,7 +24,7 @@ from dzgui.model.servers import ServerModelManager
from dzgui.util.diag import write_diagnostic from dzgui.util.diag import write_diagnostic
from dzgui.util.format import format_exception, format_player_count from dzgui.util.format import format_exception, format_player_count
from dzgui.util.open_links import open_user_workshop, open_workshop_page from dzgui.util.open_links import open_user_workshop, open_workshop_page
from dzgui.views.dialogs.filepicker import FilePicker from dzgui.views.dialogs.filepicker import DebugLogPicker, DiagnosticLogPicker
from dzgui.views.dialogs.generic import ExceptionDialog from dzgui.views.dialogs.generic import ExceptionDialog
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
@@ -297,15 +298,29 @@ class Controller(GObject.GObject):
return self.get_active_treeview().get_filter_man() return self.get_active_treeview().get_filter_man()
def dump_diagnostics(self) -> None: def dump_diagnostics(self) -> None:
picker = FilePicker(self.mediator.window) picker = DiagnosticLogPicker(self.mediator.window)
file = picker.pick_file() file = picker.pick_file()
if file is not None: if file is None:
try: return
write_diagnostic(self.prefs.paths.config, file) try:
except Exception as e: write_diagnostic(self.prefs.paths.config, file)
dialog = ExceptionDialog(self, str(e)) except Exception as e:
dialog.show_all() dialog = ExceptionDialog(self, str(e))
dialog.run() # type: ignore[no-untyped-call] dialog.show_all()
dialog.run() # type: ignore[no-untyped-call]
def dump_log(self) -> None:
picker = DebugLogPicker(self.mediator.window)
file = picker.pick_file()
if file is None:
return
try:
log = self.prefs.paths.debug.read_text()
Path(file).write_text(log)
except Exception as e:
dialog = ExceptionDialog(self, str(e))
dialog.show_all()
dialog.run() # type: ignore[no-untyped-call]
def update_steam_api_key(self, text: str) -> None: def update_steam_api_key(self, text: str) -> None:
self.config_man.update_steam_api_key(text) self.config_man.update_steam_api_key(text)
+1 -1
View File
@@ -23,7 +23,7 @@ def has_flatpak_client() -> bool:
else: else:
return False return False
except Exception as e: except Exception as e:
logger.critical(e) logger.debug(e)
return False return False
+2
View File
@@ -0,0 +1,2 @@
debug_picker_title = "Save the debug log to a file"
diagnostic_picker_title = "Save system diagnostics to a file"
+4 -1
View File
@@ -7,9 +7,12 @@ log_status = "Read the DZGUI log generated since startup"
separator_label = "SEPARATOR" separator_label = "SEPARATOR"
separator_status = "" separator_status = ""
system_log_label = "Output system info to log file" system_log_label = "Output system info to a file"
system_log_status = "Dump diagnostic data for troubleshooting" system_log_status = "Dump diagnostic data for troubleshooting"
debug_log_label = "Output debug log to a file"
debug_log_status = "Dump a summary of errors/events since DZGUI started"
docs_label = "Documentation/help files (GitHub) ⧉" docs_label = "Documentation/help files (GitHub) ⧉"
docs_status = "Open the DZGUI documentation in a browser" docs_status = "Open the DZGUI documentation in a browser"
+2
View File
@@ -347,7 +347,9 @@ thanks = Thanks(
"scandalouss", "scandalouss",
"SnackSBR", "SnackSBR",
"StevelDusa", "StevelDusa",
"sylvaingirardbe",
"Thoughtduck216", "Thoughtduck216",
"u-alexandru",
], ],
) )
+2 -2
View File
@@ -19,7 +19,7 @@ from dzgui.views.components.buttons import ClipboardButton
from dzgui.views.mixins.colorscheme import ColorAwareApp from dzgui.views.mixins.colorscheme import ColorAwareApp
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk from gi.repository import Gtk, GLib, Gdk, Pango
if TYPE_CHECKING: if TYPE_CHECKING:
from dzgui.config.xdg import Xdg from dzgui.config.xdg import Xdg
@@ -95,7 +95,7 @@ class BootDialog(ColorAwareApp, Gtk.Dialog): # type: ignore
margin_top=30, margin_top=30,
margin_bottom=30, margin_bottom=30,
) )
self.error_label = Gtk.Label(margin_start=15, margin_end=15) self.error_label = Gtk.Label(margin_start=15, margin_end=15, wrap=True, wrap_mode=Pango.WrapMode.WORD)
# TODO: abstract class # TODO: abstract class
self.copy_button = ClipboardButton(self.error_label.get_text) self.copy_button = ClipboardButton(self.error_label.get_text)
+15 -4
View File
@@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
from dzgui.util.strings import picker from dzgui.const.constants import DEBUG_LOG, SYSTEM_LOG
from dzgui.strings.filepickers import diagnostic_picker_title, debug_picker_title
import gi import gi
@@ -9,9 +10,9 @@ from gi.repository import Gtk
class FilePicker(Gtk.FileChooserDialog): class FilePicker(Gtk.FileChooserDialog):
def __init__(self, parent: Gtk.Window) -> None: def __init__(self, parent: Gtk.Window, title: str, placeholder: str) -> None:
super().__init__( super().__init__(
title=picker.title, title=title,
action=Gtk.FileChooserAction.SAVE, action=Gtk.FileChooserAction.SAVE,
transient_for=parent, transient_for=parent,
resizable=True, resizable=True,
@@ -20,7 +21,7 @@ class FilePicker(Gtk.FileChooserDialog):
self.add_buttons("_Save", Gtk.ResponseType.OK) # type: ignore[no-untyped-call] self.add_buttons("_Save", Gtk.ResponseType.OK) # type: ignore[no-untyped-call]
self.set_default_response(Gtk.ResponseType.OK) self.set_default_response(Gtk.ResponseType.OK)
self.set_current_name(picker.placeholder) self.set_current_name(placeholder)
def pick_file(self) -> Path | None: def pick_file(self) -> Path | None:
res = self.run() # type: ignore[no-untyped-call] res = self.run() # type: ignore[no-untyped-call]
@@ -35,6 +36,16 @@ class FilePicker(Gtk.FileChooserDialog):
return None return None
class DiagnosticLogPicker(FilePicker):
def __init__(self, parent: Gtk.Window) -> None:
super().__init__(parent, diagnostic_picker_title, SYSTEM_LOG)
class DebugLogPicker(FilePicker):
def __init__(self, parent: Gtk.Window) -> None:
super().__init__(parent, debug_picker_title, DEBUG_LOG)
class FolderPicker(Gtk.FileChooserDialog): class FolderPicker(Gtk.FileChooserDialog):
def __init__(self, parent: Gtk.Window, title: str) -> None: def __init__(self, parent: Gtk.Window, title: str) -> None:
super().__init__( super().__init__(
+11 -12
View File
@@ -56,19 +56,18 @@ class MenuTreeView(TreeView):
self.controller.populate_log() self.controller.populate_log()
case RowType.CHANGELOG: case RowType.CHANGELOG:
self.controller.open_page(NotebookPage.CHANGELOG) self.controller.open_page(NotebookPage.CHANGELOG)
case RowType.DUMP_LOG: case RowType.DUMP_DIAGNOSTIC:
self.controller.dump_diagnostics() self.controller.dump_diagnostics()
pass case RowType.DUMP_DEBUG:
self.controller.dump_log()
docs = [ case (
RowType.DOCS, RowType.DOCS
RowType.DOCS_FALLBACK, | RowType.DOCS_FALLBACK
RowType.BUGS, | RowType.BUGS
RowType.FORUM, | RowType.FORUM
RowType.SPONSOR, | RowType.SPONSOR
] ):
if row_type in docs: open_link_by_rowtype(row_type)
open_link_by_rowtype(row_type)
def get_row_enum(self) -> str: def get_row_enum(self) -> str:
# NOTE: col 1 contains a RowType enum # NOTE: col 1 contains a RowType enum
+2 -1
View File
@@ -1,8 +1,9 @@
import tomllib import tomllib
from shared import get_git_root from shared import get_git_root
from typing import Any
def get_entrypoint() -> None: def get_entrypoint() -> Any:
root = get_git_root() root = get_git_root()
p = root.joinpath("pyproject.toml") p = root.joinpath("pyproject.toml")
with open(p, "rb") as f: with open(p, "rb") as f:
+3 -3
View File
@@ -52,7 +52,7 @@ def untar(file: str, glob: str, renamed: str) -> None:
os.rename(_dir, build_dir.joinpath(renamed)) os.rename(_dir, build_dir.joinpath(renamed))
def install_deps() -> None: def install_deps() -> int:
pip = build_dir.joinpath(f"{CPYTHON_BUILD}/bin/pip") pip = build_dir.joinpath(f"{CPYTHON_BUILD}/bin/pip")
proc = subprocess.run([pip, "install", root]) proc = subprocess.run([pip, "install", root])
return proc.returncode return proc.returncode
@@ -65,12 +65,12 @@ def repackage() -> None:
tar.add(build_dir.joinpath(CPYTHON_BUILD), arcname="python") tar.add(build_dir.joinpath(CPYTHON_BUILD), arcname="python")
def rebuild_cpython() -> None: def rebuild_cpython() -> str:
if cpython_dir.is_dir() is False: if cpython_dir.is_dir() is False:
get_cpython() get_cpython()
code = install_deps() code = install_deps()
if code != 0: if code != 0:
return return ""
repackage() repackage()
return get_packaged_version() return get_packaged_version()
+2 -2
View File
@@ -92,8 +92,8 @@ with tarfile.open(tarpath, "w:gz") as tar:
tar.add(subfolder, arcname=appname, filter=update_uname) tar.add(subfolder, arcname=appname, filter=update_uname)
print(f"Wrote tarfile to '{tarpath}'") print(f"Wrote tarfile to '{tarpath}'")
proc = subprocess.run([release_exe, "-v"], capture_output=True, text=True) built_proc = subprocess.run([release_exe, "-v"], capture_output=True, text=True)
assert proc.stdout.rstrip() == version assert str(built_proc.stdout).rstrip() == version
# TODO: clean up staging directory # TODO: clean up staging directory
release_exe.unlink() release_exe.unlink()
+10 -4
View File
@@ -8,7 +8,13 @@ def get_image_path() -> Path:
return get_git_root().joinpath("dzgui/data/images/example.png") return get_git_root().joinpath("dzgui/data/images/example.png")
p = get_image_path() def take_screenshot() -> None:
app = build_gui("", False) p = get_image_path()
app.set_automation_param("screenshot_path", p) app = build_gui("", False)
app.run(None) if app is None:
return
app.set_automation_param("screenshot_path", p)
app.run(None)
take_screenshot()
+6 -11
View File
@@ -3,14 +3,9 @@ import subprocess
import sys import sys
cmd = ["git", "ls-files", "--others", "--exclude-standard"] cmd = ["git", "ls-files", "--others", "--exclude-standard"]
result = subprocess.Popen( result = subprocess.run(cmd, capture_output=True, text=True)
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True untracked = [os.path.basename(line.rstrip()) for line in result.stdout.splitlines()]
) if bool(untracked):
with open(".gitignore", "r") as f: print("The following files are untracked. Add to .gitignore if this is intended.")
ignored = [line.rstrip() for line in f] print("\n".join(untracked))
sys.exit(1)
untracked = [os.path.basename(line.rstrip()) for line in result.stdout]
for file in untracked:
if not any(file in item for item in ignored):
print(f"File '{file}' is untracked. Add to .gitignore file if this is intended.")
sys.exit(1)
+76 -63
View File
@@ -1,80 +1,93 @@
import pytest import pytest
import unittest
from unittest.mock import patch from typing import Literal, TYPE_CHECKING
from typing import Any
from dzgui.const.constants import ( from dzgui.const.constants import (
FLATPAK_APPID, FLATPAK_APPID,
FLATPAK_ROOT_PATH, FLATPAK_ROOT_PATH,
FLATPAK_RUN_CMD,
FLATPAK_SANDBOX,
) )
from dzgui.init import proc from dzgui.init import proc
if TYPE_CHECKING:
from _pytest.monkeypatch import MonkeyPatch
pytestmark = pytest.mark.flatpak pytestmark = pytest.mark.flatpak
class TestSteamDetection(unittest.TestCase): def mock_has_cmd(cmd: str) -> Literal[True]:
def test_flatpak_detection_with_multiple_running_apps(self) -> None: return True
def flatpak_output(args: Any, *, text: str) -> str:
# Default 'flatpak ps' includes instance, PID, app and runtime columns.
if args == ["flatpak", "ps", "--columns=application"]:
return f"com.spotify.Client\n{FLATPAK_APPID}\n{FLATPAK_APPID}\n"
return f"3904921611\t1257689\t{FLATPAK_APPID}\torg.freedesktop.Platform\n"
with (
patch.object(proc, "has_cmd", return_value=True),
patch.object(proc.subprocess, "check_output", side_effect=flatpak_output),
):
for client in (FLATPAK_RUN_CMD, FLATPAK_SANDBOX):
with self.subTest(client=client):
self.assertTrue(proc.is_steam_running(client))
def test_flatpak_not_running(self) -> None: def mock_has_not_cmd(cmd: str) -> Literal[False]:
with patch.object(proc, "has_cmd", return_value=True): return False
for output in ("", "com.spotify.Client\n", f"{FLATPAK_APPID}Helper\n"):
with (
self.subTest(output=output),
patch.object(proc.subprocess, "check_output", return_value=output),
):
self.assertFalse(proc.is_flatpak_steam_running())
def test_flatpak_not_installed(self) -> None:
with (
patch.object(proc, "has_cmd", return_value=False),
patch.object(proc.subprocess, "check_output") as check_output,
):
self.assertFalse(proc.is_flatpak_steam_running())
check_output.assert_not_called()
def test_native_steam(self) -> None: def mock_get_flatpak_output() -> list[str]:
with patch.object(proc, "has_cmd", return_value=True): lines = ["Application", "com.freedesktop.Platform", f"{FLATPAK_APPID}"]
for output, expected in ( return lines
(
[
[FLATPAK_ROOT_PATH],
"/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper",
],
True,
),
([[FLATPAK_ROOT_PATH]], False),
([[FLATPAK_ROOT_PATH], ["steam-runtime-launcher-service"]], False),
([["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"]], True),
(
[
["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"],
"steam-runtime-launcher-service",
],
True,
),
):
with (
self.subTest(running=output),
patch.object(proc, "get_steam_procs", return_value=output),
):
self.assertEqual(proc.is_native_steam_running(), expected)
def test_invalid_client(self) -> None:
with self.assertRaises(TypeError): @pytest.mark.parametrize(
proc.is_steam_running("invalid-client") "output, expected",
[
(
[
[f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"],
["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"],
],
True,
),
(
[
[f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"],
["steam-runtime-launcher-service"],
],
False,
),
([[f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"]], False),
([["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"]], True),
(
[
["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"],
["steam-runtime-launcher-service"],
],
True,
),
],
)
def test_native_steam_running(
monkeypatch: "MonkeyPatch", output: list[list[str]], expected: bool
) -> None:
def mock_get_steam_procs() -> list[list[str]]:
return output
monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_cmd)
monkeypatch.setattr("dzgui.init.proc.get_steam_procs", mock_get_steam_procs)
assert proc.is_native_steam_running() == expected
def test_flatpak_running(monkeypatch: "MonkeyPatch") -> None:
monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_cmd)
monkeypatch.setattr("dzgui.init.proc.get_flatpak_output", mock_get_flatpak_output)
assert proc.is_flatpak_steam_running()
def test_flatpak_sandboxed(monkeypatch: "MonkeyPatch") -> None:
monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd)
monkeypatch.setenv("FLATPAK_ID", FLATPAK_APPID)
assert proc.is_flatpak_steam_running()
def test_flatpak_not_installed(monkeypatch: "MonkeyPatch") -> None:
monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd)
assert not proc.is_flatpak_steam_running()
def test_steam_not_installed(monkeypatch: "MonkeyPatch") -> None:
monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd)
assert not proc.is_native_steam_running()
def test_invalid_client() -> None:
with pytest.raises(TypeError):
proc.is_steam_running("invalid-client")