-
Notifications
You must be signed in to change notification settings - Fork 330
/
openscad_utils.py
51 lines (43 loc) · 1.5 KB
/
openscad_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import py, re, os, signal, time
from subprocess import Popen, PIPE
mod_re = (r"\bmodule\s+(", r")\s*\(\s*")
func_re = (r"\bfunction\s+(", r")\s*\(")
def extract_mod_names(fpath, name_re=r"\w+"):
regex = name_re.join(mod_re)
matcher = re.compile(regex)
return (m.group(1) for m in matcher.finditer(fpath.read()))
def extract_func_names(fpath, name_re=r"\w+"):
regex = name_re.join(func_re)
matcher = re.compile(regex)
return (m.group(1) for m in matcher.finditer(fpath.read()))
def collect_test_modules():
dirpath = py.path.local("./")
print "Collecting openscad test module names"
test_files = {}
for fpath in dirpath.visit('*.scad'):
#print fpath
modules = extract_mod_names(fpath, r"test\w*")
#functions = extract_func_names(fpath, r"test\w*")
test_files[fpath] = modules
return test_files
collect_test_modules()
def call_openscad(path, stlpath, timeout=20):
try:
proc = Popen(['openscad', '-s', str(stlpath), str(path)],
stdout=PIPE, stderr=PIPE, close_fds=True)
calltime = time.time()
#print calltime
while True:
if proc.poll() is not None:
break
time.sleep(0.1)
#print time.time()
if time.time() > calltime + timeout:
raise Exception("Timeout")
finally:
try:
proc.terminate()
proc.kill()
except OSError:
pass
return (proc.returncode,) + proc.communicate()