mirror of
https://github.com/netinvent/npbackup.git
synced 2025-12-19 22:49:09 +08:00
GUI: Allow having no default repo / group
This commit is contained in:
parent
aa447a1cb9
commit
a0122a04f5
3 changed files with 51 additions and 28 deletions
|
|
@ -737,7 +737,7 @@ def get_repo_config(
|
||||||
logger.error(f"No repo with name {repo_name} found in config")
|
logger.error(f"No repo with name {repo_name} found in config")
|
||||||
return None, None
|
return None, None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error(f"No repo with name {repo_name} found in config")
|
logger.error(f"No repo key with name {repo_name} found in config")
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
# Merge prometheus global settings with repo settings
|
# Merge prometheus global settings with repo settings
|
||||||
|
|
@ -766,9 +766,14 @@ def get_repo_config(
|
||||||
repo_group = full_config.g(f"repos.{repo_name}.repo_group")
|
repo_group = full_config.g(f"repos.{repo_name}.repo_group")
|
||||||
group_config = full_config.g(f"groups.{repo_group}")
|
group_config = full_config.g(f"groups.{repo_group}")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error(f"Repo {repo_name} has no group, reset to default")
|
logger.error(f"Repo {repo_name} has no group, reset to first available group")
|
||||||
full_config.s(f"repos.{repo_name}.repo_group", "default_group")
|
try:
|
||||||
group_config = full_config.g("groups.default_group")
|
first_group = get_group_list()[0]
|
||||||
|
full_config.s(f"repos.{repo_name}.repo_group", first_group)
|
||||||
|
group_config = full_config.g(f"groups.{first_group}")
|
||||||
|
except IndexError:
|
||||||
|
logger.error("No group found in config")
|
||||||
|
group_config = {}
|
||||||
|
|
||||||
repo_config.s("name", repo_name)
|
repo_config.s("name", repo_name)
|
||||||
repo_config, config_inheritance = inherit_group_settings(repo_config, group_config)
|
repo_config, config_inheritance = inherit_group_settings(repo_config, group_config)
|
||||||
|
|
|
||||||
|
|
@ -748,15 +748,24 @@ def _main_gui(viewer_mode: bool):
|
||||||
return full_config, config_file
|
return full_config, config_file
|
||||||
|
|
||||||
def get_config(
|
def get_config(
|
||||||
config_file: str = None, window: sg.Window = None, repo_name: str = "default"
|
config_file: str = None, window: sg.Window = None, repo_name: str = None
|
||||||
) -> Tuple:
|
) -> 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:
|
||||||
|
# If no repo name is given, just show first one
|
||||||
|
try:
|
||||||
|
if not repo_name:
|
||||||
|
repo_name = npbackup.configuration.get_repo_list(full_config)[0]
|
||||||
repo_config, _ = npbackup.configuration.get_repo_config(
|
repo_config, _ = npbackup.configuration.get_repo_config(
|
||||||
full_config, repo_name=repo_name
|
full_config, repo_name=repo_name
|
||||||
)
|
)
|
||||||
backup_destination = _t("main_gui.local_folder")
|
backup_destination = _t("main_gui.local_folder")
|
||||||
repo_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
repo_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
||||||
|
except IndexError:
|
||||||
|
repo_config = None
|
||||||
|
backup_destination = "None"
|
||||||
|
repo_type = "None"
|
||||||
|
repo_uri = "None"
|
||||||
else:
|
else:
|
||||||
repo_config = None
|
repo_config = None
|
||||||
backup_destination = "None"
|
backup_destination = "None"
|
||||||
|
|
@ -806,7 +815,7 @@ def _main_gui(viewer_mode: bool):
|
||||||
"--repo-name",
|
"--repo-name",
|
||||||
dest="repo_name",
|
dest="repo_name",
|
||||||
type=str,
|
type=str,
|
||||||
default="default",
|
default=None,
|
||||||
required=False,
|
required=False,
|
||||||
help="Name of the repository to work with. Defaults to 'default'",
|
help="Name of the repository to work with. Defaults to 'default'",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,10 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
) -> Tuple[str, str]:
|
) -> Tuple[str, str]:
|
||||||
object_list = get_objects()
|
object_list = get_objects()
|
||||||
if not object_name or not object_type:
|
if not object_name or not object_type:
|
||||||
|
if len(object_list) > 0:
|
||||||
obj = object_list[0]
|
obj = object_list[0]
|
||||||
|
else:
|
||||||
|
obj = None
|
||||||
else:
|
else:
|
||||||
# We need to remove the "s" and the end if we want our combobox name to be usable later
|
# We need to remove the "s" and the end if we want our combobox name to be usable later
|
||||||
obj = f"{object_type.rstrip('s').capitalize()}: {object_name}"
|
obj = f"{object_type.rstrip('s').capitalize()}: {object_name}"
|
||||||
|
|
@ -232,20 +235,21 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
Extracts selected object from combobox
|
Extracts selected object from combobox
|
||||||
Returns object type and name
|
Returns object type and name
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
if combo_value.startswith("Repo: "):
|
if combo_value.startswith("Repo: "):
|
||||||
object_type = "repos"
|
object_type = "repos"
|
||||||
object_name = combo_value[len("Repo: ") :]
|
object_name = combo_value[len("Repo: ") :]
|
||||||
elif combo_value.startswith("Group: "):
|
elif combo_value.startswith("Group: "):
|
||||||
object_type = "groups"
|
object_type = "groups"
|
||||||
object_name = combo_value[len("Group: ") :]
|
object_name = combo_value[len("Group: ") :]
|
||||||
else:
|
return object_type, object_name
|
||||||
|
except (AttributeError, UnboundLocalError):
|
||||||
object_type = None
|
object_type = None
|
||||||
object_name = None
|
object_name = None
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Could not obtain object_type and object_name from {combo_value}"
|
f"Could not obtain object_type and object_name from {combo_value}"
|
||||||
)
|
)
|
||||||
|
return None, None
|
||||||
return object_type, object_name
|
|
||||||
|
|
||||||
def update_source_layout(source_type: str):
|
def update_source_layout(source_type: str):
|
||||||
if source_type == "stdin_from_command":
|
if source_type == "stdin_from_command":
|
||||||
|
|
@ -571,7 +575,11 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
|
|
||||||
# Load fist available repo or group if none given
|
# Load fist available repo or group if none given
|
||||||
if not object_name:
|
if not object_name:
|
||||||
|
try:
|
||||||
object_type, object_name = get_object_from_combo(get_objects()[0])
|
object_type, object_name = get_object_from_combo(get_objects()[0])
|
||||||
|
except IndexError:
|
||||||
|
object_type = None
|
||||||
|
object_name = None
|
||||||
|
|
||||||
# First we need to clear the whole GUI to reload new values
|
# First we need to clear the whole GUI to reload new values
|
||||||
for key in window.AllKeysDict:
|
for key in window.AllKeysDict:
|
||||||
|
|
@ -622,6 +630,7 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
object_config = None
|
object_config = None
|
||||||
config_inheritance = None
|
config_inheritance = None
|
||||||
logger.error(f"Bogus object {object_type}.{object_name}")
|
logger.error(f"Bogus object {object_type}.{object_name}")
|
||||||
|
return full_config
|
||||||
|
|
||||||
# Now let's iter over the whole config object and update keys accordingly
|
# Now let's iter over the whole config object and update keys accordingly
|
||||||
iter_over_config(
|
iter_over_config(
|
||||||
|
|
@ -2323,12 +2332,12 @@ Google Cloud storage: GOOGLE_PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS\n\
|
||||||
continue
|
continue
|
||||||
if event == "-OBJECT-DELETE-":
|
if event == "-OBJECT-DELETE-":
|
||||||
object_type, object_name = get_object_from_combo(values["-OBJECT-SELECT-"])
|
object_type, object_name = get_object_from_combo(values["-OBJECT-SELECT-"])
|
||||||
if object_type == "repos" and object_name == "default":
|
# if object_type == "repos" and object_name == "default":
|
||||||
sg.popup_error(_t("config_gui.cannot_delete_default_repo"))
|
# sg.popup_error(_t("config_gui.cannot_delete_default_repo"))
|
||||||
continue
|
# continue
|
||||||
if object_type == "groups" and object_name == "default_group":
|
# if object_type == "groups" and object_name == "default_group":
|
||||||
sg.popup_error(_t("config_gui.cannot_delete_default_group"))
|
# sg.popup_error(_t("config_gui.cannot_delete_default_group"))
|
||||||
continue
|
# continue
|
||||||
full_config = delete_object(full_config, values["-OBJECT-SELECT-"])
|
full_config = delete_object(full_config, values["-OBJECT-SELECT-"])
|
||||||
current_object_type, current_object_name = update_object_selector()
|
current_object_type, current_object_name = update_object_selector()
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue