From 32a56dd0daa491439d28792d3e3b8db11805e799 Mon Sep 17 00:00:00 2001 From: Eric Van Albert Date: Sat, 17 Jun 2017 22:15:46 -0400 Subject: [PATCH] add keygen.py --- Makefile | 2 -- bin/keygen.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100755 bin/keygen.py diff --git a/Makefile b/Makefile index f6f73e6..3bebcc7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ # Makefile for keygen # Executables -SCAD = openscad POLY = PYTHONPATH=/usr/share/inkscape/extensions bin/paths2openscad.py SCAD_DIR = scad @@ -20,7 +19,6 @@ POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC)) JSON_OBJ = $(patsubst $(SCAD_DIR)/%.scad,$(JSON_DIR)/%.json,$(SCAD_SRC)) POLYFLAGS = -SCADFLAGS = # Targets all: $(JSON_DIR)/keys.json poly diff --git a/bin/keygen.py b/bin/keygen.py new file mode 100755 index 0000000..aa3a7fd --- /dev/null +++ b/bin/keygen.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import argparse +import os +import string +import sys +import subprocess + +parser = argparse.ArgumentParser(description='Generates keys', epilog='All remaining arguments are passed to OpenSCAD.') +parser.add_argument("filename", + help="OpenSCAD source file for the key") +parser.add_argument("-b", "--bitting", dest='bitting', + help="Key bitting") +parser.add_argument("-u", "--outline", dest='outline', + help="Key blank outline") +parser.add_argument("-w", "--warding", dest='warding', + help="Key warding") +parser.add_argument("-o", "--output", dest='output', default="a.stl", + help="Output file (defaults to a.stl)") + +(args, remaining) = parser.parse_known_args() + +def escape(s): + return s.translate(str.maketrans({'"': '\\"', + '\\': '\\\\'})); + +scad = os.environ.get("SCAD", "openscad") +opts = [] +if args.bitting is not None: + opts += ["-D", 'bitting="{}"'.format(escape(args.bitting))] +if args.outline is not None: + opts += ["-D", 'outline="{}"'.format(escape(args.outline))] +if args.warding is not None: + opts += ["-D", 'warding="{}"'.format(escape(args.warding))] + +r = subprocess.call([scad, args.filename, "-o", args.output] + opts + remaining) +sys.exit(r)