main
noah amfm-receiver-molecule: KiCad project, fab files, 3D and README (6/7) 53707c4 1d ago
"""Run KiCad DRC (with schematic parity) and summarise the JSON report."""
import json, os, subprocess, sys
from collections import Counter

HERE = os.path.dirname(os.path.abspath(__file__))
PROJ = os.path.abspath(os.path.join(HERE, '..'))


def main(verbose=True):
    out = os.path.join(PROJ, 'build', 'drc.json')
    subprocess.run(['kicad-cli', 'pcb', 'drc', '--severity-all', '--schematic-parity', '--format', 'json',
                    '-o', out, os.path.join(PROJ, 'amfm_receiver.kicad_pcb')], capture_output=True)
    d = json.load(open(out))
    v, u, p = d.get('violations', []), d.get('unconnected_items', []), d.get('schematic_parity', [])
    print('DRC: %d violations, %d unconnected, %d schematic-parity issues' % (len(v), len(u), len(p)))
    for (t, s), n in Counter((x['type'], x['severity']) for x in v).most_common():
        print('   %-28s %-8s %d' % (t, s, n))
    if verbose:
        for x in v:
            if x['severity'] == 'error' or x['type'] in ('clearance', 'shorting_items', 'tracks_crossing',
                                                            'hole_clearance', 'copper_edge_clearance'):
                print('   E', x['type'], '|', ' / '.join(i['description'][:60] for i in x['items']))
        for x in u[:40]:
            print('   U', ' / '.join(i['description'][:60] for i in x['items']))
        for x in p[:20]:
            print('   P', x['type'], x['description'][:90], [i['description'][:50] for i in x['items']])
    return len([x for x in v if x['severity'] == 'error']), len(u), len(p)


if __name__ == '__main__':
    main('-q' not in sys.argv)