diff --git a/openscad_utils.py b/openscad_utils.py index b7a48d5..03b3bf6 100644 --- a/openscad_utils.py +++ b/openscad_utils.py @@ -1,4 +1,4 @@ -import py, re, os, signal, time +import py, re, os, signal, time, commands from subprocess import Popen, PIPE mod_re = (r"\bmodule\s+(", r")\s*\(\s*") @@ -30,26 +30,33 @@ def collect_test_modules(dirpath=None): class Timeout(Exception): pass def call_openscad(path, stlpath, timeout=1): - try: - command = ['openscad', '-s', str(stlpath), str(path)] - print command - proc = Popen(command, - stdout=PIPE, stderr=PIPE, close_fds=True) - calltime = time.time() - time.sleep(0.01) - #print calltime - while True: - if proc.poll() is not None: - break - time.sleep(0.5) - #print time.time() - if time.time() > calltime + timeout: - raise Timeout() - finally: + command = ['openscad', '-s', str(stlpath), str(path)] + print command + if timeout: try: - proc.terminate() - proc.kill() - except OSError: - pass + proc = Popen(command, + stdout=PIPE, stderr=PIPE, close_fds=True) + calltime = time.time() + time.sleep(0.01) + #print calltime + while True: + if proc.poll() is not None: + break + time.sleep(0.5) + #print time.time() + if time.time() > calltime + timeout: + raise Timeout() + finally: + try: + proc.terminate() + proc.kill() + except OSError: + pass - return (proc.returncode,) + proc.communicate() + return (proc.returncode,) + proc.communicate() + else: + output = commands.getstatusoutput(" ".join(command)) + return output + ('', '') + +def parse_output(text): + pass diff --git a/test_compile.py b/test_compile.py index 79f2731..31e0e3f 100644 --- a/test_compile.py +++ b/test_compile.py @@ -30,10 +30,11 @@ use <%s> print code f.write(code) f.flush - output = call_openscad(path=fpath, stlpath=stlpath, timeout=5) + output = call_openscad(path=fpath, stlpath=stlpath, timeout=0) print output assert output[0] is 0 - assert "warning" or "error" not in output[2].strip().lowercase() + for s in ("warning", "error"): + assert s not in output[2].strip().lower() assert len(stlpath.readlines()) > 2 def test_file_compile(modpath): @@ -41,7 +42,8 @@ def test_file_compile(modpath): output = call_openscad(path=modpath, stlpath=stlpath) print output assert output[0] is 0 - assert "warning" or "error" not in output[2].strip().lowercase() + for s in ("warning", "error"): + assert s not in output[2].strip().lower() assert len(stlpath.readlines()) == 2 diff --git a/utilities.scad b/utilities.scad index cafb6ec..174d4ba 100644 --- a/utilities.scad +++ b/utilities.scad @@ -5,7 +5,7 @@ * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later */ - +include function distance(a, b) = sqrt( (a[0] - b[0])*(a[0] - b[0]) + (a[1] - b[1])*(a[1] - b[1]) +