mirror of
https://github.com/ervanalb/keygen.git
synced 2025-12-16 13:25:25 +00:00
python dependency generation
This commit is contained in:
9
Makefile
9
Makefile
@@ -21,14 +21,17 @@ STL_OBJ =
|
||||
|
||||
OBJECTS = $(POLYGON_OBJ) $(STL_OBJ)
|
||||
|
||||
# Assembler, compiler, and linker flags
|
||||
POLYFLAGS =
|
||||
SCADFLAGS =
|
||||
|
||||
# Targets
|
||||
all: $(STL_OBJ)
|
||||
all: all_stl
|
||||
poly: $(POLY_OBJ)
|
||||
$(STL_DIR)/key_blanks.d:
|
||||
BUILD_DIR=$(STL_DIR) bin/parse.py $(SCAD_SRC)
|
||||
clean:
|
||||
-rm -f $(OBJECTS)
|
||||
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl
|
||||
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
|
||||
$(POLY) $(POLYFLAGS) --fname $@ $<
|
||||
|
||||
include $(STL_DIR)/key_blanks.d
|
||||
|
||||
49
bin/parse.py
Executable file
49
bin/parse.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import string
|
||||
import itertools
|
||||
|
||||
def handle(fn):
|
||||
with open(fn) as f:
|
||||
scad_text = f.read()
|
||||
|
||||
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
||||
|
||||
modules = re.findall(r"module\s+([^\s\(]+)\s*\("
|
||||
r".+"
|
||||
r"outlines_k\s*=\s*(\[[^\]]+\])"
|
||||
r".+"
|
||||
r"wardings_k\s*=\s*(\[[^\]]+\])"
|
||||
, scad_text, flags=re.S)
|
||||
|
||||
modules_parsed = [(n, json.loads(o), json.loads(w)) for (n, o, w) in modules]
|
||||
|
||||
def sanitize(s):
|
||||
return "".join([c for c in s.lower() if c in string.ascii_lowercase + string.digits])
|
||||
|
||||
all_keys = [(n, o, w) for (n, os, ws) in modules_parsed 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))
|
||||
|
||||
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,
|
||||
scad_fn=fn, stl_fn=stl_filename(n, o, w), deps=" ".join(["$(POLY_DIR)/{}".format(r) for r in poly_reqs]))
|
||||
for (n, o, w) in all_keys]
|
||||
all_stl = [stl_filename(n, o, w) for (n, o, w) in all_keys]
|
||||
all_keys_makefile.append("all_stl: {}".format(" \\\n ".join(all_stl)))
|
||||
|
||||
return all_keys, all_keys_makefile
|
||||
|
||||
all_keys, all_keys_makefile = (list(itertools.chain.from_iterable(e)) for e in zip(*[handle(fn) for fn in sys.argv[1:]]))
|
||||
|
||||
d = os.environ.get("BUILD_DIR", "")
|
||||
|
||||
with open(os.path.join(d, "key_blanks.d"), "w") as f:
|
||||
print("\n".join(all_keys_makefile), file=f)
|
||||
with open(os.path.join(d, "key_blanks.json"), "w") as f:
|
||||
print(json.dumps(all_keys), file=f)
|
||||
@@ -2,11 +2,11 @@ use <keygen.scad>
|
||||
include <schlage.gen.scad>
|
||||
|
||||
module schlage_classic(bitting="",
|
||||
outline_name="5pin",
|
||||
warding_name="c") {
|
||||
outline_name="5-pin",
|
||||
warding_name="C") {
|
||||
|
||||
outlines_k = ["5pin",
|
||||
"6pin"];
|
||||
outlines_k = ["5-pin",
|
||||
"6-pin"];
|
||||
outlines_v = [[outline_5pin_points, outline_5pin_paths,
|
||||
[-outline_5pin_points[92][0], -outline_5pin_points[98][1]],
|
||||
engrave_5pin_points,
|
||||
@@ -15,16 +15,16 @@ module schlage_classic(bitting="",
|
||||
[-outline_6pin_points[92][0], -outline_6pin_points[98][1]],
|
||||
engrave_6pin_points,
|
||||
engrave_6pin_paths]];
|
||||
wardings_k = ["c",
|
||||
"ce",
|
||||
"e",
|
||||
"ef",
|
||||
"f",
|
||||
"fg",
|
||||
"h",
|
||||
"j",
|
||||
"k",
|
||||
"l"];
|
||||
wardings_k = ["C",
|
||||
"CE",
|
||||
"E",
|
||||
"EF",
|
||||
"F",
|
||||
"FG",
|
||||
"H",
|
||||
"J",
|
||||
"K",
|
||||
"L"];
|
||||
wardings_v = [warding_c_points,
|
||||
warding_ce_points,
|
||||
warding_e_points,
|
||||
@@ -68,7 +68,8 @@ module schlage_classic(bitting="",
|
||||
}
|
||||
}
|
||||
|
||||
// Defaults
|
||||
bitting="";
|
||||
outline="5pin";
|
||||
warding="c";
|
||||
outline="5-pin";
|
||||
warding="C";
|
||||
schlage_classic(bitting, outline, warding);
|
||||
|
||||
Reference in New Issue
Block a user