Make args a little easier to understand, Separate out hierarchy determination, Make parts-list determination simpler
parent
57d366345c
commit
78814409d4
|
@ -55,3 +55,4 @@ Temporary Items
|
||||||
*.OutJob
|
*.OutJob
|
||||||
*.SchDoc.Zip
|
*.SchDoc.Zip
|
||||||
*.OutJob.Zip
|
*.OutJob.Zip
|
||||||
|
/tests/altium_crap/Snippets/Schematic/Free Documents.OutJob
|
||||||
|
|
43
parse.py
43
parse.py
|
@ -34,6 +34,17 @@ def parse(input, format, **kwargs):
|
||||||
schematic["header"] = [x for x in datums if 'HEADER' in x.keys()]
|
schematic["header"] = [x for x in datums if 'HEADER' in x.keys()]
|
||||||
schematic["records"] = [x for x in datums if 'RECORD' in x.keys()]
|
schematic["records"] = [x for x in datums if 'RECORD' in x.keys()]
|
||||||
|
|
||||||
|
hierarchy_schematic = determine_hierarchy(schematic)
|
||||||
|
if format == 'all-hierarchy':
|
||||||
|
schematic = hierarchy_schematic
|
||||||
|
elif format == 'parts-list':
|
||||||
|
schematic = determine_parts_list(hierarchy_schematic)
|
||||||
|
elif format == 'net-list':
|
||||||
|
schematic = determine_net_list(hierarchy_schematic)
|
||||||
|
|
||||||
|
return schematic
|
||||||
|
|
||||||
|
def determine_hierarchy(schematic):
|
||||||
# prep a scratchpad copy of records to build hierarchy from
|
# prep a scratchpad copy of records to build hierarchy from
|
||||||
records_copy = copy.deepcopy(schematic["records"])
|
records_copy = copy.deepcopy(schematic["records"])
|
||||||
schematic["hierarchy"] = []
|
schematic["hierarchy"] = []
|
||||||
|
@ -53,44 +64,40 @@ def parse(input, format, **kwargs):
|
||||||
|
|
||||||
owner["children"].append(current)
|
owner["children"].append(current)
|
||||||
|
|
||||||
if format == 'json-hierarchy':
|
|
||||||
schematic["records"] = schematic["hierarchy"]
|
schematic["records"] = schematic["hierarchy"]
|
||||||
|
|
||||||
schematic.pop("hierarchy", None)
|
schematic.pop("hierarchy", None)
|
||||||
|
|
||||||
return schematic
|
return schematic
|
||||||
|
|
||||||
def determine_parts_list(schematic):
|
def determine_parts_list(schematic):
|
||||||
print('determine parts list')
|
parts_list = {
|
||||||
for record in schematic["records"]:
|
"records": [ record for record in schematic["records"] if record["RECORD"] is "1" ]
|
||||||
if record["RECORD"] is "1":
|
}
|
||||||
print("part: " + str(record))
|
return parts_list
|
||||||
|
|
||||||
|
def determine_net_list(schematic):
|
||||||
|
print('NOT IMPLEMENTED')
|
||||||
|
return schematic
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
schematic = parse(**vars(args))
|
schematic = parse(**vars(args))
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
if args.format in ('json-flat', 'json-hierarchy'):
|
|
||||||
json_file = open(args.output, 'w')
|
json_file = open(args.output, 'w')
|
||||||
json.dump(schematic, json_file, indent=4)
|
json.dump(schematic, json_file, indent=4)
|
||||||
elif args.format == 'parts-list':
|
|
||||||
print('blah')
|
|
||||||
determine_parts_list(schematic)
|
|
||||||
else:
|
|
||||||
print('no format')
|
|
||||||
else:
|
else:
|
||||||
print(schematic)
|
print(schematic)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Converts Altium .SchDoc files into json.', formatter_class=argparse.RawTextHelpFormatter)
|
parser = argparse.ArgumentParser(description='Converts Altium .SchDoc files into json.', formatter_class=argparse.RawTextHelpFormatter)
|
||||||
parser.add_argument('--input', '-i', dest='input',
|
parser.add_argument('input',
|
||||||
help='path/to/altiumschematic.schdoc file to parse')
|
help='path/to/altiumschematic.schdoc file to parse')
|
||||||
parser.add_argument('--output', '-o', dest='output',
|
parser.add_argument('-o', '--output', dest='output',
|
||||||
help='path/to/jsonfile.json file to output json to, otherwise prints to terminal')
|
help='path/to/jsonfile.json file to output json to, otherwise prints to terminal')
|
||||||
parser.add_argument('format', nargs='?', default='json-hierarchy',
|
parser.add_argument('-f', '--format', dest='format', default='all-hierarchy',
|
||||||
choices=['json-flat', 'json-hierarchy', 'parts-list', 'net-list'],
|
choices=['all-list', 'all-hierarchy', 'parts-list', 'net-list'],
|
||||||
help=textwrap.dedent('''\
|
help=textwrap.dedent('''\
|
||||||
json-flat, json-hierarchy: Organize records into owner/child "hierarchy" or leave as a "flat" list
|
all-list: All records in a flattened list
|
||||||
|
all-hierarchy: All records in an owner/child "hierarchy"
|
||||||
parts-list: A listing of parts and their designators
|
parts-list: A listing of parts and their designators
|
||||||
net-list: A listing of nets between parts pins, referred to by their designators'''))
|
net-list: A listing of nets between parts pins, referred to by their designators'''))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue