mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +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,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