GUI: Allow having no default repo / group

This commit is contained in:
deajan 2025-02-17 00:15:08 +01:00
parent aa447a1cb9
commit a0122a04f5
3 changed files with 51 additions and 28 deletions

View file

@ -737,7 +737,7 @@ def get_repo_config(
logger.error(f"No repo with name {repo_name} found in config")
return None, None
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
# 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")
group_config = full_config.g(f"groups.{repo_group}")
except KeyError:
logger.error(f"Repo {repo_name} has no group, reset to default")
full_config.s(f"repos.{repo_name}.repo_group", "default_group")
group_config = full_config.g("groups.default_group")
logger.error(f"Repo {repo_name} has no group, reset to first available group")
try:
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, config_inheritance = inherit_group_settings(repo_config, group_config)

View file

@ -748,15 +748,24 @@ def _main_gui(viewer_mode: bool):
return full_config, config_file
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:
full_config, config_file = get_config_file(config_file=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(
full_config, repo_name=repo_name
)
backup_destination = _t("main_gui.local_folder")
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:
repo_config = None
backup_destination = "None"
@ -806,7 +815,7 @@ def _main_gui(viewer_mode: bool):
"--repo-name",
dest="repo_name",
type=str,
default="default",
default=None,
required=False,
help="Name of the repository to work with. Defaults to 'default'",
)

View file

@ -213,7 +213,10 @@ def config_gui(full_config: dict, config_file: str):
) -> Tuple[str, str]:
object_list = get_objects()
if not object_name or not object_type:
if len(object_list) > 0:
obj = object_list[0]
else:
obj = None
else:
# 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}"
@ -232,20 +235,21 @@ def config_gui(full_config: dict, config_file: str):
Extracts selected object from combobox
Returns object type and name
"""
try:
if combo_value.startswith("Repo: "):
object_type = "repos"
object_name = combo_value[len("Repo: ") :]
elif combo_value.startswith("Group: "):
object_type = "groups"
object_name = combo_value[len("Group: ") :]
else:
return object_type, object_name
except (AttributeError, UnboundLocalError):
object_type = None
object_name = None
logger.error(
f"Could not obtain object_type and object_name from {combo_value}"
)
return object_type, object_name
return None, None
def update_source_layout(source_type: str):
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
if not object_name:
try:
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
for key in window.AllKeysDict:
@ -622,6 +630,7 @@ def config_gui(full_config: dict, config_file: str):
object_config = None
config_inheritance = None
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
iter_over_config(
@ -2323,12 +2332,12 @@ Google Cloud storage: GOOGLE_PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS\n\
continue
if event == "-OBJECT-DELETE-":
object_type, object_name = get_object_from_combo(values["-OBJECT-SELECT-"])
if object_type == "repos" and object_name == "default":
sg.popup_error(_t("config_gui.cannot_delete_default_repo"))
continue
if object_type == "groups" and object_name == "default_group":
sg.popup_error(_t("config_gui.cannot_delete_default_group"))
continue
# if object_type == "repos" and object_name == "default":
# sg.popup_error(_t("config_gui.cannot_delete_default_repo"))
# continue
# if object_type == "groups" and object_name == "default_group":
# sg.popup_error(_t("config_gui.cannot_delete_default_group"))
# continue
full_config = delete_object(full_config, values["-OBJECT-SELECT-"])
current_object_type, current_object_name = update_object_selector()
continue