diff options
author | Michael Schwarz <michi.schwarz@gmail.com> | 2015-08-06 16:32:35 +0200 |
---|---|---|
committer | Michael Schwarz <michi.schwarz@gmail.com> | 2015-08-07 02:03:33 +0200 |
commit | 5a1604ce202077da2823bf63f4400dd9343a17df (patch) | |
tree | 874f57c9243f6b70ff5f24cd8dda65d5664714fe | |
parent | 6bce36b6ede16d28626d40a0b4d60954a35ad48f (diff) | |
download | pogojig-5a1604ce202077da2823bf63f4400dd9343a17df.tar.gz pogojig-5a1604ce202077da2823bf63f4400dd9343a17df.tar.bz2 pogojig-5a1604ce202077da2823bf63f4400dd9343a17df.zip |
Use Python script to run Asymptote.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | support/asymptote/__init__.py | 0 | ||||
-rw-r--r-- | support/asymptote/__main__.py | 24 | ||||
-rw-r--r-- | support/lib/util.py | 17 |
4 files changed, 33 insertions, 10 deletions
@@ -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) diff --git a/support/asymptote/__init__.py b/support/asymptote/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/support/asymptote/__init__.py diff --git a/support/asymptote/__main__.py b/support/asymptote/__main__.py new file mode 100644 index 0000000..1816224 --- /dev/null +++ b/support/asymptote/__main__.py @@ -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) diff --git a/support/lib/util.py b/support/lib/util.py index 3c5117d..54b92f0 100644 --- a/support/lib/util.py +++ b/support/lib/util.py @@ -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() |