From 13682614cc40c52ad38b2ae831b6c4fd0ca23245 Mon Sep 17 00:00:00 2001 From: Aaron Goldstein Date: Sat, 7 Mar 2020 00:12:06 -0800 Subject: [PATCH] Refactor to main function --- parse.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/parse.py b/parse.py index 24abd8c..1cdeaac 100644 --- a/parse.py +++ b/parse.py @@ -60,13 +60,22 @@ def parse(input, format, **kwargs): 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__": parser = argparse.ArgumentParser(description='Converts Altium .SchDoc files into json.', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--input', '-i', dest='input', help='path/to/altiumschematic.schdoc file to parse') parser.add_argument('--output', '-o', dest='output', 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'], help=textwrap.dedent('''\ 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''')) args = parser.parse_args() - schematic = parse(**vars(args)) - - if args.output: - json_file = open(args.output, 'w') - json.dump(schematic, json_file, indent=4) - else: - print(schematic) \ No newline at end of file + main(args) \ No newline at end of file