|
3 | 3 | import math |
4 | 4 | import coloredlogs, logging |
5 | 5 | from quine_mccluskey import qm |
6 | | -from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter |
| 6 | +from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, BooleanOptionalAction |
7 | 7 |
|
8 | 8 | # Copyright (c) maehw, 2022 |
9 | 9 | # wokwi-lookup-table-generator is licensed under the GNU General Public License v3.0 |
|
28 | 28 | help='path to generated wokwi schematic file', |
29 | 29 | default=None) |
30 | 30 |
|
| 31 | + parser.add_argument('-p', '--parts_only', |
| 32 | + action=BooleanOptionalAction, |
| 33 | + help='dump wokwi parts list only', |
| 34 | + default=0) |
| 35 | + |
| 36 | + parser.add_argument('-c', '--connections_only', |
| 37 | + action=BooleanOptionalAction, |
| 38 | + help='dump wokwi connections list only', |
| 39 | + default=0) |
| 40 | + |
31 | 41 | args = parser.parse_args() |
32 | 42 |
|
33 | 43 | # Create and configure logger object |
@@ -230,6 +240,9 @@ def allocate_next_free_or_gate_inport(): |
230 | 240 |
|
231 | 241 | log.info(f"Log level: {log_level}") |
232 | 242 |
|
| 243 | + if args.parts_only and args.connections_only: |
| 244 | + parser.error("Combination of -p and -c is currently not supported.") |
| 245 | + |
233 | 246 | # ------------------------------------------------------------------------------ |
234 | 247 | # generate insights about the design input data, i.e. log them to the console |
235 | 248 | # ------------------------------------------------------------------------------ |
@@ -697,10 +710,20 @@ def allocate_next_free_or_gate_inport(): |
697 | 710 |
|
698 | 711 | #log.debug( json.dumps(logic_meta, indent=4) ) |
699 | 712 |
|
| 713 | + wokwi_design_dump = wokwi_design |
| 714 | + |
| 715 | + # limit the dump; mutual exclusion of both options has been guaranteed earlier |
| 716 | + if args.parts_only: |
| 717 | + log.info("Only dumping wokwi parts.") |
| 718 | + wokwi_design_dump = wokwi_design["parts"] |
| 719 | + elif args.connections_only: |
| 720 | + log.info("Only dumping wokwi connections.") |
| 721 | + wokwi_design_dump = wokwi_design["connections"] |
| 722 | + |
700 | 723 | if args.out_file: |
701 | 724 | log.info(f"Writing final wokwi design file '{args.out_file}'...") |
702 | 725 | with open(args.out_file, 'w') as f: |
703 | | - json.dump(wokwi_design, f, indent=4) |
| 726 | + json.dump(wokwi_design_dump, f, indent=4) |
704 | 727 | else: |
705 | 728 | log.info("Dumping final wokwi design to stdout...") |
706 | | - print( json.dumps(wokwi_design, indent=4) ) |
| 729 | + print( json.dumps(wokwi_design_dump, indent=4) ) |
0 commit comments