mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-10 06:54:54 +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):
|
||||
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)
|
||||
return ''.join(pretty) + '\n {} {}'.format(exc.__class__, exc)
|
||||
|
||||
return "".join(pretty) + "\n {} {}".format(exc.__class__, exc)
|
||||
|
||||
|
||||
def catch_exceptions(fn: Callable):
|
||||
|
|
|
@ -372,7 +372,13 @@ class NPBackupRunner:
|
|||
def exec_time(self, value: int):
|
||||
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
|
||||
Also collect errors and warnings for json output
|
||||
|
|
|
@ -102,7 +102,6 @@ class ResticRunner:
|
|||
self.errors_for_json = []
|
||||
self.warnings_for_json = []
|
||||
|
||||
|
||||
def on_exit(self) -> bool:
|
||||
self._executor_running = False
|
||||
return self._executor_running
|
||||
|
@ -263,7 +262,13 @@ class ResticRunner:
|
|||
def executor_running(self) -> bool:
|
||||
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
|
||||
"""
|
||||
|
@ -720,9 +725,9 @@ class ResticRunner:
|
|||
# in any case, since restic might output non json data, but we need to
|
||||
# convert it to json
|
||||
|
||||
#msg = f"JSON decode error: {exc} on content '{line}'"
|
||||
#self.write_logs(msg, level="error")
|
||||
#js["extended_info"] = msg
|
||||
# msg = f"JSON decode error: {exc} on content '{line}'"
|
||||
# self.write_logs(msg, level="error")
|
||||
# js["extended_info"] = msg
|
||||
js["output"].append({"data": line})
|
||||
js["result"] = False
|
||||
else:
|
||||
|
@ -732,9 +737,9 @@ class ResticRunner:
|
|||
except json.JSONDecodeError as exc:
|
||||
# Same as above
|
||||
|
||||
#msg = f"JSON decode error: {exc} on content '{line}'"
|
||||
#self.write_logs(msg, level="error")
|
||||
#js["extended_info"] = msg
|
||||
# msg = f"JSON decode error: {exc} on content '{line}'"
|
||||
# self.write_logs(msg, level="error")
|
||||
# js["extended_info"] = msg
|
||||
js["output"].append({"data": line})
|
||||
js["result"] = False
|
||||
# If we only have one output, we don't need a list
|
||||
|
@ -754,19 +759,19 @@ class ResticRunner:
|
|||
except msgspec.DecodeError as exc:
|
||||
# Save as above
|
||||
|
||||
#msg = f"JSON decode error: {exc} on output '{output}'"
|
||||
#self.write_logs(msg, level="error")
|
||||
#js["extended_info"] = msg
|
||||
# msg = f"JSON decode error: {exc} on output '{output}'"
|
||||
# self.write_logs(msg, level="error")
|
||||
# js["extended_info"] = msg
|
||||
js["output"] = {"data": output}
|
||||
else:
|
||||
try:
|
||||
# pylint: disable=E0601 (used-before-assignment)
|
||||
js["output"] = json.loads(output)
|
||||
except json.JSONDecodeError as exc:
|
||||
# same as above
|
||||
#msg = f"JSON decode error: {exc} on output '{output}'"
|
||||
#self.write_logs(msg, level="error")
|
||||
#js["extended_info"] = msg
|
||||
# same as above
|
||||
# msg = f"JSON decode error: {exc} on output '{output}'"
|
||||
# self.write_logs(msg, level="error")
|
||||
# js["extended_info"] = msg
|
||||
js["output"] = {"data": output}
|
||||
if 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")
|
||||
else:
|
||||
if HAVE_MSGSPEC:
|
||||
print(msgspec.json.encode(result).decode('utf-8', errors='ignore'))
|
||||
print(msgspec.json.encode(result).decode("utf-8", errors="ignore"))
|
||||
else:
|
||||
print(json.dumps(result, default=serialize_datetime))
|
||||
sys.exit(0)
|
||||
|
|
Loading…
Add table
Reference in a new issue