Refactor to main function
parent
1da9e0e534
commit
13682614cc
19
parse.py
19
parse.py
|
@ -60,13 +60,22 @@ def parse(input, format, **kwargs):
|
||||||
|
|
||||||
return schematic
|
return schematic
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
schematic = parse(**vars(args))
|
||||||
|
|
||||||
|
if args.output:
|
||||||
|
json_file = open(args.output, 'w')
|
||||||
|
json.dump(schematic, json_file, indent=4)
|
||||||
|
else:
|
||||||
|
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', '-i', dest='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('--output', '-o', 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', default='hierarchy', nargs='?',
|
parser.add_argument('format', nargs='?', default='json-hierarchy',
|
||||||
choices=['json-flat', 'json-hierarchy', 'parts-list', 'net-list'],
|
choices=['json-flat', 'json-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
|
json-flat, json-hierarchy: Organize records into owner/child "hierarchy" or leave as a "flat" list
|
||||||
|
@ -74,10 +83,4 @@ if __name__ == "__main__":
|
||||||
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'''))
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
schematic = parse(**vars(args))
|
main(args)
|
||||||
|
|
||||||
if args.output:
|
|
||||||
json_file = open(args.output, 'w')
|
|
||||||
json.dump(schematic, json_file, indent=4)
|
|
||||||
else:
|
|
||||||
print(schematic)
|
|
Loading…
Reference in New Issue