duplication key error check
This commit is contained in:
parent
e12ca90f62
commit
d839c52114
2 changed files with 22 additions and 9 deletions
|
@ -19,9 +19,6 @@
|
||||||
"filament_cost": [
|
"filament_cost": [
|
||||||
"30"
|
"30"
|
||||||
],
|
],
|
||||||
"additional_cooling_fan_speed": [
|
|
||||||
"80"
|
|
||||||
],
|
|
||||||
"cool_plate_temp": [
|
"cool_plate_temp": [
|
||||||
"50"
|
"50"
|
||||||
],
|
],
|
||||||
|
|
|
@ -3,6 +3,14 @@ import json
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Add helper function for duplicate key detection.
|
||||||
|
def no_duplicates_object_pairs_hook(pairs):
|
||||||
|
seen = {}
|
||||||
|
for key, value in pairs:
|
||||||
|
if key in seen:
|
||||||
|
raise ValueError(f"Duplicate key detected: {key}")
|
||||||
|
seen[key] = value
|
||||||
|
return seen
|
||||||
|
|
||||||
def check_filament_compatible_printers(vendor_folder):
|
def check_filament_compatible_printers(vendor_folder):
|
||||||
"""
|
"""
|
||||||
|
@ -23,14 +31,22 @@ def check_filament_compatible_printers(vendor_folder):
|
||||||
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') as fp:
|
||||||
data = json.load(fp)
|
# Use custom hook to detect duplicates.
|
||||||
instantiation = str(data.get("instantiation", "")).lower() == "true"
|
data = json.load(fp, object_pairs_hook=no_duplicates_object_pairs_hook)
|
||||||
compatible_printers = data.get("compatible_printers")
|
except ValueError as ve:
|
||||||
if instantiation and (not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers)):
|
print(f"Duplicate key error in {file_path}: {ve}")
|
||||||
print(file_path)
|
error += 1
|
||||||
error += 1
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing {file_path}: {e}")
|
print(f"Error processing {file_path}: {e}")
|
||||||
|
error += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
instantiation = str(data.get("instantiation", "")).lower() == "true"
|
||||||
|
compatible_printers = data.get("compatible_printers")
|
||||||
|
if instantiation and (not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers)):
|
||||||
|
print(file_path)
|
||||||
|
error += 1
|
||||||
return error
|
return error
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue