mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-20 10:26:19 +08:00
Reformat files with black
This commit is contained in:
parent
7f32359161
commit
e23797f97d
7 changed files with 99 additions and 38 deletions
|
@ -217,9 +217,13 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
|
|
||||||
parser.add_argument("--license", action="store_true", help="Show license")
|
parser.add_argument("--license", action="store_true", help="Show license")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--auto-upgrade", action="store_true", help="Auto upgrade NPBackup")
|
"--auto-upgrade", action="store_true", help="Auto upgrade NPBackup"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--upgrade-conf", action="store_true", help="Add new configuration elements after upgrade")
|
"--upgrade-conf",
|
||||||
|
action="store_true",
|
||||||
|
help="Add new configuration elements after upgrade",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.version:
|
if args.version:
|
||||||
|
|
|
@ -41,15 +41,19 @@ ENCRYPTED_OPTIONS = [
|
||||||
{"section": "options", "name": "server_password", "type": str},
|
{"section": "options", "name": "server_password", "type": str},
|
||||||
]
|
]
|
||||||
|
|
||||||
empty_config_dict = {"backup": {
|
empty_config_dict = {
|
||||||
|
"backup": {
|
||||||
"compression": "auto",
|
"compression": "auto",
|
||||||
"use_fs_snapshot": True,
|
"use_fs_snapshot": True,
|
||||||
"ignore_cloud_files": True,
|
"ignore_cloud_files": True,
|
||||||
"exclude_caches": True,
|
"exclude_caches": True,
|
||||||
"priority": "low",
|
"priority": "low",
|
||||||
}, "repo": {
|
},
|
||||||
"minimum_backup_age": 86400
|
"repo": {"minimum_backup_age": 86400},
|
||||||
}, "prometheus": {}, "env": {}, "options": {}}
|
"prometheus": {},
|
||||||
|
"env": {},
|
||||||
|
"options": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def decrypt_data(config_dict):
|
def decrypt_data(config_dict):
|
||||||
|
|
|
@ -255,7 +255,9 @@ class NPBackupRunner:
|
||||||
logger.warning("Bogus backup priority in config file.")
|
logger.warning("Bogus backup priority in config file.")
|
||||||
try:
|
try:
|
||||||
if self.config_dict["backup"]["ignore_cloud_files"]:
|
if self.config_dict["backup"]["ignore_cloud_files"]:
|
||||||
self.restic_runner.ignore_cloud_files = self.config_dict["backup"]["ignore_cloud_files"]
|
self.restic_runner.ignore_cloud_files = self.config_dict["backup"][
|
||||||
|
"ignore_cloud_files"
|
||||||
|
]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -20,12 +20,8 @@ logger = getLogger(__intname__)
|
||||||
def run_upgrade(config_dict):
|
def run_upgrade(config_dict):
|
||||||
try:
|
try:
|
||||||
auto_upgrade_upgrade_url = config_dict["options"]["server_url"]
|
auto_upgrade_upgrade_url = config_dict["options"]["server_url"]
|
||||||
auto_upgrade_username = config_dict["options"][
|
auto_upgrade_username = config_dict["options"]["server_username"]
|
||||||
"server_username"
|
auto_upgrade_password = config_dict["options"]["server_password"]
|
||||||
]
|
|
||||||
auto_upgrade_password = config_dict["options"][
|
|
||||||
"server_password"
|
|
||||||
]
|
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -324,11 +324,51 @@ def config_gui(config_dict: dict, config_file: str):
|
||||||
]
|
]
|
||||||
|
|
||||||
tab_group_layout = [
|
tab_group_layout = [
|
||||||
[sg.Tab(_t("config_gui.backup"), backup_col, font="helvetica 16", key="--tab-backup--", element_justification='C')],
|
[
|
||||||
[sg.Tab(_t("config_gui.backup_destination"),repo_col, font="helvetica 16", key="--tab-repo--", element_justification='C')],
|
sg.Tab(
|
||||||
[sg.Tab(_t("config_gui.prometheus_config"), prometheus_col, font="helvetica 16", key="--tab-prometheus--", element_justification='C')],
|
_t("config_gui.backup"),
|
||||||
[sg.Tab(_t("config_gui.environment_variables"), env_col, font="helvetica 16", key="--tab-env--", element_justification='C')],
|
backup_col,
|
||||||
[sg.Tab(_t("generic.options"), options_col, font="helvetica 16", key="--tab-options--", element_justification='C')],
|
font="helvetica 16",
|
||||||
|
key="--tab-backup--",
|
||||||
|
element_justification="C",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Tab(
|
||||||
|
_t("config_gui.backup_destination"),
|
||||||
|
repo_col,
|
||||||
|
font="helvetica 16",
|
||||||
|
key="--tab-repo--",
|
||||||
|
element_justification="C",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Tab(
|
||||||
|
_t("config_gui.prometheus_config"),
|
||||||
|
prometheus_col,
|
||||||
|
font="helvetica 16",
|
||||||
|
key="--tab-prometheus--",
|
||||||
|
element_justification="C",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Tab(
|
||||||
|
_t("config_gui.environment_variables"),
|
||||||
|
env_col,
|
||||||
|
font="helvetica 16",
|
||||||
|
key="--tab-env--",
|
||||||
|
element_justification="C",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Tab(
|
||||||
|
_t("generic.options"),
|
||||||
|
options_col,
|
||||||
|
font="helvetica 16",
|
||||||
|
key="--tab-options--",
|
||||||
|
element_justification="C",
|
||||||
|
)
|
||||||
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
layout = [
|
layout = [
|
||||||
|
@ -336,7 +376,6 @@ def config_gui(config_dict: dict, config_file: str):
|
||||||
[sg.Column(buttons, element_justification="C")],
|
[sg.Column(buttons, element_justification="C")],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
window = sg.Window(
|
window = sg.Window(
|
||||||
"Configuration",
|
"Configuration",
|
||||||
layout,
|
layout,
|
||||||
|
|
|
@ -55,21 +55,27 @@ def _about_gui(version_string: str, config_dict: dict) -> None:
|
||||||
layout = [
|
layout = [
|
||||||
[sg.Text(version_string)],
|
[sg.Text(version_string)],
|
||||||
[
|
[
|
||||||
sg.Button(_t("config_gui.auto_upgrade_launch"), key="autoupgrade", size=(12, 2))
|
sg.Button(
|
||||||
|
_t("config_gui.auto_upgrade_launch"), key="autoupgrade", size=(12, 2)
|
||||||
|
)
|
||||||
],
|
],
|
||||||
[sg.Text("License: GNU GPLv3")],
|
[sg.Text("License: GNU GPLv3")],
|
||||||
[sg.Multiline(license_content, size=(65, 20))],
|
[sg.Multiline(license_content, size=(65, 20))],
|
||||||
[sg.Button(_t("generic.accept"), key="exit")],
|
[sg.Button(_t("generic.accept"), key="exit")],
|
||||||
]
|
]
|
||||||
|
|
||||||
window = sg.Window(_t("generic.about"), layout, keep_on_top=True, element_justification='C')
|
window = sg.Window(
|
||||||
|
_t("generic.about"), layout, keep_on_top=True, element_justification="C"
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
event, _ = window.read()
|
event, _ = window.read()
|
||||||
if event in [sg.WIN_CLOSED, "exit"]:
|
if event in [sg.WIN_CLOSED, "exit"]:
|
||||||
break
|
break
|
||||||
elif event == "autoupgrade":
|
elif event == "autoupgrade":
|
||||||
result = sg.PopupOKCancel(_t("config_gui.auto_ugprade_will_quit"), keep_on_top=True)
|
result = sg.PopupOKCancel(
|
||||||
if result == 'OK':
|
_t("config_gui.auto_ugprade_will_quit"), keep_on_top=True
|
||||||
|
)
|
||||||
|
if result == "OK":
|
||||||
logger.info("Running GUI initiated upgrade")
|
logger.info("Running GUI initiated upgrade")
|
||||||
sub_result = run_upgrade(config_dict)
|
sub_result = run_upgrade(config_dict)
|
||||||
if sub_result:
|
if sub_result:
|
||||||
|
|
|
@ -48,11 +48,11 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
The for loop logic isn't straight simple, but allows file fallback
|
The for loop logic isn't straight simple, but allows file fallback
|
||||||
"""
|
"""
|
||||||
# file counter, local, home, or temp if not available
|
# file counter, local, home, or temp if not available
|
||||||
counter_file = 'npbackup.autoupgrade.log'
|
counter_file = "npbackup.autoupgrade.log"
|
||||||
|
|
||||||
def _write_count(file: str, counter: int) -> bool:
|
def _write_count(file: str, counter: int) -> bool:
|
||||||
try:
|
try:
|
||||||
with open(file, 'w') as fpw:
|
with open(file, "w") as fpw:
|
||||||
fpw.write(str(counter))
|
fpw.write(str(counter))
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -61,7 +61,7 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
|
|
||||||
def _get_count(file: str) -> Optional[int]:
|
def _get_count(file: str) -> Optional[int]:
|
||||||
try:
|
try:
|
||||||
with open(file, 'r') as fpr:
|
with open(file, "r") as fpr:
|
||||||
count = int(fpr.read())
|
count = int(fpr.read())
|
||||||
return count
|
return count
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -71,12 +71,13 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
logger.error("Bogus upgrade counter in %s", file)
|
logger.error("Bogus upgrade counter in %s", file)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
for file in [
|
||||||
|
os.path.join(CURRENT_DIR, counter_file),
|
||||||
for file in [os.path.join(CURRENT_DIR, counter_file), os.path.join(tempfile.gettempdir(), counter_file)]:
|
os.path.join(tempfile.gettempdir(), counter_file),
|
||||||
|
]:
|
||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
if _write_count(file, 1):
|
if _write_count(file, 1):
|
||||||
logger.debug('Initial upgrade counter written to %s', file)
|
logger.debug("Initial upgrade counter written to %s", file)
|
||||||
else:
|
else:
|
||||||
logger.debug("Cannot write to upgrade counter file %s", file)
|
logger.debug("Cannot write to upgrade counter file %s", file)
|
||||||
continue
|
continue
|
||||||
|
@ -175,7 +176,16 @@ def auto_upgrader(upgrade_url: str, username: str, password: str) -> bool:
|
||||||
# Actual upgrade process
|
# Actual upgrade process
|
||||||
new_executable = os.path.join(CURRENT_DIR, os.path.basename(CURRENT_EXECUTABLE))
|
new_executable = os.path.join(CURRENT_DIR, os.path.basename(CURRENT_EXECUTABLE))
|
||||||
cmd = 'del "{}" > "{}" && move "{}" "{}" >> "{}" && del "{}" >> "{}" && "{}" --upgrade-conf >> "{}"'.format(
|
cmd = 'del "{}" > "{}" && move "{}" "{}" >> "{}" && del "{}" >> "{}" && "{}" --upgrade-conf >> "{}"'.format(
|
||||||
CURRENT_EXECUTABLE, log_file, executable, log_file, new_executable, log_file, executable, log_file, new_executable, log_file
|
CURRENT_EXECUTABLE,
|
||||||
|
log_file,
|
||||||
|
executable,
|
||||||
|
log_file,
|
||||||
|
new_executable,
|
||||||
|
log_file,
|
||||||
|
executable,
|
||||||
|
log_file,
|
||||||
|
new_executable,
|
||||||
|
log_file,
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Launching upgrade. Current process will quit. Upgrade starts in %s seconds. Upgrade is done by OS logged in %s",
|
"Launching upgrade. Current process will quit. Upgrade starts in %s seconds. Upgrade is done by OS logged in %s",
|
||||||
|
|
Loading…
Add table
Reference in a new issue