mirror of
https://github.com/netinvent/npbackup.git
synced 2024-11-10 09:03:02 +08:00
Various pylint fixes
This commit is contained in:
parent
43a35a2c70
commit
2894e57ad5
4 changed files with 14 additions and 14 deletions
|
@ -19,6 +19,7 @@ __SPECIAL_DEBUG_STRING = ""
|
||||||
__debug_os_env = os.environ.get("_DEBUG", "False").strip("'\"")
|
__debug_os_env = os.environ.get("_DEBUG", "False").strip("'\"")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# pylint: disable=E0601 (used-before-assignment)
|
||||||
_DEBUG
|
_DEBUG
|
||||||
except NameError:
|
except NameError:
|
||||||
_DEBUG = False
|
_DEBUG = False
|
||||||
|
|
|
@ -132,16 +132,6 @@ class NPBackupRunner:
|
||||||
|
|
||||||
self._using_dev_binary = False
|
self._using_dev_binary = False
|
||||||
|
|
||||||
@property
|
|
||||||
def repo_name(self) -> str:
|
|
||||||
return self._repo_name
|
|
||||||
|
|
||||||
@repo_name.setter
|
|
||||||
def repo_name(self, value: str):
|
|
||||||
if not isinstance(value, str) or not value:
|
|
||||||
msg = f"Bogus repo name {value} found"
|
|
||||||
self.write_logs(msg, level="critical", raise_error="ValueError")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repo_config(self) -> dict:
|
def repo_config(self) -> dict:
|
||||||
return self._repo_config
|
return self._repo_config
|
||||||
|
@ -152,7 +142,6 @@ class NPBackupRunner:
|
||||||
msg = f"Bogus repo config object given"
|
msg = f"Bogus repo config object given"
|
||||||
self.write_logs(msg, level="critical", raise_error="ValueError")
|
self.write_logs(msg, level="critical", raise_error="ValueError")
|
||||||
self._repo_config = deepcopy(value)
|
self._repo_config = deepcopy(value)
|
||||||
self.repo_name = self.repo_config.g("name")
|
|
||||||
# Create an instance of restic wrapper
|
# Create an instance of restic wrapper
|
||||||
self.create_restic_runner()
|
self.create_restic_runner()
|
||||||
|
|
||||||
|
@ -271,6 +260,7 @@ class NPBackupRunner:
|
||||||
# pylint: disable=E1102 (not-callable)
|
# pylint: disable=E1102 (not-callable)
|
||||||
result = fn(self, *args, **kwargs)
|
result = fn(self, *args, **kwargs)
|
||||||
self.exec_time = (datetime.utcnow() - start_time).total_seconds()
|
self.exec_time = (datetime.utcnow() - start_time).total_seconds()
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
self.write_logs(
|
self.write_logs(
|
||||||
f"Runner took {self.exec_time} seconds for {fn.__name__}", level="info"
|
f"Runner took {self.exec_time} seconds for {fn.__name__}", level="info"
|
||||||
)
|
)
|
||||||
|
@ -286,6 +276,7 @@ class NPBackupRunner:
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
close_queues = kwargs.pop("close_queues", True)
|
close_queues = kwargs.pop("close_queues", True)
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
result = fn(self, *args, **kwargs)
|
result = fn(self, *args, **kwargs)
|
||||||
if close_queues:
|
if close_queues:
|
||||||
if self.stdout:
|
if self.stdout:
|
||||||
|
@ -304,11 +295,13 @@ class NPBackupRunner:
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
if not self._is_ready:
|
if not self._is_ready:
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
self.write_logs(
|
self.write_logs(
|
||||||
f"Runner cannot execute {fn.__name__}. Backend not ready",
|
f"Runner cannot execute {fn.__name__}. Backend not ready",
|
||||||
level="error",
|
level="error",
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
return fn(self, *args, **kwargs)
|
return fn(self, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -337,9 +330,11 @@ class NPBackupRunner:
|
||||||
try:
|
try:
|
||||||
# When running group_runner, we need to extract operation from kwargs
|
# When running group_runner, we need to extract operation from kwargs
|
||||||
# else, operarion is just the wrapped function name
|
# else, operarion is just the wrapped function name
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
if fn.__name__ == "group_runner":
|
if fn.__name__ == "group_runner":
|
||||||
operation = kwargs.get("operation")
|
operation = kwargs.get("operation")
|
||||||
else:
|
else:
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
operation = fn.__name__
|
operation = fn.__name__
|
||||||
# TODO: enforce permissions
|
# TODO: enforce permissions
|
||||||
self.write_logs(
|
self.write_logs(
|
||||||
|
@ -349,6 +344,7 @@ class NPBackupRunner:
|
||||||
except (IndexError, KeyError):
|
except (IndexError, KeyError):
|
||||||
self.write_logs("You don't have sufficient permissions", level="error")
|
self.write_logs("You don't have sufficient permissions", level="error")
|
||||||
return False
|
return False
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
return fn(self, *args, **kwargs)
|
return fn(self, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -362,6 +358,7 @@ class NPBackupRunner:
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
if not self._apply_config_to_restic_runner():
|
if not self._apply_config_to_restic_runner():
|
||||||
return False
|
return False
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
return fn(self, *args, **kwargs)
|
return fn(self, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -374,8 +371,10 @@ class NPBackupRunner:
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
return fn(self, *args, **kwargs)
|
return fn(self, *args, **kwargs)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
self.write_logs(f"Function {fn.__name__} failed with: {exc}")
|
self.write_logs(f"Function {fn.__name__} failed with: {exc}")
|
||||||
logger.debug("Trace:", exc_info=True)
|
logger.debug("Trace:", exc_info=True)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -728,7 +728,7 @@ def main_gui(viewer_mode=False):
|
||||||
sys.exit(250)
|
sys.exit(250)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
sg.Popup(_t("config_gui.unknown_error_see_logs") + f": {exc}")
|
sg.Popup(_t("config_gui.unknown_error_see_logs") + f": {exc}")
|
||||||
logger.critical("GUI Execution error", exc)
|
logger.critical(f"GUI Execution error {exc}")
|
||||||
if _DEBUG:
|
if _DEBUG:
|
||||||
logger.critical("Trace:", exc_info=True)
|
logger.critical("Trace:", exc_info=True)
|
||||||
sys.exit(251)
|
sys.exit(251)
|
||||||
|
|
|
@ -693,7 +693,7 @@ class ResticRunner:
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
self.write_logs(f"Returned data is not JSON:\n{output}", level="error")
|
self.write_logs(f"Returned data is not JSON:\n{output}", level="error")
|
||||||
logger.debug("Trace:", exc_info=True)
|
logger.debug("Trace:", exc_info=True)
|
||||||
self.write_logs(f"Could not find path: {path}")
|
self.write_logs(f"Could not find path: {path}", level="error")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def restore(self, snapshot: str, target: str, includes: List[str] = None):
|
def restore(self, snapshot: str, target: str, includes: List[str] = None):
|
||||||
|
@ -903,7 +903,7 @@ class ResticRunner:
|
||||||
snapshots = self.snapshots()
|
snapshots = self.snapshots()
|
||||||
if self.last_command_status is False:
|
if self.last_command_status is False:
|
||||||
return None, None
|
return None, None
|
||||||
return self.has_snapshot_timedelta(snapshots, delta)
|
return self._has_snapshot_timedelta(snapshots, delta)
|
||||||
except IndexError as exc:
|
except IndexError as exc:
|
||||||
self.write_logs(f"snapshot information missing: {exc}", level="error")
|
self.write_logs(f"snapshot information missing: {exc}", level="error")
|
||||||
logger.debug("Trace", exc_info=True)
|
logger.debug("Trace", exc_info=True)
|
||||||
|
|
Loading…
Reference in a new issue