mirror of
https://github.com/aclist/dztui.git
synced 2026-11-06 18:10:58 +01:00
Compare commits
6
Commits
7.0.0b4
...
6ec77f6542
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ec77f6542 | ||
|
|
59959ae3a1 | ||
|
|
05fd95cd8e | ||
|
|
86ba8d9187 | ||
|
|
e715e6da1c | ||
|
|
18ba851b7e |
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import logging
|
||||
import requests
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dzgui.const.constants import (
|
||||
APP_NAME,
|
||||
TMP_EXE,
|
||||
TMP_PATH,
|
||||
TMP_TARBALL,
|
||||
)
|
||||
from dzgui.strings import dialogs
|
||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||
from dzgui.views.dialogs.generic import ExceptionDialog, QuitDialog
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GLib # noqa E402
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dzgui.controllers.mc import Controller
|
||||
|
||||
logger = logging.getLogger(APP_NAME)
|
||||
|
||||
|
||||
class UpdateManager:
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
|
||||
self.thread_man = ThreadingManager(controller)
|
||||
self.controller = controller
|
||||
|
||||
@call_on_thread(dialogs.fetching_update)
|
||||
def update_version(self, exe_path: str, url: str) -> None:
|
||||
try:
|
||||
res = requests.get(url)
|
||||
if res.status_code == 200:
|
||||
with open(TMP_TARBALL, "wb") as file:
|
||||
file.write(res.content)
|
||||
with tarfile.open(TMP_TARBALL) as tar:
|
||||
tar.extractall(TMP_PATH)
|
||||
|
||||
shutil.move(TMP_EXE, exe_path)
|
||||
|
||||
proc = subprocess.run([exe_path, "self", "restore"])
|
||||
if proc.returncode == 0:
|
||||
func = StoredFunc(self._on_update_success)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
else:
|
||||
msg = dialogs.failed_to_update
|
||||
func = StoredFunc(self._on_update_failure, msg)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
except Exception as e:
|
||||
func = StoredFunc(self._on_update_failure, e)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
logger.warning(e)
|
||||
|
||||
def _on_update_success(self) -> None:
|
||||
msg = dialogs.update_success
|
||||
dialog = QuitDialog(self.controller, msg)
|
||||
dialog.run()
|
||||
|
||||
def _on_update_failure(self, msg: str) -> None:
|
||||
dialog = ExceptionDialog(self.controller, msg)
|
||||
dialog.run()
|
||||
@@ -1,9 +1,5 @@
|
||||
import logging
|
||||
import os
|
||||
import requests
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
|
||||
from typing import Literal, TYPE_CHECKING
|
||||
|
||||
@@ -13,20 +9,14 @@ from dzgui.const.constants import (
|
||||
NO_FILL,
|
||||
FILL,
|
||||
NO_PADDING,
|
||||
TMP_EXE,
|
||||
TMP_PATH,
|
||||
TMP_TARBALL,
|
||||
)
|
||||
from dzgui.const.update import ALLOW_UPDATES
|
||||
from dzgui.const.enum import ServerTab
|
||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||
from dzgui.strings import dialogs
|
||||
from dzgui.managers.update import UpdateManager
|
||||
from dzgui.util.clip import copy_clipboard
|
||||
from dzgui.views.components.buttonbox import ButtonBox
|
||||
from dzgui.views.components.filter_panel import FilterPanel
|
||||
from dzgui.views.components.mod_panel import ModSelectionPanel
|
||||
from dzgui.views.components.buttons import IconTextButton, RefreshButton, KeysButton
|
||||
from dzgui.views.dialogs.generic import ExceptionDialog, QuitDialog
|
||||
|
||||
import gi
|
||||
|
||||
@@ -45,7 +35,6 @@ class RightPanel(Gtk.Box):
|
||||
def __init__(self, controller: "Controller"):
|
||||
super().__init__(spacing=6, orientation=Gtk.Orientation.VERTICAL)
|
||||
|
||||
self.thread_man = ThreadingManager(controller)
|
||||
self.controller = controller
|
||||
self.controller.register_widget("right_panel", self)
|
||||
|
||||
@@ -96,54 +85,20 @@ class RightPanel(Gtk.Box):
|
||||
valign=Gtk.Align.END,
|
||||
spacing=10,
|
||||
)
|
||||
if ALLOW_UPDATES and update is not None:
|
||||
exe_path = os.getenv("PYAPP")
|
||||
if exe_path and update is not None:
|
||||
self.update_button.set_halign(Gtk.Align.END)
|
||||
self.gutter_box.add(self.update_button)
|
||||
self.update_button.connect(
|
||||
"clicked", self._on_update_button_clicked, update
|
||||
"clicked", self._on_update_button_clicked, exe_path, update
|
||||
)
|
||||
self.gutter_box.add(eb)
|
||||
self.pack_start(self.gutter_box, NO_EXPAND, FILL, NO_PADDING)
|
||||
|
||||
def _on_update_success(self) -> None:
|
||||
msg = dialogs.update_success
|
||||
dialog = QuitDialog(self.controller, msg)
|
||||
dialog.run()
|
||||
|
||||
def _on_update_failure(self, msg: str) -> None:
|
||||
dialog = ExceptionDialog(self.controller, msg)
|
||||
dialog.run()
|
||||
|
||||
@call_on_thread(dialogs.fetching_update)
|
||||
def _on_update_button_clicked(self, button: Gtk.Button, url: str) -> None:
|
||||
try:
|
||||
res = requests.get(url)
|
||||
if res.status_code == 200:
|
||||
with open(TMP_TARBALL, "wb") as file:
|
||||
file.write(res.content)
|
||||
with tarfile.open(TMP_TARBALL) as tar:
|
||||
tar.extractall(TMP_PATH)
|
||||
|
||||
exe_path = os.getenv("PYAPP")
|
||||
if exe_path is None:
|
||||
msg = dialogs.failed_to_update
|
||||
func = StoredFunc(self._on_update_failure, msg)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
return
|
||||
shutil.move(TMP_EXE, exe_path)
|
||||
|
||||
proc = subprocess.run([exe_path, "self", "restore"])
|
||||
if proc.returncode == 0:
|
||||
func = StoredFunc(self._on_update_success)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
else:
|
||||
msg = dialogs.failed_to_update
|
||||
func = StoredFunc(self._on_update_failure, msg)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
except Exception as e:
|
||||
func = StoredFunc(self._on_update_failure, e)
|
||||
self.thread_man.set_cleanup_func(func, destroy_first=True)
|
||||
logger.warning(e)
|
||||
def _on_update_button_clicked(
|
||||
self, button: Gtk.Button, exe_path: str, url: str
|
||||
) -> None:
|
||||
UpdateManager(self.controller).update_version(exe_path, url)
|
||||
|
||||
def _on_server_page_changed(
|
||||
self, emitter: "Emitter", page: "ServerTreeView"
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ description = "DayZ server browser and mod manager for Linux"
|
||||
authors = [
|
||||
{name = "aclist"}
|
||||
]
|
||||
version = "7.0.0b4"
|
||||
version = "7.0.0b5"
|
||||
license = "GPL-3.0-or-later"
|
||||
license-files = ["LICENSE"]
|
||||
readme = "README.md"
|
||||
|
||||
@@ -28,7 +28,6 @@ env["PYAPP_PROJECT_NAME"] = appname
|
||||
env["PYAPP_EXEC_SPEC"] = entrypoint
|
||||
env["PYAPP_PROJECT_PATH"] = wheel
|
||||
env["PYAPP_PASS_LOCATION"] = "true"
|
||||
# env["PYAPP_PYTHON_VERSION"] = "3.13"
|
||||
|
||||
# NOTE: explicitly install all dependencies into distribution
|
||||
env["PYAPP_SKIP_INSTALL"] = "true"
|
||||
|
||||
@@ -2,14 +2,14 @@ from dzgui.util import localize
|
||||
|
||||
|
||||
def test_de(monkeypatch):
|
||||
monkeypatch.setenv("LC_CTYPE", "de_DE.UTF-8")
|
||||
monkeypatch.setenv("LC_ALL", "de_DE.UTF-8")
|
||||
localize.set_locale()
|
||||
assert localize.number(9900) == "9.900"
|
||||
assert localize.number(99.88) == "99,88"
|
||||
|
||||
|
||||
def test_en(monkeypatch):
|
||||
monkeypatch.setenv("LC_CTYPE", "en_US.UTF-8")
|
||||
monkeypatch.setenv("LC_ALL", "en_US.UTF-8")
|
||||
localize.set_locale()
|
||||
assert localize.number(9900) == "9,900"
|
||||
assert localize.number(99.88) == "99.88"
|
||||
@@ -22,7 +22,7 @@ def test_none(monkeypatch):
|
||||
|
||||
|
||||
def test_empty(monkeypatch):
|
||||
monkeypatch.setenv("LC_CTYPE", "")
|
||||
monkeypatch.setenv("LC_ALL", "")
|
||||
localize.set_locale()
|
||||
assert localize.number(9900) == "9,900"
|
||||
assert localize.number(99.88) == "99.88"
|
||||
Reference in new issue
Block a user