Add check for profile name consistency

(cherry picked from commit 7343aa5b55cab9a9f7cbdcdddd4e7650f1577598)
This commit is contained in:
Noisyfox 2025-04-15 17:09:03 +08:00
parent 5a39e6beda
commit eb38474bb2

View file

@ -139,8 +139,61 @@ def check_machine_default_materials(profiles_dir, vendor_name):
return error_count
def check_name_consistency(profiles_dir, vendor_name):
"""
Make sure profile names match in both vendor json and subpath files
"""
error_count = 0
vendor_dir = profiles_dir / vendor_name
vendor_file = profiles_dir / (vendor_name + ".json")
if not vendor_file.exists():
print(f"No profiles found for vendor: {vendor_name} at {vendor_file}")
return 0
try:
with open(vendor_file, 'r', encoding='UTF-8') as fp:
data = json.load(fp)
except Exception as e:
print(f"Error loading vendor profile {vendor_file}: {e}")
return 1
for sect in [
'machine_model_list',
'process_list',
'filament_list',
'machine_list',
]:
if sect not in data:
continue
for child in data[sect]:
name_in_vendor = child['name']
sub_path = child['sub_path']
sub_file = vendor_dir / sub_path
if not sub_file.exists():
print(f"Missing sub profile: '{sub_path}' declared in {vendor_file.relative_to(profiles_dir)}")
error_count += 1
continue
try:
with open(sub_file, 'r', encoding='UTF-8') as fp:
sub_data = json.load(fp)
except Exception as e:
print(f"Error loading profile {sub_file}: {e}")
error_count += 1
continue
name_in_sub = sub_data['name']
if not name_in_vendor == name_in_sub:
print(f"Profile name mismatch: '{name_in_vendor}' in {vendor_file.relative_to(profiles_dir)} but '{name_in_sub}' in {sub_file.relative_to(profiles_dir)}")
error_count += 1
return error_count
def main():
print("Checking compatible_printers ...")
print("Checking profiles ...")
parser = argparse.ArgumentParser(description="Check profiles for issues")
parser.add_argument("--vendor", type=str, required=False, help="Vendor name")
parser.add_argument("--check-filaments", default=True, action="store_true", help="Check compatible_printers in filament profiles")
@ -157,17 +210,20 @@ def main():
errors_found += check_filament_compatible_printers(profiles_dir / args.vendor / "filament")
if args.check_materials:
errors_found += check_machine_default_materials(profiles_dir, args.vendor)
errors_found += check_name_consistency(profiles_dir, args.vendor)
checked_vendor_count += 1
else:
for vendor_dir in profiles_dir.iterdir():
if not vendor_dir.is_dir():
continue
errors_found += check_name_consistency(profiles_dir, vendor_dir.name)
# skip "OrcaFilamentLibrary" folder
if vendor_dir.name == "OrcaFilamentLibrary":
continue
if vendor_dir.is_dir():
if args.check_filaments or not (args.check_materials and not args.check_filaments):
errors_found += check_filament_compatible_printers(vendor_dir / "filament")
if args.check_materials:
errors_found += check_machine_default_materials(profiles_dir, vendor_dir.name)
if args.check_filaments or not (args.check_materials and not args.check_filaments):
errors_found += check_filament_compatible_printers(vendor_dir / "filament")
if args.check_materials:
errors_found += check_machine_default_materials(profiles_dir, vendor_dir.name)
checked_vendor_count += 1
if errors_found > 0: