mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-12 07:55:23 +08:00
Reformat files with black
This commit is contained in:
parent
81cd60969c
commit
c2791e8d7f
4 changed files with 32 additions and 20 deletions
|
@ -45,10 +45,11 @@ if not "_DEBUG" in globals():
|
||||||
|
|
||||||
|
|
||||||
def exception_to_string(exc):
|
def exception_to_string(exc):
|
||||||
stack = traceback.extract_stack()[:-3] + traceback.extract_tb(exc.__traceback__) # add limit=??
|
stack = traceback.extract_stack()[:-3] + traceback.extract_tb(
|
||||||
|
exc.__traceback__
|
||||||
|
) # add limit=??
|
||||||
pretty = traceback.format_list(stack)
|
pretty = traceback.format_list(stack)
|
||||||
return ''.join(pretty) + '\n {} {}'.format(exc.__class__, exc)
|
return "".join(pretty) + "\n {} {}".format(exc.__class__, exc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def catch_exceptions(fn: Callable):
|
def catch_exceptions(fn: Callable):
|
||||||
|
|
|
@ -372,7 +372,13 @@ class NPBackupRunner:
|
||||||
def exec_time(self, value: int):
|
def exec_time(self, value: int):
|
||||||
self._exec_time = value
|
self._exec_time = value
|
||||||
|
|
||||||
def write_logs(self, msg: str, level: str, raise_error: str = None, ignore_additional_json: bool = False):
|
def write_logs(
|
||||||
|
self,
|
||||||
|
msg: str,
|
||||||
|
level: str,
|
||||||
|
raise_error: str = None,
|
||||||
|
ignore_additional_json: bool = False,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Write logs to log file and stdout / stderr queues if exist for GUI usage
|
Write logs to log file and stdout / stderr queues if exist for GUI usage
|
||||||
Also collect errors and warnings for json output
|
Also collect errors and warnings for json output
|
||||||
|
|
|
@ -102,7 +102,6 @@ class ResticRunner:
|
||||||
self.errors_for_json = []
|
self.errors_for_json = []
|
||||||
self.warnings_for_json = []
|
self.warnings_for_json = []
|
||||||
|
|
||||||
|
|
||||||
def on_exit(self) -> bool:
|
def on_exit(self) -> bool:
|
||||||
self._executor_running = False
|
self._executor_running = False
|
||||||
return self._executor_running
|
return self._executor_running
|
||||||
|
@ -263,7 +262,13 @@ class ResticRunner:
|
||||||
def executor_running(self) -> bool:
|
def executor_running(self) -> bool:
|
||||||
return self._executor_running
|
return self._executor_running
|
||||||
|
|
||||||
def write_logs(self, msg: str, level: str, raise_error: str = None, ignore_additional_json: bool = False):
|
def write_logs(
|
||||||
|
self,
|
||||||
|
msg: str,
|
||||||
|
level: str,
|
||||||
|
raise_error: str = None,
|
||||||
|
ignore_additional_json: bool = False,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Write logs to log file and stdout / stderr queues if exist for GUI usage
|
Write logs to log file and stdout / stderr queues if exist for GUI usage
|
||||||
"""
|
"""
|
||||||
|
@ -720,9 +725,9 @@ class ResticRunner:
|
||||||
# in any case, since restic might output non json data, but we need to
|
# in any case, since restic might output non json data, but we need to
|
||||||
# convert it to json
|
# convert it to json
|
||||||
|
|
||||||
#msg = f"JSON decode error: {exc} on content '{line}'"
|
# msg = f"JSON decode error: {exc} on content '{line}'"
|
||||||
#self.write_logs(msg, level="error")
|
# self.write_logs(msg, level="error")
|
||||||
#js["extended_info"] = msg
|
# js["extended_info"] = msg
|
||||||
js["output"].append({"data": line})
|
js["output"].append({"data": line})
|
||||||
js["result"] = False
|
js["result"] = False
|
||||||
else:
|
else:
|
||||||
|
@ -732,9 +737,9 @@ class ResticRunner:
|
||||||
except json.JSONDecodeError as exc:
|
except json.JSONDecodeError as exc:
|
||||||
# Same as above
|
# Same as above
|
||||||
|
|
||||||
#msg = f"JSON decode error: {exc} on content '{line}'"
|
# msg = f"JSON decode error: {exc} on content '{line}'"
|
||||||
#self.write_logs(msg, level="error")
|
# self.write_logs(msg, level="error")
|
||||||
#js["extended_info"] = msg
|
# js["extended_info"] = msg
|
||||||
js["output"].append({"data": line})
|
js["output"].append({"data": line})
|
||||||
js["result"] = False
|
js["result"] = False
|
||||||
# If we only have one output, we don't need a list
|
# If we only have one output, we don't need a list
|
||||||
|
@ -754,19 +759,19 @@ class ResticRunner:
|
||||||
except msgspec.DecodeError as exc:
|
except msgspec.DecodeError as exc:
|
||||||
# Save as above
|
# Save as above
|
||||||
|
|
||||||
#msg = f"JSON decode error: {exc} on output '{output}'"
|
# msg = f"JSON decode error: {exc} on output '{output}'"
|
||||||
#self.write_logs(msg, level="error")
|
# self.write_logs(msg, level="error")
|
||||||
#js["extended_info"] = msg
|
# js["extended_info"] = msg
|
||||||
js["output"] = {"data": output}
|
js["output"] = {"data": output}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# pylint: disable=E0601 (used-before-assignment)
|
# pylint: disable=E0601 (used-before-assignment)
|
||||||
js["output"] = json.loads(output)
|
js["output"] = json.loads(output)
|
||||||
except json.JSONDecodeError as exc:
|
except json.JSONDecodeError as exc:
|
||||||
# same as above
|
# same as above
|
||||||
#msg = f"JSON decode error: {exc} on output '{output}'"
|
# msg = f"JSON decode error: {exc} on output '{output}'"
|
||||||
#self.write_logs(msg, level="error")
|
# self.write_logs(msg, level="error")
|
||||||
#js["extended_info"] = msg
|
# js["extended_info"] = msg
|
||||||
js["output"] = {"data": output}
|
js["output"] = {"data": output}
|
||||||
if self.errors_for_json:
|
if self.errors_for_json:
|
||||||
js["additional_error_info"] += self.errors_for_json
|
js["additional_error_info"] += self.errors_for_json
|
||||||
|
|
|
@ -80,7 +80,7 @@ def entrypoint(*args, **kwargs):
|
||||||
logger.error(f"Operation finished")
|
logger.error(f"Operation finished")
|
||||||
else:
|
else:
|
||||||
if HAVE_MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
print(msgspec.json.encode(result).decode('utf-8', errors='ignore'))
|
print(msgspec.json.encode(result).decode("utf-8", errors="ignore"))
|
||||||
else:
|
else:
|
||||||
print(json.dumps(result, default=serialize_datetime))
|
print(json.dumps(result, default=serialize_datetime))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue