mirror of
https://git.mirrors.martin98.com/https://github.com/SoftFever/OrcaSlicer.git
synced 2025-06-04 11:25:39 +08:00
Fix profile check error msg (#9414)
* Ensure file encoding * Show correct file path in error message
This commit is contained in:
parent
cd2077ebaf
commit
cd2df8f5ef
@ -33,7 +33,7 @@ def check_filament_compatible_printers(vendor_folder):
|
|||||||
# Use rglob to recursively find .json files.
|
# Use rglob to recursively find .json files.
|
||||||
for file_path in vendor_path.rglob("*.json"):
|
for file_path in vendor_path.rglob("*.json"):
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r') as fp:
|
with open(file_path, 'r', encoding='UTF-8') as fp:
|
||||||
# Use custom hook to detect duplicates.
|
# Use custom hook to detect duplicates.
|
||||||
data = json.load(fp, object_pairs_hook=no_duplicates_object_pairs_hook)
|
data = json.load(fp, object_pairs_hook=no_duplicates_object_pairs_hook)
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
@ -51,31 +51,35 @@ def check_filament_compatible_printers(vendor_folder):
|
|||||||
error += 1
|
error += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
profiles[profile_name] = data
|
profiles[profile_name] = {
|
||||||
|
'file_path': file_path,
|
||||||
|
'content': data,
|
||||||
|
}
|
||||||
|
|
||||||
def get_inherit_property(data, key):
|
def get_inherit_property(profile, key):
|
||||||
if key in data:
|
content = profile['content']
|
||||||
return data[key]
|
if key in content:
|
||||||
|
return content[key]
|
||||||
|
|
||||||
if 'inherits' in data:
|
if 'inherits' in content:
|
||||||
inherits = data['inherits']
|
inherits = content['inherits']
|
||||||
if inherits not in profiles:
|
if inherits not in profiles:
|
||||||
raise ValueError(f"Parent profile not found: {inherits}")
|
raise ValueError(f"Parent profile not found: {inherits}, referrenced in {profile['file_path']}")
|
||||||
|
|
||||||
return get_inherit_property(profiles[inherits], key)
|
return get_inherit_property(profiles[inherits], key)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for data in profiles.values():
|
for profile in profiles.values():
|
||||||
instantiation = str(data.get("instantiation", "")).lower() == "true"
|
instantiation = str(profile['content'].get("instantiation", "")).lower() == "true"
|
||||||
if instantiation:
|
if instantiation:
|
||||||
try:
|
try:
|
||||||
compatible_printers = get_inherit_property(data, "compatible_printers")
|
compatible_printers = get_inherit_property(profile, "compatible_printers")
|
||||||
if not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers):
|
if not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers):
|
||||||
print(f"'compatible_printers' missing in {file_path}")
|
print(f"'compatible_printers' missing in {profile['file_path']}")
|
||||||
error += 1
|
error += 1
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
print(f"Unable to parse {file_path}: {ve}")
|
print(f"Unable to parse {profile['file_path']}: {ve}")
|
||||||
error += 1
|
error += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -100,7 +104,7 @@ def load_available_filament_profiles(profiles_dir, vendor_name):
|
|||||||
|
|
||||||
for file_path in vendor_path.rglob("*.json"):
|
for file_path in vendor_path.rglob("*.json"):
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r') as fp:
|
with open(file_path, 'r', encoding='UTF-8') as fp:
|
||||||
data = json.load(fp)
|
data = json.load(fp)
|
||||||
if "name" in data:
|
if "name" in data:
|
||||||
profiles.add(data["name"])
|
profiles.add(data["name"])
|
||||||
@ -136,7 +140,7 @@ def check_machine_default_materials(profiles_dir, vendor_name):
|
|||||||
# Check each machine profile
|
# Check each machine profile
|
||||||
for file_path in machine_dir.rglob("*.json"):
|
for file_path in machine_dir.rglob("*.json"):
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r') as fp:
|
with open(file_path, 'r', encoding='UTF-8') as fp:
|
||||||
data = json.load(fp)
|
data = json.load(fp)
|
||||||
|
|
||||||
default_materials = None
|
default_materials = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user