added windows interaction test

adding more variant stuff
This commit is contained in:
brentperteet
2026-02-22 13:31:14 -06:00
parent 3f0aff923d
commit ab8d5c0c14
6 changed files with 461 additions and 43 deletions

View File

@@ -76,8 +76,22 @@ def apply_variant_to_schematic(schematic_file: str, variant_name: str, kicad_cli
dnp_parts = manager.get_dnp_parts(variant_name)
# Build property overrides dict: uuid -> {base + variant_overrides}
property_overrides = {}
base_values = manager.variants.get("base_values", {})
variant_overrides = manager.variants["variants"][variant_name].get("part_overrides", {})
# Merge base + variant overrides for each part
all_uuids = set(list(base_values.keys()) + list(variant_overrides.keys()))
for uuid in all_uuids:
props = base_values.get(uuid, {}).copy()
props.update(variant_overrides.get(uuid, {}))
if props:
property_overrides[uuid] = props
print(f"Applying variant '{variant_name}' to {Path(schematic_file).name}")
print(f"DNP parts ({len(dnp_parts)}): {dnp_parts}")
print(f"Property overrides for {len(property_overrides)} parts")
# Get all schematic files (root + hierarchical sheets)
all_schematics = get_all_schematic_files(schematic_file)
@@ -88,7 +102,7 @@ def apply_variant_to_schematic(schematic_file: str, variant_name: str, kicad_cli
# Process each schematic file
for idx, sch_file in enumerate(all_schematics):
is_root = (idx == 0) # First file is the root schematic
if not process_single_schematic(sch_file, dnp_parts, variant_name, is_root):
if not process_single_schematic(sch_file, dnp_parts, property_overrides, variant_name, is_root):
overall_success = False
if overall_success:
@@ -98,19 +112,22 @@ def apply_variant_to_schematic(schematic_file: str, variant_name: str, kicad_cli
return overall_success
def process_single_schematic(schematic_file: str, dnp_uuids: list, variant_name: str = None, is_root: bool = False) -> bool:
def process_single_schematic(schematic_file: str, dnp_uuids: list, property_overrides: dict = None, variant_name: str = None, is_root: bool = False) -> bool:
"""
Process a single schematic file to apply DNP flags.
Process a single schematic file to apply DNP flags and property overrides.
Args:
schematic_file: Path to .kicad_sch file
dnp_uuids: List of UUIDs that should be DNP
property_overrides: Dict of UUID -> {property_name: value} for property overrides
variant_name: Name of variant being applied (for title block)
is_root: True if this is the root schematic (not a sub-sheet)
Returns:
True if successful, False otherwise
"""
if property_overrides is None:
property_overrides = {}
sch_path = Path(schematic_file)
if not sch_path.exists():
print(f"Error: Schematic file not found: {schematic_file}")
@@ -228,6 +245,70 @@ def process_single_schematic(schematic_file: str, dnp_uuids: list, variant_name:
else:
print(f" Cleared DNP: {current_ref if current_ref else current_uuid}")
# Apply property overrides
# Parse through symbols and update properties for parts that have overrides
if property_overrides:
in_symbol = False
current_uuid = None
current_ref = None
symbol_start_indent = None
for i, line in enumerate(lines):
stripped = line.strip()
indent_level = len(line) - len(line.lstrip())
# Detect start of symbol
if stripped.startswith('(symbol'):
in_symbol = True
current_uuid = None
current_ref = None
symbol_start_indent = indent_level
# Detect end of symbol (closing paren at same indent level)
elif in_symbol and stripped == ')' and indent_level == symbol_start_indent:
in_symbol = False
current_uuid = None
current_ref = None
# Extract UUID when in symbol (at symbol level, not nested)
elif in_symbol and '(dnp' in stripped and not current_uuid:
# Look forward for UUID after DNP line
for j in range(i + 1, min(len(lines), i + 5)):
if '(uuid' in lines[j]:
if '\t(uuid' in lines[j] or ' (uuid' in lines[j]:
uuid_parts = lines[j].split('"')
if len(uuid_parts) >= 2:
current_uuid = uuid_parts[1]
break
# Extract reference (for logging)
elif in_symbol and '(property "Reference"' in stripped and not current_ref:
ref_parts = line.split('"')
if len(ref_parts) >= 4:
current_ref = ref_parts[3]
# Check if this symbol has property overrides
elif in_symbol and current_uuid and current_uuid in property_overrides:
overrides = property_overrides[current_uuid]
# Check each tracked property
for prop_name in ['Value', 'MPN', 'Manufacturer', 'IPN']:
if prop_name in overrides and f'(property "{prop_name}"' in stripped:
# Extract current value
parts = line.split('"')
if len(parts) >= 4:
current_value = parts[3]
new_value = overrides[prop_name]
# Update if different
if current_value != new_value:
# Reconstruct the line with new value
indent = line[:len(line) - len(line.lstrip())]
parts[3] = new_value
lines[i] = indent + '"'.join(parts)
modified = True
print(f" Set {prop_name}: {current_ref if current_ref else current_uuid} = {new_value} (was {current_value})")
if modified:
# Backup original file
backup_path = sch_path.with_suffix('.kicad_sch.bak')