Reformat file with black, linter fixes

This commit is contained in:
Orsiris de Jong 2023-12-29 20:22:13 +01:00
parent 3f3c75f414
commit f5b6fe3a8b
5 changed files with 61 additions and 34 deletions

View file

@ -227,9 +227,12 @@ def get_default_config() -> dict:
Returns a config dict as nested CommentedMaps (used by ruamel.yaml to keep comments intact) Returns a config dict as nested CommentedMaps (used by ruamel.yaml to keep comments intact)
""" """
full_config = deepcopy(empty_config_dict) full_config = deepcopy(empty_config_dict)
def convert_to(source_dict, ):
def convert_to(
source_dict,
):
if isinstance(source_dict, 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: else:
return source_dict return source_dict

View file

@ -290,7 +290,7 @@ class NPBackupRunner:
return wrapper return wrapper
def is_ready(fn: Callable): def is_ready(fn: Callable):
""" " """
Decorator that checks if NPBackupRunner is ready to run, and logs accordingly Decorator that checks if NPBackupRunner is ready to run, and logs accordingly
""" """
@ -397,8 +397,9 @@ class NPBackupRunner:
) )
return False return False
else: else:
# pylint: disable=E1102 (not-callable) result = fn( # pylint: disable=E1102 (not-callable)
result = fn(self, *args, **kwargs) self, *args, **kwargs
)
return result return result
return wrapper return wrapper
@ -636,6 +637,7 @@ class NPBackupRunner:
self.write_logs( self.write_logs(
f"Listing snapshots of repo {self.repo_config.g('name')}", level="info" f"Listing snapshots of repo {self.repo_config.g('name')}", level="info"
) )
# TODO: replace with list("snapshots")
snapshots = self.restic_runner.snapshots() snapshots = self.restic_runner.snapshots()
return snapshots return snapshots

View file

@ -52,8 +52,6 @@ from npbackup.core.upgrade_runner import run_upgrade, check_new_version
from npbackup.path_helper import CURRENT_DIR from npbackup.path_helper import CURRENT_DIR
from npbackup.__version__ import version_string from npbackup.__version__ import version_string
from npbackup.__debug__ import _DEBUG 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 from npbackup.restic_wrapper import ResticRunner
@ -541,7 +539,9 @@ def _main_gui(viewer_mode: bool):
sys.exit(100) sys.exit(100)
if action == "--NEW-CONFIG--": if action == "--NEW-CONFIG--":
config_file = "npbackup.conf" 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: if config_file:
logger.info(f"Using configuration file {config_file}") logger.info(f"Using configuration file {config_file}")
full_config = npbackup.configuration.load_config(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}") sg.PopupError(f"{_t('main_gui.config_error')} {config_file}")
config_file = None config_file = None
else: else:
return full_config return full_config, config_file
if not viewer_mode: 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( repo_config, config_inheritance = npbackup.configuration.get_repo_config(
full_config full_config
) )
@ -632,7 +632,7 @@ def _main_gui(viewer_mode: bool):
sg.Button( sg.Button(
_t("main_gui.open_repo"), _t("main_gui.open_repo"),
key="--OPEN-REPO--", key="--OPEN-REPO--",
visible=viewer_mode visible=viewer_mode,
), ),
sg.Button( sg.Button(
_t("main_gui.launch_backup"), _t("main_gui.launch_backup"),
@ -656,7 +656,7 @@ def _main_gui(viewer_mode: bool):
sg.Button( sg.Button(
_t("main_gui.load_configuration"), _t("main_gui.load_configuration"),
key="--LOAD-CONF--", key="--LOAD-CONF--",
disabled=viewer_mode disabled=viewer_mode,
), ),
sg.Button(_t("generic.about"), key="--ABOUT--"), sg.Button(_t("generic.about"), key="--ABOUT--"),
sg.Button(_t("generic.quit"), key="--EXIT--"), sg.Button(_t("generic.quit"), key="--EXIT--"),
@ -747,7 +747,7 @@ def _main_gui(viewer_mode: bool):
event = "--STATE-BUTTON--" event = "--STATE-BUTTON--"
if event == "--LOAD-CONF--": if event == "--LOAD-CONF--":
# TODO: duplicate code # TODO: duplicate code
full_config = get_config_file() full_config, config_file = get_config_file()
repo_config, config_inheritance = npbackup.configuration.get_repo_config( repo_config, config_inheritance = npbackup.configuration.get_repo_config(
full_config full_config
) )

View file

@ -93,7 +93,7 @@ def gui_thread_runner(
"-OPERATIONS-PROGRESS-STDERR-", "-OPERATIONS-PROGRESS-STDERR-",
): ):
progress_window[key].Update(visible=True) progress_window[key].Update(visible=True)
progress_window['--EXPAND--'].Update(visible=False) progress_window["--EXPAND--"].Update(visible=False)
runner = NPBackupRunner() runner = NPBackupRunner()
# So we don't always init repo_config, since runner.group_runner would do that itself # 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.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( sg.Image(
LOADER_ANIMATION, LOADER_ANIMATION,
@ -212,12 +222,15 @@ def gui_thread_runner(
result = runner.__getattribute__(fn.__name__)(*args, **kwargs) result = runner.__getattribute__(fn.__name__)(*args, **kwargs)
while True: while True:
# No idea why pylint thingks that UpdateAnimation does not exist in PySimpleGUI # 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 LOADER_ANIMATION, time_between_frames=100
) # pylint: disable=E1101 (no-member) )
# So we actually need to read the progress window for it to refresh... # So we actually need to read the progress window for it to refresh...
event , _ = progress_window.read(0.01) event, _ = progress_window.read(0.01)
if event == '--EXPAND--': if event == "--EXPAND--":
_upgrade_from_compact_view() _upgrade_from_compact_view()
# Read stdout queue # Read stdout queue
try: try:
@ -244,8 +257,8 @@ def gui_thread_runner(
read_stderr_queue = False read_stderr_queue = False
else: else:
stderr_has_messages = True stderr_has_messages = True
#if __compact: # if __compact:
#for key in progress_window.AllKeysDict: # for key in progress_window.AllKeysDict:
# progress_window[key].Update(visible=True) # progress_window[key].Update(visible=True)
progress_window["-OPERATIONS-PROGRESS-STDERR-"].Update( progress_window["-OPERATIONS-PROGRESS-STDERR-"].Update(
f"\n{stderr_data}", append=True f"\n{stderr_data}", append=True

View file

@ -508,17 +508,6 @@ class ResticRunner:
def is_init(self, value: bool): def is_init(self, value: bool):
self._is_init = value 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 @property
def last_command_status(self): def last_command_status(self):
return self._last_command_status return self._last_command_status
@ -527,6 +516,26 @@ class ResticRunner:
def last_command_status(self, value: bool): def last_command_status(self, value: bool):
self._last_command_status = value 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 @check_if_init
def list(self, obj: str = "snapshots") -> Optional[list]: def list(self, obj: str = "snapshots") -> Optional[list]:
""" """