mirror of
https://github.com/netinvent/npbackup.git
synced 2024-09-20 23:06:17 +08:00
Do not allow actions unless config is loaded
This commit is contained in:
parent
3de0a77002
commit
fbe562ab2e
|
@ -431,7 +431,6 @@ def _main_gui(viewer_mode: bool):
|
||||||
[
|
[
|
||||||
sg.Push(),
|
sg.Push(),
|
||||||
sg.Button(_t("generic.cancel"), key="--CANCEL--"),
|
sg.Button(_t("generic.cancel"), key="--CANCEL--"),
|
||||||
sg.Button(_t("generic.quit"), key="--EXIT--"),
|
|
||||||
sg.Button(_t("main_gui.new_config"), key="--NEW-CONFIG--"),
|
sg.Button(_t("main_gui.new_config"), key="--NEW-CONFIG--"),
|
||||||
sg.Button(_t("generic.accept"), key="--ACCEPT--"),
|
sg.Button(_t("generic.accept"), key="--ACCEPT--"),
|
||||||
],
|
],
|
||||||
|
@ -444,9 +443,6 @@ def _main_gui(viewer_mode: bool):
|
||||||
if event in [sg.WIN_X_EVENT, sg.WIN_CLOSED, "--CANCEL--"]:
|
if event in [sg.WIN_X_EVENT, sg.WIN_CLOSED, "--CANCEL--"]:
|
||||||
action = "--CANCEL--"
|
action = "--CANCEL--"
|
||||||
break
|
break
|
||||||
if event == "--EXIT--":
|
|
||||||
action = "--EXIT--"
|
|
||||||
break
|
|
||||||
if event == "--NEW-CONFIG--":
|
if event == "--NEW-CONFIG--":
|
||||||
action = event
|
action = event
|
||||||
break
|
break
|
||||||
|
@ -497,8 +493,13 @@ def _main_gui(viewer_mode: bool):
|
||||||
snapshots = gui_thread_runner(
|
snapshots = gui_thread_runner(
|
||||||
repo_config, "snapshots", __gui_msg=gui_msg, __autoclose=True, __compact=True
|
repo_config, "snapshots", __gui_msg=gui_msg, __autoclose=True, __compact=True
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
min_backup_age = repo_config.g("repo_opts.minimum_backup_age")
|
||||||
|
except AttributeError:
|
||||||
|
min_backup_age = 0
|
||||||
|
|
||||||
current_state, backup_tz = ResticRunner._has_recent_snapshot(
|
current_state, backup_tz = ResticRunner._has_recent_snapshot(
|
||||||
snapshots, repo_config.g("repo_opts.minimum_backup_age")
|
snapshots, min_backup_age
|
||||||
)
|
)
|
||||||
snapshot_list = []
|
snapshot_list = []
|
||||||
if snapshots:
|
if snapshots:
|
||||||
|
@ -542,9 +543,9 @@ def _main_gui(viewer_mode: bool):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if not config_file or not config_file.exists():
|
if not config_file or not config_file.exists():
|
||||||
config_file, action = select_config_file(config_file)
|
config_file, action = select_config_file()
|
||||||
if action == "--EXIT--":
|
if action == "--CANCEL--":
|
||||||
sys.exit(100)
|
break
|
||||||
if action == "--NEW-CONFIG--":
|
if action == "--NEW-CONFIG--":
|
||||||
config_file = "npbackup.conf"
|
config_file = "npbackup.conf"
|
||||||
full_config = config_gui(
|
full_config = config_gui(
|
||||||
|
@ -558,16 +559,43 @@ def _main_gui(viewer_mode: bool):
|
||||||
config_file = None
|
config_file = None
|
||||||
else:
|
else:
|
||||||
return full_config, config_file
|
return full_config, config_file
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
def get_config():
|
||||||
|
full_config, config_file = get_config_file()
|
||||||
|
if full_config and config_file:
|
||||||
|
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
||||||
|
full_config
|
||||||
|
)
|
||||||
|
backup_destination = _t("main_gui.local_folder")
|
||||||
|
backend_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
||||||
|
window.set_title(f"{SHORT_PRODUCT_NAME} - {config_file}")
|
||||||
|
else:
|
||||||
|
repo_config = None
|
||||||
|
config_inheritance = None
|
||||||
|
backup_destination = "None"
|
||||||
|
backend_type = "None"
|
||||||
|
repo_uri = "None"
|
||||||
|
repo_list = npbackup.configuration.get_repo_list(full_config)
|
||||||
|
return full_config, config_file, repo_config, backup_destination, backend_type, repo_uri, repo_list
|
||||||
|
|
||||||
if not viewer_mode:
|
if not viewer_mode:
|
||||||
|
"""
|
||||||
full_config, config_file = get_config_file()
|
full_config, config_file = get_config_file()
|
||||||
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
if full_config and config_file:
|
||||||
full_config
|
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
||||||
)
|
full_config
|
||||||
|
)
|
||||||
|
backup_destination = _t("main_gui.local_folder")
|
||||||
|
backend_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
||||||
|
else:
|
||||||
|
repo_config = None
|
||||||
|
config_inheritance = None
|
||||||
|
backup_destination = "None"
|
||||||
|
backend_type = "Bone"
|
||||||
repo_list = npbackup.configuration.get_repo_list(full_config)
|
repo_list = npbackup.configuration.get_repo_list(full_config)
|
||||||
|
"""
|
||||||
backup_destination = _t("main_gui.local_folder")
|
full_config, config_file, repo_config, backup_destination, backend_type, repo_uri, repo_list = get_config()
|
||||||
backend_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
|
||||||
else:
|
else:
|
||||||
# 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)
|
||||||
|
@ -619,7 +647,7 @@ def _main_gui(viewer_mode: bool):
|
||||||
sg.Combo(
|
sg.Combo(
|
||||||
repo_list,
|
repo_list,
|
||||||
key="-active_repo-",
|
key="-active_repo-",
|
||||||
default_value=repo_list[0],
|
default_value=repo_list[0] if repo_list else None,
|
||||||
enable_events=True,
|
enable_events=True,
|
||||||
),
|
),
|
||||||
sg.Text(f"Type {backend_type}", key="-backend_type-"),
|
sg.Text(f"Type {backend_type}", key="-backend_type-"),
|
||||||
|
@ -723,9 +751,15 @@ def _main_gui(viewer_mode: bool):
|
||||||
sg.PopupError("Repo not existent in config")
|
sg.PopupError("Repo not existent in config")
|
||||||
continue
|
continue
|
||||||
if event == "--LAUNCH-BACKUP--":
|
if event == "--LAUNCH-BACKUP--":
|
||||||
|
if not full_config:
|
||||||
|
sg.PopupError(_t("main_gui.no_config"))
|
||||||
|
continue
|
||||||
backup(repo_config)
|
backup(repo_config)
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
if event == "--SEE-CONTENT--":
|
if event == "--SEE-CONTENT--":
|
||||||
|
if not full_config:
|
||||||
|
sg.PopupError(_t("main_gui.no_config"))
|
||||||
|
continue
|
||||||
if not values["snapshot-list"]:
|
if not values["snapshot-list"]:
|
||||||
sg.Popup(_t("main_gui.select_backup"), keep_on_top=True)
|
sg.Popup(_t("main_gui.select_backup"), keep_on_top=True)
|
||||||
continue
|
continue
|
||||||
|
@ -735,6 +769,9 @@ def _main_gui(viewer_mode: bool):
|
||||||
snapshot_to_see = snapshot_list[values["snapshot-list"][0]][0]
|
snapshot_to_see = snapshot_list[values["snapshot-list"][0]][0]
|
||||||
ls_window(repo_config, snapshot_to_see)
|
ls_window(repo_config, snapshot_to_see)
|
||||||
if event == "--FORGET--":
|
if event == "--FORGET--":
|
||||||
|
if not full_config:
|
||||||
|
sg.PopupError(_t("main_gui.no_config"))
|
||||||
|
continue
|
||||||
if not values["snapshot-list"]:
|
if not values["snapshot-list"]:
|
||||||
sg.Popup(_t("main_gui.select_backup"), keep_on_top=True)
|
sg.Popup(_t("main_gui.select_backup"), keep_on_top=True)
|
||||||
continue
|
continue
|
||||||
|
@ -745,9 +782,15 @@ def _main_gui(viewer_mode: bool):
|
||||||
# Make sure we trigger a GUI refresh after forgetting snapshots
|
# Make sure we trigger a GUI refresh after forgetting snapshots
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
if event == "--OPERATIONS--":
|
if event == "--OPERATIONS--":
|
||||||
|
if not full_config:
|
||||||
|
sg.PopupError(_t("main_gui.no_config"))
|
||||||
|
continue
|
||||||
full_config = operations_gui(full_config)
|
full_config = operations_gui(full_config)
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
if event == "--CONFIGURE--":
|
if event == "--CONFIGURE--":
|
||||||
|
if not full_config:
|
||||||
|
sg.PopupError(_t("main_gui.no_config"))
|
||||||
|
continue
|
||||||
full_config = config_gui(full_config, config_file)
|
full_config = config_gui(full_config, config_file)
|
||||||
# Make sure we trigger a GUI refresh when configuration is changed
|
# Make sure we trigger a GUI refresh when configuration is changed
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
|
@ -756,16 +799,7 @@ def _main_gui(viewer_mode: bool):
|
||||||
repo_config = viewer_create_repo(viewer_repo_uri, viewer_repo_password)
|
repo_config = viewer_create_repo(viewer_repo_uri, viewer_repo_password)
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
if event == "--LOAD-CONF--":
|
if event == "--LOAD-CONF--":
|
||||||
# TODO: duplicate code
|
full_config, config_file, repo_config, backup_destination, backend_type, repo_uri, repo_list = get_config()
|
||||||
full_config, config_file = get_config_file(default=False)
|
|
||||||
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
|
||||||
full_config
|
|
||||||
)
|
|
||||||
repo_list = npbackup.configuration.get_repo_list(full_config)
|
|
||||||
|
|
||||||
backup_destination = _t("main_gui.local_folder")
|
|
||||||
backend_type, repo_uri = get_anon_repo_uri(repo_config.g("repo_uri"))
|
|
||||||
window.set_title(f"{SHORT_PRODUCT_NAME} - {config_file}")
|
|
||||||
event = "--STATE-BUTTON--"
|
event = "--STATE-BUTTON--"
|
||||||
if event == _t("generic.destination"):
|
if event == _t("generic.destination"):
|
||||||
try:
|
try:
|
||||||
|
@ -780,10 +814,11 @@ def _main_gui(viewer_mode: bool):
|
||||||
if event == "--ABOUT--":
|
if event == "--ABOUT--":
|
||||||
about_gui(version_string, full_config if not viewer_mode else None)
|
about_gui(version_string, full_config if not viewer_mode else None)
|
||||||
if event == "--STATE-BUTTON--":
|
if event == "--STATE-BUTTON--":
|
||||||
current_state, backup_tz, snapshot_list = get_gui_data(repo_config)
|
if full_config:
|
||||||
gui_update_state()
|
current_state, backup_tz, snapshot_list = get_gui_data(repo_config)
|
||||||
if current_state is None:
|
gui_update_state()
|
||||||
sg.Popup(_t("main_gui.cannot_get_repo_status"))
|
if current_state is None:
|
||||||
|
sg.Popup(_t("main_gui.cannot_get_repo_status"))
|
||||||
|
|
||||||
|
|
||||||
def main_gui(viewer_mode=False):
|
def main_gui(viewer_mode=False):
|
||||||
|
|
Loading…
Reference in a new issue