mirror of
https://github.com/ervanalb/keygen.git
synced 2025-12-16 13:25:25 +00:00
improve dependencies
This commit is contained in:
4
Makefile
4
Makefile
@@ -11,7 +11,7 @@ STL_DIR = build
|
|||||||
|
|
||||||
# Files to include
|
# Files to include
|
||||||
SVG_SRC = $(wildcard $(SVG_DIR)/*.svg)
|
SVG_SRC = $(wildcard $(SVG_DIR)/*.svg)
|
||||||
SCAD_SRC = $(wildcard $(SCAD_DIR)/*.scad)
|
SCAD_SRC = $(SCAD_DIR)/schlage.scad
|
||||||
|
|
||||||
# Generated polygon files
|
# Generated polygon files
|
||||||
POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC))
|
POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC))
|
||||||
@@ -28,7 +28,7 @@ SCADFLAGS =
|
|||||||
all: stl
|
all: stl
|
||||||
poly: $(POLY_OBJ)
|
poly: $(POLY_OBJ)
|
||||||
$(STL_DIR)/%.d: $(SCAD_DIR)/%.scad
|
$(STL_DIR)/%.d: $(SCAD_DIR)/%.scad
|
||||||
BUILD_DIR=$(STL_DIR) bin/parse.py $<
|
bin/parse.py $< $@
|
||||||
clean:
|
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
|
||||||
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
|
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
|
||||||
|
|||||||
31
bin/parse.py
31
bin/parse.py
@@ -7,11 +7,10 @@ import json
|
|||||||
import string
|
import string
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
build_dir = os.environ.get("BUILD_DIR", "")
|
scad_fn = sys.argv[1]
|
||||||
|
d_fn = sys.argv[2]
|
||||||
|
|
||||||
fn = sys.argv[1]
|
with open(scad_fn) as f:
|
||||||
|
|
||||||
with open(fn) as f:
|
|
||||||
scad_text = f.read()
|
scad_text = f.read()
|
||||||
|
|
||||||
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
poly_reqs = re.findall(r'<(.+\.gen\.scad)>', scad_text)
|
||||||
@@ -23,29 +22,33 @@ modules = re.findall(r"module\s+([^\s\(]+)\s*\("
|
|||||||
r"wardings_k\s*=\s*(\[[^\]]+\])"
|
r"wardings_k\s*=\s*(\[[^\]]+\])"
|
||||||
, scad_text, flags=re.S)
|
, scad_text, flags=re.S)
|
||||||
|
|
||||||
modules_parsed = [(n, json.loads(o), json.loads(w)) for (n, o, w) in modules]
|
if len(modules) == 0:
|
||||||
|
print("Could not find any compatible modules in {}".format(scad_fn), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
module = modules[0]
|
||||||
|
|
||||||
|
(n, os, ws) = module
|
||||||
|
|
||||||
|
# Dirty hack to parse OpenSCAD lists
|
||||||
|
os = json.loads(os)
|
||||||
|
ws = json.loads(ws)
|
||||||
|
|
||||||
def sanitize(s):
|
def sanitize(s):
|
||||||
return "".join([c for c in s.lower() if c in string.ascii_lowercase + string.digits])
|
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]
|
all_keys = [(n, o, w) for o in os for w in ws]
|
||||||
|
|
||||||
def stl_filename(n, o, w):
|
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}_{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 $@"
|
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,
|
.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]))
|
scad_fn=scad_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]
|
for (n, o, w) in all_keys]
|
||||||
all_stl = [stl_filename(n, o, w) 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("STL_OBJ += {}".format(" \\\n ".join(all_stl)))
|
all_keys_makefile.append("STL_OBJ += {}".format(" \\\n ".join(all_stl)))
|
||||||
|
|
||||||
def stripfn(fn):
|
with open(d_fn, "w") as f:
|
||||||
fn = os.path.basename(fn)
|
|
||||||
if fn.endswith(".scad"):
|
|
||||||
fn = fn[:-5]
|
|
||||||
return fn
|
|
||||||
|
|
||||||
with open(os.path.join(build_dir, "{}.d".format(stripfn(fn))), "w") as f:
|
|
||||||
print("\n".join(all_keys_makefile), file=f
|
print("\n".join(all_keys_makefile), file=f
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user