mirror of
https://github.com/netinvent/npbackup.git
synced 2025-02-23 14:04:43 +08:00
Refactor upgrader to use new config format
This commit is contained in:
parent
bc230037fd
commit
3082e6311f
2 changed files with 27 additions and 26 deletions
|
@ -19,34 +19,32 @@ from npbackup.__version__ import __version__ as npbackup_version
|
|||
logger = getLogger()
|
||||
|
||||
|
||||
def check_new_version(config_dict: dict) -> bool:
|
||||
try:
|
||||
upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
|
||||
username = config_dict["options"]["auto_upgrade_server_username"]
|
||||
password = config_dict["options"]["auto_upgrade_server_password"]
|
||||
except KeyError as exc:
|
||||
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
||||
def check_new_version(full_config: dict) -> bool:
|
||||
upgrade_url = full_config.g("global_options.auto_upgrade_server_url")
|
||||
username = full_config.g("global_options.auto_upgrade_server_username")
|
||||
password = full_config.g("global_options.auto_upgrade_server_password")
|
||||
if not upgrade_url or not username or not password:
|
||||
logger.error(f"Missing auto upgrade info, cannot launch auto upgrade")
|
||||
return None
|
||||
else:
|
||||
return _check_new_version(upgrade_url, username, password)
|
||||
|
||||
|
||||
def run_upgrade(config_dict):
|
||||
try:
|
||||
auto_upgrade_upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
|
||||
auto_upgrade_username = config_dict["options"]["auto_upgrade_server_username"]
|
||||
auto_upgrade_password = config_dict["options"]["auto_upgrade_server_password"]
|
||||
except KeyError as exc:
|
||||
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
||||
def run_upgrade(full_config: dict) -> bool:
|
||||
upgrade_url = full_config.g("global_options.auto_upgrade_server_url")
|
||||
username = full_config.g("global_options.auto_upgrade_server_username")
|
||||
password = full_config.g("global_options.auto_upgrade_server_password")
|
||||
if not upgrade_url or not username or not password:
|
||||
logger.error(f"Missing auto upgrade info, cannot launch auto upgrade")
|
||||
return False
|
||||
|
||||
auto_upgrade_host_identity = config_dict.g("global_options.auto_upgrade_host_identity")
|
||||
group = config_dict.g("global_options.auto_upgrade_group")
|
||||
auto_upgrade_host_identity = full_config.g("global_options.auto_upgrade_host_identity")
|
||||
group = full_config.g("global_options.auto_upgrade_group")
|
||||
|
||||
result = auto_upgrader(
|
||||
upgrade_url=auto_upgrade_upgrade_url,
|
||||
username=auto_upgrade_username,
|
||||
password=auto_upgrade_password,
|
||||
upgrade_url=upgrade_url,
|
||||
username=username,
|
||||
password=password,
|
||||
auto_upgrade_host_identity=auto_upgrade_host_identity,
|
||||
installed_version=npbackup_version,
|
||||
group=group,
|
||||
|
|
|
@ -65,11 +65,14 @@ logger = getLogger()
|
|||
THREAD_SHARED_DICT = {}
|
||||
|
||||
|
||||
def _about_gui(version_string: str, repo_config: dict) -> None:
|
||||
def _about_gui(version_string: str, full_config: dict) -> None:
|
||||
license_content = LICENSE_TEXT
|
||||
|
||||
result = check_new_version(repo_config)
|
||||
if result:
|
||||
if full_config.g("global_options.auto_upgrade_server_url"):
|
||||
auto_upgrade_result = check_new_version(full_config)
|
||||
else:
|
||||
auto_upgrade_result = None
|
||||
if auto_upgrade_result:
|
||||
new_version = [
|
||||
sg.Button(
|
||||
_t("config_gui.auto_upgrade_launch"),
|
||||
|
@ -77,9 +80,9 @@ def _about_gui(version_string: str, repo_config: dict) -> None:
|
|||
size=(12, 2),
|
||||
)
|
||||
]
|
||||
elif result is False:
|
||||
elif auto_upgrade_result is False:
|
||||
new_version = [sg.Text(_t("generic.is_uptodate"))]
|
||||
elif result is None:
|
||||
elif auto_upgrade_result is None:
|
||||
new_version = [sg.Text(_t("config_gui.auto_upgrade_disabled"))]
|
||||
try:
|
||||
with open(LICENSE_FILE, "r", encoding="utf-8") as file_handle:
|
||||
|
@ -113,7 +116,7 @@ def _about_gui(version_string: str, repo_config: dict) -> None:
|
|||
)
|
||||
if result == "OK":
|
||||
logger.info("Running GUI initiated upgrade")
|
||||
sub_result = run_upgrade(repo_config)
|
||||
sub_result = run_upgrade(full_config)
|
||||
if sub_result:
|
||||
sys.exit(0)
|
||||
else:
|
||||
|
@ -768,7 +771,7 @@ def _main_gui():
|
|||
except (TypeError, KeyError):
|
||||
sg.PopupNoFrame(_t("main_gui.unknown_repo"))
|
||||
if event == "about":
|
||||
_about_gui(version_string, repo_config)
|
||||
_about_gui(version_string, full_config)
|
||||
if event == "state-button":
|
||||
current_state, backup_tz, snapshot_list = get_gui_data(repo_config)
|
||||
_gui_update_state(window, current_state, backup_tz, snapshot_list)
|
||||
|
|
Loading…
Reference in a new issue