mirror of
https://github.com/netinvent/npbackup.git
synced 2025-11-07 20:06:04 +08:00
Reformat file with black, linter fixes
This commit is contained in:
parent
3f3c75f414
commit
f5b6fe3a8b
5 changed files with 61 additions and 34 deletions
|
|
@ -227,9 +227,12 @@ def get_default_config() -> dict:
|
|||
Returns a config dict as nested CommentedMaps (used by ruamel.yaml to keep comments intact)
|
||||
"""
|
||||
full_config = deepcopy(empty_config_dict)
|
||||
def convert_to(source_dict, ):
|
||||
|
||||
def convert_to(
|
||||
source_dict,
|
||||
):
|
||||
if isinstance(source_dict, dict):
|
||||
return CommentedMap({k:convert_to(v) for k,v in source_dict.items()})
|
||||
return CommentedMap({k: convert_to(v) for k, v in source_dict.items()})
|
||||
else:
|
||||
return source_dict
|
||||
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ class NPBackupRunner:
|
|||
return wrapper
|
||||
|
||||
def is_ready(fn: Callable):
|
||||
""" "
|
||||
"""
|
||||
Decorator that checks if NPBackupRunner is ready to run, and logs accordingly
|
||||
"""
|
||||
|
||||
|
|
@ -397,8 +397,9 @@ class NPBackupRunner:
|
|||
)
|
||||
return False
|
||||
else:
|
||||
# pylint: disable=E1102 (not-callable)
|
||||
result = fn(self, *args, **kwargs)
|
||||
result = fn( # pylint: disable=E1102 (not-callable)
|
||||
self, *args, **kwargs
|
||||
)
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
|
@ -636,6 +637,7 @@ class NPBackupRunner:
|
|||
self.write_logs(
|
||||
f"Listing snapshots of repo {self.repo_config.g('name')}", level="info"
|
||||
)
|
||||
# TODO: replace with list("snapshots")
|
||||
snapshots = self.restic_runner.snapshots()
|
||||
return snapshots
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ from npbackup.core.upgrade_runner import run_upgrade, check_new_version
|
|||
from npbackup.path_helper import CURRENT_DIR
|
||||
from npbackup.__version__ import version_string
|
||||
from npbackup.__debug__ import _DEBUG
|
||||
from npbackup.gui.config import config_gui
|
||||
from npbackup.gui.operations import operations_gui
|
||||
from npbackup.restic_wrapper import ResticRunner
|
||||
|
||||
|
||||
|
|
@ -541,7 +539,9 @@ def _main_gui(viewer_mode: bool):
|
|||
sys.exit(100)
|
||||
if action == "--NEW-CONFIG--":
|
||||
config_file = "npbackup.conf"
|
||||
full_config = config_gui(npbackup.configuration.get_default_config(), config_file)
|
||||
full_config = config_gui(
|
||||
npbackup.configuration.get_default_config(), config_file
|
||||
)
|
||||
if config_file:
|
||||
logger.info(f"Using configuration file {config_file}")
|
||||
full_config = npbackup.configuration.load_config(config_file)
|
||||
|
|
@ -549,10 +549,10 @@ def _main_gui(viewer_mode: bool):
|
|||
sg.PopupError(f"{_t('main_gui.config_error')} {config_file}")
|
||||
config_file = None
|
||||
else:
|
||||
return full_config
|
||||
return full_config, config_file
|
||||
|
||||
if not viewer_mode:
|
||||
full_config = get_config_file()
|
||||
full_config, config_file = get_config_file()
|
||||
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
||||
full_config
|
||||
)
|
||||
|
|
@ -568,7 +568,7 @@ def _main_gui(viewer_mode: bool):
|
|||
repo_config = viewer_create_repo(viewer_repo_uri, viewer_repo_password)
|
||||
else:
|
||||
repo_config = None
|
||||
|
||||
|
||||
right_click_menu = ["", [_t("generic.destination")]]
|
||||
headings = [
|
||||
"ID ",
|
||||
|
|
@ -632,7 +632,7 @@ def _main_gui(viewer_mode: bool):
|
|||
sg.Button(
|
||||
_t("main_gui.open_repo"),
|
||||
key="--OPEN-REPO--",
|
||||
visible=viewer_mode
|
||||
visible=viewer_mode,
|
||||
),
|
||||
sg.Button(
|
||||
_t("main_gui.launch_backup"),
|
||||
|
|
@ -656,7 +656,7 @@ def _main_gui(viewer_mode: bool):
|
|||
sg.Button(
|
||||
_t("main_gui.load_configuration"),
|
||||
key="--LOAD-CONF--",
|
||||
disabled=viewer_mode
|
||||
disabled=viewer_mode,
|
||||
),
|
||||
sg.Button(_t("generic.about"), key="--ABOUT--"),
|
||||
sg.Button(_t("generic.quit"), key="--EXIT--"),
|
||||
|
|
@ -747,7 +747,7 @@ def _main_gui(viewer_mode: bool):
|
|||
event = "--STATE-BUTTON--"
|
||||
if event == "--LOAD-CONF--":
|
||||
# TODO: duplicate code
|
||||
full_config = get_config_file()
|
||||
full_config, config_file = get_config_file()
|
||||
repo_config, config_inheritance = npbackup.configuration.get_repo_config(
|
||||
full_config
|
||||
)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ def gui_thread_runner(
|
|||
"-OPERATIONS-PROGRESS-STDERR-",
|
||||
):
|
||||
progress_window[key].Update(visible=True)
|
||||
progress_window['--EXPAND--'].Update(visible=False)
|
||||
progress_window["--EXPAND--"].Update(visible=False)
|
||||
|
||||
runner = NPBackupRunner()
|
||||
# So we don't always init repo_config, since runner.group_runner would do that itself
|
||||
|
|
@ -153,7 +153,17 @@ def gui_thread_runner(
|
|||
[
|
||||
sg.Column(
|
||||
[
|
||||
[sg.Push(background_color=BG_COLOR_LDR), sg.Text("↓", key="--EXPAND--", enable_events=True, background_color=BG_COLOR_LDR, text_color=TXT_COLOR_LDR, visible=__compact)],
|
||||
[
|
||||
sg.Push(background_color=BG_COLOR_LDR),
|
||||
sg.Text(
|
||||
"↓",
|
||||
key="--EXPAND--",
|
||||
enable_events=True,
|
||||
background_color=BG_COLOR_LDR,
|
||||
text_color=TXT_COLOR_LDR,
|
||||
visible=__compact,
|
||||
),
|
||||
],
|
||||
[
|
||||
sg.Image(
|
||||
LOADER_ANIMATION,
|
||||
|
|
@ -212,12 +222,15 @@ def gui_thread_runner(
|
|||
result = runner.__getattribute__(fn.__name__)(*args, **kwargs)
|
||||
while True:
|
||||
# No idea why pylint thingks that UpdateAnimation does not exist in PySimpleGUI
|
||||
progress_window["-LOADER-ANIMATION-"].UpdateAnimation(
|
||||
# pylint: disable=E1101 (no-member)
|
||||
progress_window[
|
||||
"-LOADER-ANIMATION-"
|
||||
].UpdateAnimation(
|
||||
LOADER_ANIMATION, time_between_frames=100
|
||||
) # pylint: disable=E1101 (no-member)
|
||||
)
|
||||
# So we actually need to read the progress window for it to refresh...
|
||||
event , _ = progress_window.read(0.01)
|
||||
if event == '--EXPAND--':
|
||||
event, _ = progress_window.read(0.01)
|
||||
if event == "--EXPAND--":
|
||||
_upgrade_from_compact_view()
|
||||
# Read stdout queue
|
||||
try:
|
||||
|
|
@ -244,9 +257,9 @@ def gui_thread_runner(
|
|||
read_stderr_queue = False
|
||||
else:
|
||||
stderr_has_messages = True
|
||||
#if __compact:
|
||||
#for key in progress_window.AllKeysDict:
|
||||
# progress_window[key].Update(visible=True)
|
||||
# if __compact:
|
||||
# for key in progress_window.AllKeysDict:
|
||||
# progress_window[key].Update(visible=True)
|
||||
progress_window["-OPERATIONS-PROGRESS-STDERR-"].Update(
|
||||
f"\n{stderr_data}", append=True
|
||||
)
|
||||
|
|
|
|||
|
|
@ -508,17 +508,6 @@ class ResticRunner:
|
|||
def is_init(self, value: bool):
|
||||
self._is_init = value
|
||||
|
||||
def check_if_init(fn):
|
||||
"""
|
||||
Decorator to check that we don't do anything unless repo is initialized
|
||||
"""
|
||||
@wraps(fn)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if not self.is_init:
|
||||
return None
|
||||
return fn(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
@property
|
||||
def last_command_status(self):
|
||||
return self._last_command_status
|
||||
|
|
@ -527,6 +516,26 @@ class ResticRunner:
|
|||
def last_command_status(self, value: bool):
|
||||
self._last_command_status = value
|
||||
|
||||
# pylint: disable=E0213 (no-self-argument)
|
||||
def check_if_init(fn: Callable):
|
||||
"""
|
||||
Decorator to check that we don't do anything unless repo is initialized
|
||||
"""
|
||||
|
||||
@wraps(fn)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if not self.is_init:
|
||||
# pylint: disable=E1101 (no-member)
|
||||
self.write_logs(
|
||||
"Backend is not ready to perform operation {fn.__name}",
|
||||
level="error",
|
||||
)
|
||||
return None
|
||||
# pylint: disable=E1102 (not-callable)
|
||||
return fn(self, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
@check_if_init
|
||||
def list(self, obj: str = "snapshots") -> Optional[list]:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue