Reformat files with black

This commit is contained in:
Orsiris de Jong 2023-02-02 11:39:15 +01:00
parent 525e7fce49
commit a3bf71ef6c
5 changed files with 60 additions and 57 deletions

View file

@ -39,7 +39,7 @@ ENCRYPTED_OPTIONS = [
{"section": "prometheus", "name": "http_password", "type": str}, {"section": "prometheus", "name": "http_password", "type": str},
{"section": "options", "name": "server_username", "type": str}, {"section": "options", "name": "server_username", "type": str},
{"section": "options", "name": "server_password", "type": str}, {"section": "options", "name": "server_password", "type": str},
{"section": "options", "name": "backup_admin_password", "type": str} {"section": "options", "name": "backup_admin_password", "type": str},
] ]
empty_config_dict = { empty_config_dict = {
@ -53,9 +53,7 @@ empty_config_dict = {
"repo": {"minimum_backup_age": 1440}, "repo": {"minimum_backup_age": 1440},
"prometheus": {}, "prometheus": {},
"env": {}, "env": {},
"options": { "options": {"backup_admin_password": DEFAULT_BACKUP_ADMIN_PASSWORD},
"backup_admin_password": DEFAULT_BACKUP_ADMIN_PASSWORD
},
} }

View file

@ -24,7 +24,7 @@ logger = getLogger(__intname__)
def ask_backup_admin_password(config_dict) -> bool: def ask_backup_admin_password(config_dict) -> bool:
try: try:
backup_admin_password = config_dict['options']['backup_admin_password'] backup_admin_password = config_dict["options"]["backup_admin_password"]
except KeyError: except KeyError:
backup_admin_password = configuration.DEFAULT_BACKUP_ADMIN_PASSWORD backup_admin_password = configuration.DEFAULT_BACKUP_ADMIN_PASSWORD
if ( if (
@ -333,14 +333,12 @@ def config_gui(config_dict: dict, config_file: str):
sg.Text(_t("config_gui.auto_upgrade_interval"), size=(30, 1)), sg.Text(_t("config_gui.auto_upgrade_interval"), size=(30, 1)),
sg.Input(key="options---interval", size=(50, 1)), sg.Input(key="options---interval", size=(50, 1)),
], ],
[sg.HorizontalSeparator(key='sep')], [sg.HorizontalSeparator(key="sep")],
[ [
sg.Text(_t("config_gui.enter_backup_admin_password"), size=(30, 1)), sg.Text(_t("config_gui.enter_backup_admin_password"), size=(30, 1)),
sg.Input(key="backup_admin_password", size=(50, 1), password_char='*'), sg.Input(key="backup_admin_password", size=(50, 1), password_char="*"),
], ],
[ [sg.Button(_t("generic.change"), key="change_backup_admin_password")],
sg.Button(_t("generic.change"), key="change_backup_admin_password")
]
] ]
scheduled_task_col = [ scheduled_task_col = [
@ -348,11 +346,9 @@ def config_gui(config_dict: dict, config_file: str):
sg.Text(_t("config_gui.create_scheduled_task_every")), sg.Text(_t("config_gui.create_scheduled_task_every")),
sg.Input(key="scheduled_task_interval", size=(4, 1)), sg.Input(key="scheduled_task_interval", size=(4, 1)),
sg.Text(_t("generic.minutes")), sg.Text(_t("generic.minutes")),
sg.Button(_t("generic.create"), key="create_task") sg.Button(_t("generic.create"), key="create_task"),
], ],
[ [sg.Text(_t("config_gui.scheduled_task_explanation"))],
sg.Text(_t("config_gui.scheduled_task_explanation"))
]
] ]
buttons = [ buttons = [
@ -456,8 +452,10 @@ def config_gui(config_dict: dict, config_file: str):
if ask_backup_admin_password(config_dict): if ask_backup_admin_password(config_dict):
update_gui(window, config_dict, unencrypted=True) update_gui(window, config_dict, unencrypted=True)
if event == "create_task": if event == "create_task":
if os.name == 'nt': if os.name == "nt":
result = create_scheduled_task(CURRENT_EXECUTABLE, values['scheduled_task_interval']) result = create_scheduled_task(
CURRENT_EXECUTABLE, values["scheduled_task_interval"]
)
if result: if result:
sg.Popup(_t("config_gui.scheduled_task_creation_success")) sg.Popup(_t("config_gui.scheduled_task_creation_success"))
else: else:
@ -466,7 +464,9 @@ def config_gui(config_dict: dict, config_file: str):
sg.PopupError(_t("config_gui.scheduled_task_creation_failure")) sg.PopupError(_t("config_gui.scheduled_task_creation_failure"))
if event == "change_backup_admin_password": if event == "change_backup_admin_password":
if ask_backup_admin_password(config_dict): if ask_backup_admin_password(config_dict):
config_dict['options']['backup_admin_password'] = values['backup_admin_password'] config_dict["options"]["backup_admin_password"] = values[
"backup_admin_password"
]
sg.Popup(_t("config_gui.password_updated_please_save")) sg.Popup(_t("config_gui.password_updated_please_save"))
window.close() window.close()
return config_dict return config_dict

View file

@ -47,24 +47,22 @@ 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
try: try:
upgrade_server = config_dict['options']["server_url"] upgrade_server = config_dict["options"]["server_url"]
except KeyError: except KeyError:
upgrade_server = None upgrade_server = None
if upgrade_server: if upgrade_server:
if check_new_version(config_dict): if check_new_version(config_dict):
new_version = [ new_version = [
sg.Button( sg.Button(
_t("config_gui.auto_upgrade_launch"), key="autoupgrade", size=(12, 2) _t("config_gui.auto_upgrade_launch"),
key="autoupgrade",
size=(12, 2),
) )
] ]
else: else:
new_version = [ new_version = [sg.Text(_t("generic.is_uptodate"))]
sg.Text(_t("generic.is_uptodate"))
]
else: else:
new_version = [ new_version = [sg.Text(_t("config_gui.auto_upgrade_disabled"))]
sg.Text(_t("config_gui.auto_upgrade_disabled"))
]
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()
@ -80,7 +78,11 @@ def _about_gui(version_string: str, config_dict: dict) -> None:
] ]
window = sg.Window( window = sg.Window(
_t("generic.about"), layout, keep_on_top=True, element_justification="C", finalize=True _t("generic.about"),
layout,
keep_on_top=True,
element_justification="C",
finalize=True,
) )
while True: while True:

