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
92a9700a29
commit
31740a1d07
4 changed files with 53 additions and 30 deletions
|
@ -412,7 +412,9 @@ def expand_units(object_config: dict, unexpand: bool = False) -> dict:
|
||||||
return BytesConverter(0).human_iec_bits
|
return BytesConverter(0).human_iec_bits
|
||||||
return BytesConverter(0)
|
return BytesConverter(0)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning(f"Cannot parse bytes value {key}:\"{value}\", setting to zero")
|
logger.warning(
|
||||||
|
f'Cannot parse bytes value {key}:"{value}", setting to zero'
|
||||||
|
)
|
||||||
if unexpand:
|
if unexpand:
|
||||||
return BytesConverter(0).human_iec_bits
|
return BytesConverter(0).human_iec_bits
|
||||||
return BytesConverter(0)
|
return BytesConverter(0)
|
||||||
|
|
|
@ -571,7 +571,9 @@ def _main_gui(viewer_mode: bool):
|
||||||
return full_config, config_file
|
return full_config, config_file
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def get_config(config_file: str = None, window: sg.Window = None, repo_name: str = "default") -> Tuple:
|
def get_config(
|
||||||
|
config_file: str = None, window: sg.Window = None, repo_name: str = "default"
|
||||||
|
) -> Tuple:
|
||||||
full_config, config_file = get_config_file(config_file=config_file)
|
full_config, config_file = get_config_file(config_file=config_file)
|
||||||
if full_config and config_file:
|
if full_config and config_file:
|
||||||
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
||||||
|
@ -651,7 +653,6 @@ def _main_gui(viewer_mode: bool):
|
||||||
else:
|
else:
|
||||||
config_file = Path(f"{CURRENT_DIR}/npbackup.conf")
|
config_file = Path(f"{CURRENT_DIR}/npbackup.conf")
|
||||||
|
|
||||||
|
|
||||||
# Let's try to read standard restic repository env variables
|
# Let's try to read standard restic repository env variables
|
||||||
viewer_repo_uri = os.environ.get("RESTIC_REPOSITORY", None)
|
viewer_repo_uri = os.environ.get("RESTIC_REPOSITORY", None)
|
||||||
viewer_repo_password = os.environ.get("RESTIC_PASSWORD", None)
|
viewer_repo_password = os.environ.get("RESTIC_PASSWORD", None)
|
||||||
|
@ -674,7 +675,6 @@ def _main_gui(viewer_mode: bool):
|
||||||
repo_list,
|
repo_list,
|
||||||
) = get_config(config_file=config_file, repo_name=args.repo_name)
|
) = get_config(config_file=config_file, repo_name=args.repo_name)
|
||||||
|
|
||||||
|
|
||||||
right_click_menu = ["", [_t("generic.destination")]]
|
right_click_menu = ["", [_t("generic.destination")]]
|
||||||
headings = [
|
headings = [
|
||||||
"ID ",
|
"ID ",
|
||||||
|
|
|
@ -517,7 +517,10 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
# TODO exclude encrypted env vars
|
# TODO exclude encrypted env vars
|
||||||
if value == ENCRYPTED_DATA_PLACEHOLDER:
|
if value == ENCRYPTED_DATA_PLACEHOLDER:
|
||||||
continue
|
continue
|
||||||
if not isinstance(key, str) or (isinstance(key, str) and (not "." in key and not key in ("repo_uri", "repo_group"))):
|
if not isinstance(key, str) or (
|
||||||
|
isinstance(key, str)
|
||||||
|
and (not "." in key and not key in ("repo_uri", "repo_group"))
|
||||||
|
):
|
||||||
# Don't bother with keys that don't contain with "." since they're not in the YAML config file
|
# Don't bother with keys that don't contain with "." since they're not in the YAML config file
|
||||||
# but are most probably for GUI events
|
# but are most probably for GUI events
|
||||||
# Still, we need to handle repo_uri and repo_group which do not have dot notations since they're root keys
|
# Still, we need to handle repo_uri and repo_group which do not have dot notations since they're root keys
|
||||||
|
@ -568,8 +571,13 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
|
|
||||||
# Special case for nested retention_policy dict which may not exist, we need to create it
|
# Special case for nested retention_policy dict which may not exist, we need to create it
|
||||||
if key.startswith("repo_opts.retention_policy"):
|
if key.startswith("repo_opts.retention_policy"):
|
||||||
if not full_config.g(f"{object_type}s.{object_name}.repo_opts.retention_policy"):
|
if not full_config.g(
|
||||||
full_config.s(f"{object_type}s.{object_name}.repo_opts.retention_policy", CommentedMap())
|
f"{object_type}s.{object_name}.repo_opts.retention_policy"
|
||||||
|
):
|
||||||
|
full_config.s(
|
||||||
|
f"{object_type}s.{object_name}.repo_opts.retention_policy",
|
||||||
|
CommentedMap(),
|
||||||
|
)
|
||||||
|
|
||||||
if object_group:
|
if object_group:
|
||||||
inheritance_key = f"groups.{object_group}.{key}"
|
inheritance_key = f"groups.{object_group}.{key}"
|
||||||
|
@ -585,9 +593,9 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Debug WIP
|
# Debug WIP
|
||||||
#if object_group:
|
# if object_group:
|
||||||
# inherited = full_config.g(inheritance_key)
|
# inherited = full_config.g(inheritance_key)
|
||||||
#else:
|
# else:
|
||||||
# inherited = False
|
# inherited = False
|
||||||
|
|
||||||
# Don't bother to update empty strings, empty lists and None
|
# Don't bother to update empty strings, empty lists and None
|
||||||
|
@ -599,9 +607,9 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
|
|
||||||
# Finally, update the config dictionary
|
# Finally, update the config dictionary
|
||||||
# Debug WIP
|
# Debug WIP
|
||||||
#if object_type == "group":
|
# if object_type == "group":
|
||||||
# print(f"UPDATING {active_object_key} curr={current_value} new={value}")
|
# print(f"UPDATING {active_object_key} curr={current_value} new={value}")
|
||||||
#else:
|
# else:
|
||||||
# print(f"UPDATING {active_object_key} curr={current_value} inherited={inherited} new={value}")
|
# print(f"UPDATING {active_object_key} curr={current_value} inherited={inherited} new={value}")
|
||||||
full_config.s(active_object_key, value)
|
full_config.s(active_object_key, value)
|
||||||
return full_config
|
return full_config
|
||||||
|
@ -756,8 +764,18 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
[
|
[
|
||||||
sg.Column(
|
sg.Column(
|
||||||
[
|
[
|
||||||
[sg.Button("+", key="--ADD-BACKUP-TAG--", size=(3, 1))],
|
[
|
||||||
[sg.Button("-", key="--REMOVE-BACKUP-TAG--", size=(3, 1))],
|
sg.Button(
|
||||||
|
"+", key="--ADD-BACKUP-TAG--", size=(3, 1)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
sg.Button(
|
||||||
|
"-",
|
||||||
|
key="--REMOVE-BACKUP-TAG--",
|
||||||
|
size=(3, 1),
|
||||||
|
)
|
||||||
|
],
|
||||||
],
|
],
|
||||||
pad=0,
|
pad=0,
|
||||||
size=(40, 80),
|
size=(40, 80),
|
||||||
|
@ -1267,23 +1285,21 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Checkbox(_t("config_gui.keep_within"), key="repo_opts.retention_policy.keep_within", size=(40, 1)),
|
sg.Checkbox(
|
||||||
|
_t("config_gui.keep_within"),
|
||||||
|
key="repo_opts.retention_policy.keep_within",
|
||||||
|
size=(40, 1),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Text(_t("config_gui.keep_within_explanation"), size=(40, 1)),
|
sg.Text(_t("config_gui.keep_within_explanation"), size=(40, 1)),
|
||||||
],
|
],
|
||||||
[
|
[sg.HorizontalSeparator()],
|
||||||
sg.HorizontalSeparator()
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
sg.Column(
|
sg.Column(
|
||||||
[
|
[
|
||||||
[sg.Button("+", key="--ADD-RETENTION-TAG--", size=(3, 1))],
|
[sg.Button("+", key="--ADD-RETENTION-TAG--", size=(3, 1))],
|
||||||
[
|
[sg.Button("-", key="--REMOVE-RETENTION-TAG--", size=(3, 1))],
|
||||||
sg.Button(
|
|
||||||
"-", key="--REMOVE-RETENTION-TAG--", size=(3, 1)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
pad=0,
|
pad=0,
|
||||||
),
|
),
|
||||||
|
@ -1305,9 +1321,7 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
expand_x=True,
|
expand_x=True,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[sg.HorizontalSeparator()],
|
||||||
sg.HorizontalSeparator()
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
sg.Text(_t("config_gui.optional_ntp_server_uri"), size=(40, 1)),
|
sg.Text(_t("config_gui.optional_ntp_server_uri"), size=(40, 1)),
|
||||||
sg.Input(
|
sg.Input(
|
||||||
|
@ -1315,7 +1329,6 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
prometheus_col = [
|
prometheus_col = [
|
||||||
[sg.Text(_t("config_gui.available_variables"))],
|
[sg.Text(_t("config_gui.available_variables"))],
|
||||||
|
@ -1521,7 +1534,7 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
key="--tab-retention--",
|
key="--tab-retention--",
|
||||||
expand_x=True,
|
expand_x=True,
|
||||||
expand_y=True,
|
expand_y=True,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Tab(
|
sg.Tab(
|
||||||
|
@ -1922,7 +1935,9 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
)
|
)
|
||||||
# NPF-SEC-00009
|
# NPF-SEC-00009
|
||||||
env_manager_password = os.environ.get("NPBACKUP_MANAGER_PASSWORD", None)
|
env_manager_password = os.environ.get("NPBACKUP_MANAGER_PASSWORD", None)
|
||||||
if (env_manager_password and env_manager_password == manager_password) or ask_manager_password(manager_password):
|
if (
|
||||||
|
env_manager_password and env_manager_password == manager_password
|
||||||
|
) or ask_manager_password(manager_password):
|
||||||
update_object_gui(values["-OBJECT-SELECT-"], unencrypted=True)
|
update_object_gui(values["-OBJECT-SELECT-"], unencrypted=True)
|
||||||
update_global_gui(full_config, unencrypted=True)
|
update_global_gui(full_config, unencrypted=True)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -550,7 +550,10 @@ class ResticRunner:
|
||||||
live_output = self.live_output
|
live_output = self.live_output
|
||||||
self.live_output = False
|
self.live_output = False
|
||||||
self._is_init, output = self.executor(
|
self._is_init, output = self.executor(
|
||||||
cmd, timeout=FAST_COMMANDS_TIMEOUT, errors_allowed=True, no_output_queues=True
|
cmd,
|
||||||
|
timeout=FAST_COMMANDS_TIMEOUT,
|
||||||
|
errors_allowed=True,
|
||||||
|
no_output_queues=True,
|
||||||
)
|
)
|
||||||
self.live_output = live_output
|
self.live_output = live_output
|
||||||
if not self._is_init:
|
if not self._is_init:
|
||||||
|
@ -931,7 +934,10 @@ class ResticRunner:
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
result, output = self.executor(cmd)
|
result, output = self.executor(cmd)
|
||||||
if result:
|
if result:
|
||||||
self.write_logs(f"successfully forgot {'using retention policy' if policy else 'snapshots ' + snapshots}", level="info")
|
self.write_logs(
|
||||||
|
f"successfully forgot {'using retention policy' if policy else 'snapshots ' + snapshots}",
|
||||||
|
level="info",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.write_logs(f"Forget failed\n{output}", level="error")
|
self.write_logs(f"Forget failed\n{output}", level="error")
|
||||||
batch_result = False
|
batch_result = False
|
||||||
|
|
Loading…
Add table
Reference in a new issue