mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-09 21:17:47 +08:00
Linter fixes
This commit is contained in:
parent
542da5b4c4
commit
09b669e9a8
4 changed files with 16 additions and 13 deletions
|
@ -58,7 +58,7 @@ 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.restic_wrapper import ResticRunner
|
from npbackup.restic_wrapper import ResticRunner
|
||||||
from npbackup.restic_wrapper import schema, MSGSPEC
|
from npbackup.restic_wrapper import schema, HAVE_MSGSPEC
|
||||||
|
|
||||||
|
|
||||||
logger = getLogger()
|
logger = getLogger()
|
||||||
|
@ -193,13 +193,13 @@ def _make_treedata_from_json(ls_result: List[dict]) -> sg.TreeData:
|
||||||
"""
|
"""
|
||||||
treedata = sg.TreeData()
|
treedata = sg.TreeData()
|
||||||
count = 0
|
count = 0
|
||||||
if not MSGSPEC:
|
if not HAVE_MSGSPEC:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Using basic json representation for data which is slow and memory hungry. Consider using a newer OS that supports Python 3.8+"
|
"Using basic json representation for data which is slow and memory hungry. Consider using a newer OS that supports Python 3.8+"
|
||||||
)
|
)
|
||||||
for entry in ls_result:
|
for entry in ls_result:
|
||||||
# Make sure we drop the prefix '/' so sg.TreeData does not get an empty root
|
# Make sure we drop the prefix '/' so sg.TreeData does not get an empty root
|
||||||
if MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
entry.path = entry.path.lstrip("/")
|
entry.path = entry.path.lstrip("/")
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
# On windows, we need to make sure tree keys don't get duplicate because of lower/uppercase
|
# On windows, we need to make sure tree keys don't get duplicate because of lower/uppercase
|
||||||
|
|
|
@ -30,12 +30,12 @@ from npbackup.restic_wrapper import schema
|
||||||
try:
|
try:
|
||||||
import msgspec
|
import msgspec
|
||||||
|
|
||||||
MSGSPEC = True
|
HAVE_MSGSPEC = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# We may not have msgspec on Python 3.7
|
# We may not have msgspec on Python 3.7
|
||||||
import json
|
import json
|
||||||
|
|
||||||
MSGSPEC = False
|
HAVE_MSGSPEC = False
|
||||||
|
|
||||||
logger = getLogger()
|
logger = getLogger()
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ class ResticRunner:
|
||||||
}
|
}
|
||||||
if result:
|
if result:
|
||||||
if output:
|
if output:
|
||||||
if MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
decoder = msgspec.json.Decoder()
|
decoder = msgspec.json.Decoder()
|
||||||
ls_decoder = msgspec.json.Decoder(schema.LsNode)
|
ls_decoder = msgspec.json.Decoder(schema.LsNode)
|
||||||
is_first_line = True
|
is_first_line = True
|
||||||
|
@ -690,7 +690,7 @@ class ResticRunner:
|
||||||
for line in output.split("\n"):
|
for line in output.split("\n"):
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
if MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
not is_first_line
|
not is_first_line
|
||||||
|
@ -710,6 +710,7 @@ class ResticRunner:
|
||||||
js["result"] = False
|
js["result"] = False
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
# pylint: disable=E0601 (used-before-assignment)
|
||||||
js["output"].append(json.loads(line))
|
js["output"].append(json.loads(line))
|
||||||
except json.JSONDecodeError as exc:
|
except json.JSONDecodeError as exc:
|
||||||
msg = f"JSON decode error: {exc} on content '{line}'"
|
msg = f"JSON decode error: {exc} on content '{line}'"
|
||||||
|
@ -728,7 +729,7 @@ class ResticRunner:
|
||||||
js["reason"] = msg
|
js["reason"] = msg
|
||||||
self.write_logs(msg, level="error")
|
self.write_logs(msg, level="error")
|
||||||
if output:
|
if output:
|
||||||
if MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
try:
|
try:
|
||||||
js["output"] = msgspec.json.decode(output)
|
js["output"] = msgspec.json.decode(output)
|
||||||
except msgspec.DecodeError as exc:
|
except msgspec.DecodeError as exc:
|
||||||
|
@ -738,6 +739,7 @@ class ResticRunner:
|
||||||
js["output"] = {"data": output}
|
js["output"] = {"data": output}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
# 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:
|
||||||
msg = f"JSON decode error: {exc} on output '{output}'"
|
msg = f"JSON decode error: {exc} on output '{output}'"
|
||||||
|
|
|
@ -17,7 +17,7 @@ try:
|
||||||
from msgspec import Struct
|
from msgspec import Struct
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
|
||||||
MSGSPEC = True
|
HAVE_MSGSPEC = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
||||||
class Struct:
|
class Struct:
|
||||||
|
@ -29,7 +29,7 @@ except ImportError:
|
||||||
class StrEnum:
|
class StrEnum:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
MSGSPEC = False
|
HAVE_MSGSPEC = False
|
||||||
|
|
||||||
|
|
||||||
class LsNodeType(StrEnum):
|
class LsNodeType(StrEnum):
|
||||||
|
|
|
@ -18,11 +18,11 @@ from logging import getLogger
|
||||||
try:
|
try:
|
||||||
import msgspec.json
|
import msgspec.json
|
||||||
|
|
||||||
MSGSPEC = True
|
HAVE_MSGSPEC = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
MSGSPEC = False
|
HAVE_MSGSPEC = False
|
||||||
import datetime
|
import datetime
|
||||||
from npbackup.core.runner import NPBackupRunner
|
from npbackup.core.runner import NPBackupRunner
|
||||||
|
|
||||||
|
@ -78,9 +78,10 @@ def entrypoint(*args, **kwargs):
|
||||||
else:
|
else:
|
||||||
logger.error(f"Operation finished")
|
logger.error(f"Operation finished")
|
||||||
else:
|
else:
|
||||||
if MSGSPEC:
|
if HAVE_MSGSPEC:
|
||||||
print(msgspec.json.encode(result))
|
print(msgspec.json.encode(result))
|
||||||
else:
|
else:
|
||||||
|
# pylint: disable=E0601 (used-before-assignment)
|
||||||
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