Use Python script to run Asymptote.

This commit is contained in:
Michael Schwarz 2015-08-06 16:32:35 +02:00
parent 6bce36b6ed
commit 5a1604ce20
4 changed files with 33 additions and 10 deletions

View file

@ -84,7 +84,7 @@ $(SCAD_STL_FILES): %.stl: %.scad $(GLOBAL_DEPS) | $(SCAD_ORDER_DEPS)
# Rule to export an SVG file to an Asymptote file.
$(ASY_PDF_FILES): %.pdf: %.asy $(GLOBAL_DEPS) $(COMPILED_SRC_FILES) $(SVG_ASY_FILES)
ASYMPTOTE_DIR=$$(dirname $@) $(ASYMPTOTE) -f pdf -o $@ $<
$(ASYMPTOTE_CMD) $*.asy $@
# Rule for automaticaly generated OpenSCAD files.
$(GENERATED_FILES): generate_sources.sh $(GLOBAL_DEPS)

View file

View file

@ -0,0 +1,24 @@
import os, sys
from lib import util
def _asymptote(in_path, out_path, asymptote_dir):
util.command([os.environ['ASYMPTOTE'], '-f', 'pdf', '-o', out_path, in_path], set_env = { 'ASYMPTOTE_DIR': asymptote_dir })
def main(in_path, out_path):
_, out_suffix = os.path.splitext(out_path)
if out_suffix == '.pdf':
_asymptote(in_path, out_path, os.path.dirname(in_path))
else:
raise Exception('Unknown file type: {}'.format(out_suffix))
try:
main(*sys.argv[1:])
except util.UserError as e:
print 'Error:', e
sys.exit(1)
except KeyboardInterrupt:
sys.exit(2)

View file

@ -27,15 +27,14 @@ def TemporaryDirectory():
shutil.rmtree(dir)
def command(args, remove_env = None):
if remove_env is None:
env = None
else:
env = dict(os.environ)
for i in remove_env:
if i in env:
del env[i]
def command(args, remove_env = [], set_env = { }):
env = dict(os.environ)
for i in remove_env:
del env[i]
for k, v in set_env.items():
env[k] = v
process = subprocess.Popen(args, env = env)
process.wait()