WIP: auto upgrade client main integration

This commit is contained in:
Orsiris de Jong 2023-02-01 01:50:45 +01:00
parent dcf2293ec0
commit 61fdecc837
3 changed files with 36 additions and 16 deletions

View file

@ -61,4 +61,5 @@ options:
auto_upgrade: true
auto_upgrade_server_url:
auto_upgrade_server_username:
auto_upgrade_server_password:
auto_upgrade_server_password:
auto_upgrade_interval: 10 # every 10 NPBackup runs, we'll try an autoupgrade

View file

@ -39,7 +39,7 @@ from npbackup.gui.main import main_gui
from npbackup.core.runner import NPBackupRunner
from npbackup.core.i18n_helper import _t
from npbackup.path_helper import CURRENT_DIR, CURRENT_EXECUTABLE
from npbackup.upgrade_client.upgrader import auto_upgrade
from npbackup.upgrade_client.upgrader import auto_upgrader, need_upgrade
del sys.path[0]
@ -297,23 +297,34 @@ This is free software, and you are welcome to redistribute it under certain cond
logger.error("No configuration created via GUI")
sys.exit(7)
if args.auto_upgrade:
logger.info("Running user initiated auto upgrade")
# Try to perform an auto upgrade if needed
try:
auto_upgrade = config_dict['options']['auto_upgrade']
except KeyError:
auto_upgrade = True
try:
auto_upgrade_interval = config_dict['options']['auto_upgrade_interval']
except KeyError:
auto_upgrade_interval = 10
if (auto_upgrade and need_upgrade(auto_upgrade_interval)) or args.auto_upgrade:
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']
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", exc)
sys.exit(23)
else:
result = auto_upgrade(upgrade_url=upgrade_url, username=username, password=password)
if result:
sys.exit(0)
if args.auto_upgrade:
logger.info("Running user initiated auto upgrade")
else:
sys.exit(23)
logger.info("Running program initiated auto upgrade")
result = auto_upgrader(upgrade_url=auto_upgrade_upgrade_url, username=auto_upgrade_username, password=auto_upgrade_password)
if args.auto_upgrade:
if result:
sys.exit(0)
else:
sys.exit(23)
dry_run = False
if args.dry_run:

View file

@ -36,7 +36,15 @@ def sha256sum_data(data):
return sha256.hexdigest()
def auto_upgrade(upgrade_url: str, username: str, password: str) -> bool:
def need_upgrade(upgrade_interval: int) -> bool:
"""
Basic counter which allows an upgrade only every X times this is called so failed operations won't end in an endless upgrade loop
"""
# file counter, local, home, or temp if not available
return True # WIP
def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
"""
Auto upgrade binary NPBackup distributions
@ -45,7 +53,7 @@ def auto_upgrade(upgrade_url: str, username: str, password: str) -> bool:
"""
is_nuitka = "__compiled__" in globals()
if not is_nuitka:
logger.info("No upgrade necessary")
logger.info("Auto upgrade will only upgrade compiled verions. Please use 'pip install --upgrade npbackup' instead")
return True
logger.info("Upgrade server is %s", upgrade_url)
requestor = Requestor(upgrade_url, username, password)