View file

@ -152,6 +152,7 @@ def _check_new_version(upgrade_url: str, username: str, password: str) -> bool:
) )
return False return False
def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool: def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
""" """
Auto upgrade binary NPBackup distributions Auto upgrade binary NPBackup distributions
@ -197,37 +198,39 @@ def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
logger.info("Logging upgrade to %s", log_file) logger.info("Logging upgrade to %s", log_file)
# Actual upgrade process # Actual upgrade process
backup_executable = CURRENT_EXECUTABLE + '.old' backup_executable = CURRENT_EXECUTABLE + ".old"
# Inplace upgrade script, gets executed after main program has exited # Inplace upgrade script, gets executed after main program has exited
if os.name == 'nt': if os.name == "nt":
cmd = \ cmd = (
f'echo "Launching upgrade" >> {log_file} 2>&1 && ' \ f'echo "Launching upgrade" >> {log_file} 2>&1 && '
f'del /F /Q "{backup_executable}" >> NUL 2>&1 && ' \ f'del /F /Q "{backup_executable}" >> NUL 2>&1 && '
f'echo "Renaming earlier executable from {CURRENT_EXECUTABLE} to {backup_executable}" >> {log_file} 2>&1 && ' \ f'echo "Renaming earlier executable from {CURRENT_EXECUTABLE} to {backup_executable}" >> {log_file} 2>&1 && '
f'move /Y "{CURRENT_EXECUTABLE}" "{backup_executable}" >> {log_file} 2>&1 && ' \ f'move /Y "{CURRENT_EXECUTABLE}" "{backup_executable}" >> {log_file} 2>&1 && '
f'echo "Copying new executable from {downloaded_executable} to {CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'echo "Copying new executable from {downloaded_executable} to {CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'copy /Y "{downloaded_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'copy /Y "{downloaded_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'del "{downloaded_executable}" >> {log_file} 2>&1 && ' \ f'del "{downloaded_executable}" >> {log_file} 2>&1 && '
f'echo "Loading new executable" >> {log_file} 2>&1 && ' \ f'echo "Loading new executable" >> {log_file} 2>&1 && '
f'"{CURRENT_EXECUTABLE}" --upgrade-conf >> {log_file} 2>&1 || ' \ f'"{CURRENT_EXECUTABLE}" --upgrade-conf >> {log_file} 2>&1 || '
f'echo "New executable failed. Rolling back" >> {log_file} 2>&1 && ' \ f'echo "New executable failed. Rolling back" >> {log_file} 2>&1 && '
f'del /F /Q "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'del /F /Q "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'move /Y "{backup_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1' f'move /Y "{backup_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1'
)
else: else:
cmd = \ cmd = (
f'echo "Launching upgrade" >> {log_file} 2>&1 && ' \ f'echo "Launching upgrade" >> {log_file} 2>&1 && '
f'rm -f "{backup_executable}" >> /dev/null 2>&1 && ' \ f'rm -f "{backup_executable}" >> /dev/null 2>&1 && '
f'echo "Renaming earlier executable from {CURRENT_EXECUTABLE} to {backup_executable}" >> {log_file} 2>&1 && ' \ f'echo "Renaming earlier executable from {CURRENT_EXECUTABLE} to {backup_executable}" >> {log_file} 2>&1 && '
f'mv -f "{CURRENT_EXECUTABLE}" "{backup_executable}" >> {log_file} 2>&1 && ' \ f'mv -f "{CURRENT_EXECUTABLE}" "{backup_executable}" >> {log_file} 2>&1 && '
f'echo "Copying new executable from {downloaded_executable} to {CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'echo "Copying new executable from {downloaded_executable} to {CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'alias cp=cp && cp -f "{downloaded_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'alias cp=cp && cp -f "{downloaded_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'rm -f "{downloaded_executable}" >> {log_file} 2>&1 && ' \ f'rm -f "{downloaded_executable}" >> {log_file} 2>&1 && '
f'echo "Loading new executable" >> {log_file} 2>&1 && ' \ f'echo "Loading new executable" >> {log_file} 2>&1 && '
f'"{CURRENT_EXECUTABLE}" --upgrade-conf >> {log_file} 2>&1 || ' \ f'"{CURRENT_EXECUTABLE}" --upgrade-conf >> {log_file} 2>&1 || '
f'echo "New executable failed. Rolling back" >> {log_file} 2>&1 && ' \ f'echo "New executable failed. Rolling back" >> {log_file} 2>&1 && '
f'rm -f "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && ' \ f'rm -f "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1 && '
f'mv -f "{backup_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1' f'mv -f "{backup_executable}" "{CURRENT_EXECUTABLE}" >> {log_file} 2>&1'
)
# We still need to unregister previous kill_childs function se we can actually make the upgrade happen # We still need to unregister previous kill_childs function se we can actually make the upgrade happen
atexit.unregister(kill_childs) atexit.unregister(kill_childs)