mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-10 05:26:40 +08:00
WIP: auto upgrade client main integration
This commit is contained in:
parent
dcf2293ec0
commit
61fdecc837
3 changed files with 36 additions and 16 deletions
|
@ -61,4 +61,5 @@ options:
|
||||||
auto_upgrade: true
|
auto_upgrade: true
|
||||||
auto_upgrade_server_url:
|
auto_upgrade_server_url:
|
||||||
auto_upgrade_server_username:
|
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
|
|
@ -39,7 +39,7 @@ from npbackup.gui.main import main_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.path_helper import CURRENT_DIR, CURRENT_EXECUTABLE
|
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]
|
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")
|
logger.error("No configuration created via GUI")
|
||||||
sys.exit(7)
|
sys.exit(7)
|
||||||
|
|
||||||
if args.auto_upgrade:
|
# Try to perform an auto upgrade if needed
|
||||||
logger.info("Running user initiated auto upgrade")
|
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:
|
try:
|
||||||
upgrade_url = config_dict['options']['auto_upgrade_server_url']
|
auto_upgrade_upgrade_url = config_dict['options']['auto_upgrade_server_url']
|
||||||
username = config_dict['options']['auto_upgrade_server_username']
|
auto_upgrade_username = config_dict['options']['auto_upgrade_server_username']
|
||||||
password = config_dict['options']['auto_upgrade_server_password']
|
auto_upgrade_password = config_dict['options']['auto_upgrade_server_password']
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
logger.error("Missing auto upgrade info: %s", exc)
|
logger.error("Missing auto upgrade info: %s", exc)
|
||||||
sys.exit(23)
|
|
||||||
else:
|
else:
|
||||||
result = auto_upgrade(upgrade_url=upgrade_url, username=username, password=password)
|
if args.auto_upgrade:
|
||||||
if result:
|
logger.info("Running user initiated auto upgrade")
|
||||||
sys.exit(0)
|
|
||||||
else:
|
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
|
dry_run = False
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
|
|
|
@ -36,7 +36,15 @@ def sha256sum_data(data):
|
||||||
return sha256.hexdigest()
|
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
|
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()
|
is_nuitka = "__compiled__" in globals()
|
||||||
if not is_nuitka:
|
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
|
return True
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue