mirror of
https://github.com/ervanalb/keygen.git
synced 2025-12-16 13:25:25 +00:00
json file generation
This commit is contained in:
12
Makefile
12
Makefile
@@ -8,6 +8,7 @@ SCAD_DIR = src
|
||||
SVG_DIR = resources
|
||||
POLY_DIR = build
|
||||
STL_DIR = build
|
||||
JSON_DIR = build
|
||||
|
||||
# Files to include
|
||||
SVG_SRC = $(wildcard $(SVG_DIR)/*.svg)
|
||||
@@ -17,9 +18,10 @@ SCAD_SRC = $(SCAD_DIR)/schlage.scad
|
||||
POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC))
|
||||
|
||||
# Generated STL
|
||||
STL_OBJ =
|
||||
STL_OBJ = # populated in .d files
|
||||
|
||||
OBJECTS = $(POLYGON_OBJ) $(STL_OBJ)
|
||||
# Generated JSON files
|
||||
JSON_OBJ = $(patsubst $(SCAD_DIR)/%.scad,$(JSON_DIR)/%.json,$(SCAD_SRC))
|
||||
|
||||
POLYFLAGS =
|
||||
SCADFLAGS =
|
||||
@@ -28,9 +30,11 @@ SCADFLAGS =
|
||||
all: stl
|
||||
poly: $(POLY_OBJ)
|
||||
$(STL_DIR)/%.d: $(SCAD_DIR)/%.scad
|
||||
bin/parse.py $< $@
|
||||
bin/parse.py $< $(STL_DIR)/$*.d $(JSON_DIR)/$*.json
|
||||
$(JSON_DIR)/%.json: $(SCAD_DIR)/%.scad
|
||||
bin/parse.py $< $(STL_DIR)/$*.d $(JSON_DIR)/$*.json
|
||||
clean:
|
||||
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl $(STL_DIR)/*.d
|
||||
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl $(STL_DIR)/*.d $(JSON_DIR)/*.json
|
||||
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
|
||||
$(POLY) $(POLYFLAGS) --fname $@ $<
|
||||
|
||||
|
||||
23
bin/parse.py
23
bin/parse.py
@@ -9,6 +9,7 @@ import itertools
|
||||
|
||||
scad_fn = sys.argv[1]
|
||||
d_fn = sys.argv[2]
|
||||
json_fn = sys.argv[3]
|
||||
|
||||
with open(scad_fn) as f:
|
||||
scad_text = f.read()
|
||||
@@ -16,6 +17,10 @@ with open(scad_fn) as f:
|
||||
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
||||
|
||||
modules = re.findall(r"module\s+([^\s\(]+)\s*\("
|
||||
r".+"
|
||||
r'name\s*=\s*("[^"]+")'
|
||||
r".+"
|
||||
r'/\*(.+?)\*/'
|
||||
r".+"
|
||||
r"outlines_k\s*=\s*(\[[^\]]+\])"
|
||||
r".+"
|
||||
@@ -28,9 +33,11 @@ if len(modules) == 0:
|
||||
|
||||
module = modules[0]
|
||||
|
||||
(n, os, ws) = module
|
||||
(m, n, d, os, ws) = module
|
||||
|
||||
# Dirty hack to parse OpenSCAD lists
|
||||
# Dirty hack to parse OpenSCAD types
|
||||
n = json.loads(n)
|
||||
d = d.strip()
|
||||
os = json.loads(os)
|
||||
ws = json.loads(ws)
|
||||
|
||||
@@ -40,7 +47,7 @@ def sanitize(s):
|
||||
all_keys = [(n, o, w) for o in os for w in ws]
|
||||
|
||||
def stl_filename(n, o, w):
|
||||
return "$(STL_DIR)/{n}_{o_s}_{w_s}.stl".format(n=n, o=o, w=w, o_s=sanitize(o), w_s=sanitize(w))
|
||||
return "$(STL_DIR)/{n_s}_{o_s}_{w_s}.stl".format(n_s=sanitize(n), o_s=sanitize(o), w_s=sanitize(w))
|
||||
|
||||
all_keys_makefile = ["{stl_fn}: {scad_fn} {deps}\n\t$(SCAD) $(SCADFLAGS) -D 'outline=\"{o}\"' -D 'warding=\"{w}\"' {scad_fn} -o $@"
|
||||
.format(n=n, o=o, w=w,
|
||||
@@ -52,3 +59,13 @@ all_keys_makefile.append("STL_OBJ += {}".format(" \\\n ".join(all_stl)))
|
||||
with open(d_fn, "w") as f:
|
||||
print("\n".join(all_keys_makefile), file=f
|
||||
)
|
||||
|
||||
json_obj = {
|
||||
"name": n,
|
||||
"description": d,
|
||||
"outlines": os,
|
||||
"wardings": ws
|
||||
}
|
||||
|
||||
with open(json_fn, "w") as f:
|
||||
print(json.dumps(json_obj), file=f)
|
||||
|
||||
@@ -7,6 +7,11 @@ module schlage_classic(bitting="",
|
||||
|
||||
name = "Schlage Classic";
|
||||
|
||||
/*
|
||||
Bitting is specified from bow to tip, 0-9, with 0 being the shallowest cut and 9 being the deepest.
|
||||
Example: 25363
|
||||
*/
|
||||
|
||||
outlines_k = ["5-pin",
|
||||
"6-pin"];
|
||||
outlines_v = [[outline_5pin_points, outline_5pin_paths,
|
||||
|
||||
Reference in New Issue
Block a user