优化loader写法
This commit is contained in:
parent
397486253b
commit
b6505aef27
|
@ -57,21 +57,16 @@ def version_check(configuration: dict, pkg_name: str) -> int:
|
|||
|
||||
def file_check(file_json, pkg_name):
|
||||
try:
|
||||
if "compatibility" in file_json:
|
||||
if "file" in file_json["compatibility"]:
|
||||
if "must" in file_json["compatibility"]["file"]:
|
||||
for i in file_json["compatibility"]["file"]["must"]:
|
||||
if not os.path.exists(i):
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
f"Cannot find file: [{i}]")
|
||||
return 8
|
||||
if "mustnot" in file_json["compatibility"]["file"]:
|
||||
for i in file_json["compatibility"]["file"]["mustnot"]:
|
||||
if os.path.exists(i):
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
f"Find incompatible file: [{i}]")
|
||||
return 9
|
||||
|
||||
for i in file_json.get("compatibility", {}).get("file", {}).get("must", []):
|
||||
if not os.path.exists(i):
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
f"Cannot find file: [{i}]")
|
||||
return 8
|
||||
for i in file_json.get("compatibility", {}).get("file", {}).get("mustnot", []):
|
||||
if os.path.exists(i):
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
f"Find incompatible file: [{i}]")
|
||||
return 9
|
||||
except:
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
"Unknown error in file check")
|
||||
|
@ -91,17 +86,15 @@ def load_package(pkg_name):
|
|||
return 1
|
||||
try:
|
||||
with open(pkg_path+"/"+"manifest.json", "r", encoding="utf-8") as file:
|
||||
file_str = file.read()
|
||||
file_json = json.load(json.decoder.JSONDecodeError)
|
||||
except json.decoder.JSONDecodeError:
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
"Json syntax error")
|
||||
return 3
|
||||
except Exception as exp:
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
"Unknown error in read file ("+repr(exp)+")")
|
||||
return 2
|
||||
try:
|
||||
file_json = json.loads(file_str)
|
||||
except:
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
"Json syntax error")
|
||||
return 3
|
||||
for i in ("version", "name", "author", "introduce"):
|
||||
if i not in file_json:
|
||||
log.warn(f"load moudle [{pkg_name}] failed: " +
|
||||
|
|
Loading…
Reference in New Issue