mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-13 08:24:40 +08:00
Split auto_upgrader into check_new_version so we can actually show in GUI
This commit is contained in:
parent
a0a1091a53
commit
cbd8bbeb02
5 changed files with 52 additions and 20 deletions
|
@ -11,12 +11,24 @@ __build__ = "2023011701"
|
||||||
|
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from npbackup.upgrade_client.upgrader import auto_upgrader
|
from npbackup.upgrade_client.upgrader import auto_upgrader, _check_new_version
|
||||||
|
|
||||||
|
|
||||||
logger = getLogger(__intname__)
|
logger = getLogger(__intname__)
|
||||||
|
|
||||||
|
|
||||||
|
def check_new_version(config_dict):
|
||||||
|
try:
|
||||||
|
upgrade_url = config_dict["options"]["server_url"]
|
||||||
|
username = config_dict["options"]["server_username"]
|
||||||
|
password = config_dict["options"]["server_password"]
|
||||||
|
except KeyError as exc:
|
||||||
|
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return _check_new_version(upgrade_url, username, password)
|
||||||
|
|
||||||
|
|
||||||
def run_upgrade(config_dict):
|
def run_upgrade(config_dict):
|
||||||
try:
|
try:
|
||||||
auto_upgrade_upgrade_url = config_dict["options"]["server_url"]
|
auto_upgrade_upgrade_url = config_dict["options"]["server_url"]
|
||||||
|
|
|
@ -34,7 +34,7 @@ from npbackup.customization import (
|
||||||
from npbackup.gui.config import config_gui
|
from npbackup.gui.config import config_gui
|
||||||
from npbackup.core.runner import NPBackupRunner
|
from npbackup.core.runner import NPBackupRunner
|
||||||
from npbackup.core.i18n_helper import _t
|
from npbackup.core.i18n_helper import _t
|
||||||
from npbackup.core.upgrade_runner import run_upgrade
|
from npbackup.core.upgrade_runner import run_upgrade, check_new_version
|
||||||
|
|
||||||
|
|
||||||
logger = getLogger(__intname__)
|
logger = getLogger(__intname__)
|
||||||
|
@ -46,6 +46,16 @@ THREAD_SHARED_DICT = {}
|
||||||
|
|
||||||
def _about_gui(version_string: str, config_dict: dict) -> None:
|
def _about_gui(version_string: str, config_dict: dict) -> None:
|
||||||
license_content = LICENSE_TEXT
|
license_content = LICENSE_TEXT
|
||||||
|
if check_new_version(config_dict):
|
||||||
|
new_version = [
|
||||||
|
sg.Button(
|
||||||
|
_t("config_gui.auto_upgrade_launch"), key="autoupgrade", size=(12, 2)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
new_version = [
|
||||||
|
sg.Text(_t("generic.is_uptodate"))
|
||||||
|
]
|
||||||
try:
|
try:
|
||||||
with open(LICENSE_FILE, "r") as file_handle:
|
with open(LICENSE_FILE, "r") as file_handle:
|
||||||
license_content = file_handle.read()
|
license_content = file_handle.read()
|
||||||
|
@ -54,19 +64,16 @@ def _about_gui(version_string: str, config_dict: dict) -> None:
|
||||||
|
|
||||||
layout = [
|
layout = [
|
||||||
[sg.Text(version_string)],
|
[sg.Text(version_string)],
|
||||||
[
|
new_version,
|
||||||
sg.Button(
|
|
||||||
_t("config_gui.auto_upgrade_launch"), key="autoupgrade", size=(12, 2)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
[sg.Text("License: GNU GPLv3")],
|
[sg.Text("License: GNU GPLv3")],
|
||||||
[sg.Multiline(license_content, size=(65, 20))],
|
[sg.Multiline(license_content, size=(65, 20))],
|
||||||
[sg.Button(_t("generic.accept"), key="exit")],
|
[sg.Button(_t("generic.accept"), key="exit")],
|
||||||
]
|
]
|
||||||
|
|
||||||
window = sg.Window(
|
window = sg.Window(
|
||||||
_t("generic.about"), layout, keep_on_top=True, element_justification="C"
|
_t("generic.about"), layout, keep_on_top=True, element_justification="C", finalize=True
|
||||||
)
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event, _ = window.read()
|
event, _ = window.read()
|
||||||
if event in [sg.WIN_CLOSED, "exit"]:
|
if event in [sg.WIN_CLOSED, "exit"]:
|
||||||
|
|
|
@ -28,3 +28,5 @@ en:
|
||||||
|
|
||||||
decrypt: Decrypt
|
decrypt: Decrypt
|
||||||
encrypt: Encrypt
|
encrypt: Encrypt
|
||||||
|
|
||||||
|
is_uptodate: Program Uptodateu
|
|
@ -27,4 +27,6 @@ fr:
|
||||||
destination: Destination
|
destination: Destination
|
||||||
|
|
||||||
decrypt: Déchiffrer
|
decrypt: Déchiffrer
|
||||||
encrypt: Chiffrer
|
encrypt: Chiffrer
|
||||||
|
|
||||||
|
is_uptodate: Logiciel à jour
|
|
@ -98,19 +98,10 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
|
def _check_new_version(upgrade_url: str, username: str, password: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Auto upgrade binary NPBackup distributions
|
Check if we have a newer version of npbackup
|
||||||
|
|
||||||
We must check that we run a compiled binary first
|
|
||||||
We assume that we run a onefile nuitka binary
|
|
||||||
"""
|
"""
|
||||||
is_nuitka = "__compiled__" in globals()
|
|
||||||
if not is_nuitka:
|
|
||||||
logger.info(
|
|
||||||
"Auto upgrade will only upgrade compiled verions. Please use 'pip install --upgrade npbackup' instead"
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
logger.info("Upgrade server is %s", upgrade_url)
|
logger.info("Upgrade server is %s", upgrade_url)
|
||||||
requestor = Requestor(upgrade_url, username, password)
|
requestor = Requestor(upgrade_url, username, password)
|
||||||
requestor.create_session(authenticated=True)
|
requestor.create_session(authenticated=True)
|
||||||
|
@ -148,6 +139,24 @@ def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
|
||||||
|
"""
|
||||||
|
Auto upgrade binary NPBackup distributions
|
||||||
|
|
||||||
|
We must check that we run a compiled binary first
|
||||||
|
We assume that we run a onefile nuitka binary
|
||||||
|
"""
|
||||||
|
is_nuitka = "__compiled__" in globals()
|
||||||
|
if not is_nuitka:
|
||||||
|
logger.info(
|
||||||
|
"Auto upgrade will only upgrade compiled verions. Please use 'pip install --upgrade npbackup' instead"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not _check_new_version(upgrade_url, username, password):
|
||||||
|
return False
|
||||||
|
requestor = Requestor(upgrade_url, username, password)
|
||||||
|
requestor.create_session(authenticated=True)
|
||||||
platform_and_arch = "{}/{}".format(get_os(), os_arch()).lower()
|
platform_and_arch = "{}/{}".format(get_os(), os_arch()).lower()
|
||||||
|
|
||||||
file_info = requestor.data_model("upgrades", id_record=platform_and_arch)
|
file_info = requestor.data_model("upgrades", id_record=platform_and_arch)
|
||||||
|
|
Loading…
Add table
Reference in a new issue