mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 22:52:42 +01:00
feat: dzgui 7 alpha
This commit is contained in:
1 parent
1acdbd58c5
commit
2e5b771137
150 files changed
+10359
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dzgui.util.ip import get_local_ip, get_coords, Coords
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_local_coords(path: "Path") -> Coords | None:
|
||||
try:
|
||||
my_ip = get_local_ip()
|
||||
except Exception as e:
|
||||
logger.warn(e)
|
||||
return None
|
||||
|
||||
try:
|
||||
return get_coords(path, my_ip)
|
||||
except Exception as e:
|
||||
logger.warn(e)
|
||||
return None
|
||||
@@ -0,0 +1,22 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.config.query import lookup
|
||||
from dzgui.const.constants import LIBRARYFOLDERS_PATH, APPID_DAYZ
|
||||
from dzgui.const.enum import Preferences
|
||||
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
||||
|
||||
import dzgui.api.pefile as PeFile
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def is_dayz_installed(config: Path) -> None:
|
||||
try:
|
||||
path = lookup(config, Preferences.DEFAULT)
|
||||
PeFile.get_app_path(Path(path) / LIBRARYFOLDERS_PATH, APPID_DAYZ)
|
||||
except Exception as e:
|
||||
logger.critical(e)
|
||||
EarlyAlertDialog(e)
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,25 @@
|
||||
import fcntl
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
||||
from dzgui.util.strings import cannot_acquire_lock
|
||||
|
||||
|
||||
def lock_release(lock: TextIO) -> None:
|
||||
fcntl.flock(lock, fcntl.LOCK_UN)
|
||||
os.close(lock.fileno())
|
||||
|
||||
|
||||
def lock_acquire() -> TextIO:
|
||||
lockfile = Path("/tmp/dzgui.flock")
|
||||
lock = open(lockfile, "w")
|
||||
try:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except OSError:
|
||||
EarlyAlertDialog(cannot_acquire_lock)
|
||||
sys.exit(1)
|
||||
return lock
|
||||
@@ -0,0 +1,37 @@
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from dzgui.const.constants import LEGACY_CONFIG_PATH
|
||||
from dzgui.config.convert import rc2json
|
||||
|
||||
|
||||
def test_legacy_conf(config: Path) -> None:
|
||||
if config.exists() is True:
|
||||
return
|
||||
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
||||
if old_conf.is_file():
|
||||
j = rc2json(old_conf)
|
||||
Path(config).parent.mkdir(parents=True, exist_ok=True)
|
||||
config.write_text(j)
|
||||
else:
|
||||
print("Unimplemented. You must have a working dztuirc.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def move_state_files(state_path: Path) -> None:
|
||||
home = Path.home()
|
||||
legacy = home / ".local/state/dzgui"
|
||||
if state_path == legacy:
|
||||
# TODO: log this
|
||||
return
|
||||
for file in legacy.iterdir():
|
||||
file.rename(state_path / file.name)
|
||||
|
||||
|
||||
def move_ipdb(ips_path: Path) -> None:
|
||||
home = Path.home()
|
||||
name = "ips.csv"
|
||||
legacy = home / ".local/share/helpers/dzgui" / name
|
||||
if ips_path == legacy:
|
||||
return
|
||||
legacy.rename(ips_path)
|
||||
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from importlib import metadata
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.const.constants import APP_NAME_LOWER
|
||||
|
||||
def is_prefix_writeable() -> bool:
|
||||
prefix = sys.prefix
|
||||
path = Path(prefix)
|
||||
file = path / ".is_writeable"
|
||||
try:
|
||||
with open(file, "w") as f:
|
||||
f.write("")
|
||||
os.remove(file)
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_version() -> str:
|
||||
return metadata.version(APP_NAME_LOWER)
|
||||
@@ -0,0 +1,28 @@
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from dzgui.const.constants import STEAM_CMD, FLATPAK_APPID, FLATPAK_CMD
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def has_steam_client() -> bool:
|
||||
if shutil.which(STEAM_CMD):
|
||||
return True
|
||||
if not shutil.which(FLATPAK_CMD):
|
||||
return False
|
||||
try:
|
||||
res = subprocess.run(
|
||||
[FLATPAK_CMD, "list"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
if FLATPAK_APPID in res.stdout:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.critical(e)
|
||||
return False
|
||||
@@ -0,0 +1,26 @@
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
from dzgui.const.constants import DAYZ_BINARY, STEAM_CMD
|
||||
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
||||
from dzgui.util.strings import init
|
||||
|
||||
|
||||
def is_dayz_running() -> None:
|
||||
if is_running(DAYZ_BINARY) is True:
|
||||
EarlyAlertDialog(init.is_dayz_running)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def is_steam_running() -> None:
|
||||
# TODO: check proc name of flatpak steam
|
||||
if is_running(STEAM_CMD) is False:
|
||||
EarlyAlertDialog(init.is_steam_running)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def is_running(proc: str) -> bool:
|
||||
for process in psutil.process_iter(["pid", "name"]):
|
||||
if process.info["name"] == proc:
|
||||
return True
|
||||
return False
|
||||
@@ -0,0 +1,51 @@
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
"""
|
||||
Find possible locations of default steam path
|
||||
"""
|
||||
|
||||
def get_steam_dirs() -> list[Path]:
|
||||
dirs = []
|
||||
# pass 1
|
||||
if shutil.which("locate") is not None:
|
||||
# TODO: config or steamapps path? cf. LIBRARYFOLDERS_PATH
|
||||
proc = subprocess.run(
|
||||
["/usr/bin/locate", "Steam/config/libraryfolders.vdf"],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
if proc.returncode == 0:
|
||||
for d in proc.stdout.splitlines():
|
||||
dirs.append(Path(d))
|
||||
return dirs
|
||||
|
||||
# pass 2
|
||||
for d in Path.home().rglob("Steam/config/libraryfolders.vdf"):
|
||||
dirs.append(d)
|
||||
|
||||
# pass 3
|
||||
# if still nothing, let them select it
|
||||
# prompt what the dir should look like
|
||||
if len(dirs) == 0:
|
||||
print("none found")
|
||||
return dirs
|
||||
|
||||
|
||||
dirs = get_steam_dirs()
|
||||
print(dirs)
|
||||
|
||||
# TODO: present these in a group of radio buttons
|
||||
"""
|
||||
when user toggles radio button, updates text saying
|
||||
"this is the standard steam location on debian" etc.
|
||||
|
||||
if None or if not satisfied, pop a filepicker and choose
|
||||
if selection was custom, it has to have a libraryfolders.vdf
|
||||
keeps next button grayed out until requirements are satisfied
|
||||
|
||||
Cancel Next
|
||||
"""
|
||||
@@ -0,0 +1,50 @@
|
||||
import requests
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from importlib import resources
|
||||
from packaging.version import Version, InvalidVersion
|
||||
from pathlib import Path
|
||||
|
||||
from dzgui.const.constants import APP_NAME_LOWER, REQUEST_TIMEOUT
|
||||
from dzgui.const.endpoints import GITHUB_RELEASES, CODEBERG_RELEASES
|
||||
from dzgui.init.prefix import is_prefix_writeable
|
||||
|
||||
|
||||
def get_latest_release() -> str | None:
|
||||
tag = None
|
||||
for url in [GITHUB_RELEASES, CODEBERG_RELEASES]:
|
||||
res = requests.get(url, timeout=REQUEST_TIMEOUT)
|
||||
if res.status_code == 200:
|
||||
tag = res.json()["tag_name"]
|
||||
break
|
||||
return tag
|
||||
|
||||
def allow_updates(allow: bool) -> bool:
|
||||
if allow is False:
|
||||
return False
|
||||
if allow is True:
|
||||
return is_prefix_writeable()
|
||||
|
||||
def check_updates(version: str) -> None:
|
||||
latest = get_latest_release()
|
||||
prefix = sys.prefix
|
||||
if latest is None:
|
||||
return
|
||||
try:
|
||||
if Version(version) >= Version(latest):
|
||||
return
|
||||
|
||||
# TODO: test update logic
|
||||
print("UNIMPLEMENTED: fetches in-app updates")
|
||||
return
|
||||
|
||||
with resources.path(APP_NAME_LOWER, "scripts/update.sh") as path:
|
||||
proc = subprocess.Popen(["/usr/bin/env", "bash", path, latest, prefix])
|
||||
if proc != 0:
|
||||
# TODO: pop a dialog
|
||||
pass
|
||||
sys.exit(proc)
|
||||
except InvalidVersion:
|
||||
return
|
||||
Reference in new issue
Block a user