Skip to content

Commit 728be0c

Browse files
committed
Implement Eric's suggestion to limit the dump to wokwi parts/connections only; update README.md
1 parent 6e90108 commit 728be0c

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ This project is WIP. Feel free to contribute, open issues, etc.
1010
## Usage
1111

1212
```
13-
$ python3 generate.py -h
14-
usage: generate.py [-h] [-v] [-f IN_FILE] [-o OUT_FILE]
13+
$ usage: generate.py [-h] [-v] [-f IN_FILE] [-o OUT_FILE] [-p | --parts_only | --no-parts_only] [-c | --connections_only | --no-connections_only]
1514
1615
generate.py is a lookup table generator tool for wokwi
1716
@@ -22,6 +21,10 @@ options:
2221
path to JSON logic input file; if none is given, stdout is used (default: logic.json)
2322
-o OUT_FILE, --outfile OUT_FILE
2423
path to generated wokwi schematic file (default: None)
24+
-p, --parts_only, --no-parts_only
25+
dump wokwi parts list only (default: 0)
26+
-c, --connections_only, --no-connections_only
27+
dump wokwi connections list only (default: 0)
2528
```
2629

2730
Examples:
@@ -50,6 +53,14 @@ Specify an output file for the wokwi schematic externally but also show contents
5053
python3 generate.py -f 2bit_half_adder.logic.json | tee 2bit_half_adder.diagram.json
5154
```
5255

56+
Switches `-p` and `-c` allow to limit the dump to wokwi parts ony respectively wokwi connections only.
57+
58+
This feature can be used to modify existing designs only. The following command can be used on Mac OS X to **copy** the parts of the design into the **p**aste **b**uffer:
59+
60+
```
61+
python3 generate.py -f bcd_7segment_lut.logic.json -p | sed 's/[{}]//' | pbcopy
62+
```
63+
5364

5465
After having generated your diagram JSON file, ...
5566

generate.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import math
44
import coloredlogs, logging
55
from quine_mccluskey import qm
6-
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
6+
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, BooleanOptionalAction
77

88
# Copyright (c) maehw, 2022
99
# wokwi-lookup-table-generator is licensed under the GNU General Public License v3.0
@@ -28,6 +28,16 @@
2828
help='path to generated wokwi schematic file',
2929
default=None)
3030

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+
3141
args = parser.parse_args()
3242

3343
# Create and configure logger object
@@ -230,6 +240,9 @@ def allocate_next_free_or_gate_inport():
230240

231241
log.info(f"Log level: {log_level}")
232242

243+
if args.parts_only and args.connections_only:
244+
parser.error("Combination of -p and -c is currently not supported.")
245+
233246
# ------------------------------------------------------------------------------
234247
# generate insights about the design input data, i.e. log them to the console
235248
# ------------------------------------------------------------------------------
@@ -697,10 +710,20 @@ def allocate_next_free_or_gate_inport():
697710

698711
#log.debug( json.dumps(logic_meta, indent=4) )
699712

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+
700723
if args.out_file:
701724
log.info(f"Writing final wokwi design file '{args.out_file}'...")
702725
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)
704727
else:
705728
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

Comments
 (0)