GUI: Inject config file on upgrade test

This commit is contained in:
deajan 2025-02-04 12:09:48 +01:00
parent 3716427c32
commit fb1a49fc97
4 changed files with 26 additions and 10 deletions

View file

@ -562,7 +562,7 @@ This is free software, and you are welcome to redistribute it under certain cond
# Don't log upgrade check errors if we're in auto upgrade mode
# since it will change the whole exit code of the program
result = upgrade_runner.run_upgrade(
full_config, ignore_errors=False if args.auto_upgrade else True
config_file, full_config, ignore_errors=False if args.auto_upgrade else True
)
if result:
# This only happens when no upgrade is available

View file

@ -105,7 +105,9 @@ def check_new_version(full_config: dict) -> bool:
return _check_new_version(upgrade_url, username, password)
def run_upgrade(full_config: dict, ignore_errors: bool = False) -> bool:
def run_upgrade(
config_file: str, full_config: dict, ignore_errors: bool = False
) -> 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")
@ -122,6 +124,7 @@ def run_upgrade(full_config: dict, ignore_errors: bool = False) -> bool:
group = evaluated_full_config.g("global_options.auto_upgrade_group")
result = auto_upgrader(
config_file=config_file,
upgrade_url=upgrade_url,
username=username,
password=password,

View file

@ -54,8 +54,8 @@ from npbackup.gui.helpers import get_anon_repo_uri, gui_thread_runner
from npbackup.core.i18n_helper import _t
from npbackup.core import upgrade_runner
from npbackup.path_helper import CURRENT_DIR
from npbackup.__version__ import version_string
from npbackup.__debug__ import _DEBUG
from npbackup.__version__ import version_dict, version_string
from npbackup.__debug__ import _DEBUG, _NPBACKUP_ALLOW_AUTOUPGRADE_DEBUG
from npbackup.restic_wrapper import ResticRunner
from npbackup.restic_wrapper import schema
@ -83,7 +83,10 @@ def popup_wait_for_upgrade(text: str):
def about_gui(
version_string: str, full_config: dict = None, auto_upgrade_result: bool = False
version_string: str,
config_file: str,
full_config: dict = None,
auto_upgrade_result: bool = False,
) -> None:
if auto_upgrade_result:
@ -125,7 +128,7 @@ def about_gui(
)
if result == "OK":
logger.info("Running GUI initiated upgrade")
sub_result = upgrade_runner.run_upgrade(full_config)
sub_result = upgrade_runner.run_upgrade(config_file, full_config)
if sub_result:
sys.exit(0)
else:
@ -529,7 +532,7 @@ def _main_gui(viewer_mode: bool):
global backend_binary
global GUI_STATUS_IGNORE_ERRORS
def check_for_auto_upgrade(full_config: dict) -> bool:
def check_for_auto_upgrade(config_file: str, full_config: dict) -> bool:
if full_config and full_config.g("global_options.auto_upgrade_server_url"):
upgrade_popup = popup_wait_for_upgrade(_t("main_gui.auto_upgrade_checking"))
auto_upgrade_result = upgrade_runner.check_new_version(full_config)
@ -543,7 +546,7 @@ def _main_gui(viewer_mode: bool):
sg.Popup(
_t("main_gui.upgrade_in_progress"),
)
result = upgrade_runner.run_upgrade(full_config)
result = upgrade_runner.run_upgrade(config_file, full_config)
if not result:
sg.Popup(_t("config_gui.auto_upgrade_failed"))
return auto_upgrade_result
@ -1022,8 +1025,8 @@ def _main_gui(viewer_mode: bool):
]
]
if not viewer_mode:
auto_upgrade_result = check_for_auto_upgrade(full_config)
if not viewer_mode and (version_dict["comp"] or _NPBACKUP_ALLOW_AUTOUPGRADE_DEBUG):
auto_upgrade_result = check_for_auto_upgrade(config_file, full_config)
else:
auto_upgrade_result = None
window = sg.Window(
@ -1179,6 +1182,7 @@ def _main_gui(viewer_mode: bool):
if event == "--ABOUT--":
about_gui(
version_string,
config_file,
full_config if not viewer_mode else None,
auto_upgrade_result,
)

View file

@ -164,6 +164,7 @@ def _check_new_version(
def auto_upgrader(
config_file: str,
upgrade_url: str,
username: str,
password: str,
@ -320,9 +321,17 @@ def auto_upgrader(
# Original arguments which were passed to this executable / script
# Except --auto-upgrade of course
filtered_args = []
has_config_arg = False
for arg in sys.argv[1:]:
if arg != "--auto-upgrade":
filtered_args.append(arg)
# We also need to inject config file as arg for GUI upgrades where config was loaded from GUI
if arg == "-c" or "--config-file" in arg:
has_config_arg = True
if not has_config_arg:
filtered_args.append("--config-file")
filtered_args.append(config_file)
original_args = " ".join(filtered_args)
if file_info["script"]["local_fs_path"]: