22 |
|
'''Process and pipeline management for Python Radiance scripts |
23 |
|
''' |
24 |
|
def raise_on_error(self, actstr, e): |
25 |
< |
raise Error('Unable to %s - %s' % (actstr, str(e))) |
25 |
> |
if hasattr(e, 'strerror'): eb = e.strerror |
26 |
> |
elif isinstance(e, self._strtypes): eb = e |
27 |
> |
else: eb = e |
28 |
> |
if isinstance(eb, type(b'')): |
29 |
> |
estr = eb.decode(encoding='utf-8', errors='ignore') |
30 |
> |
else: estr = eb |
31 |
> |
raise Error('Unable to %s - %s' % (actstr, estr)) # |
32 |
|
|
33 |
|
def __configure_subprocess(self): |
34 |
|
'''Prevent subprocess module failure in frozen scripts on Windows. |
79 |
|
if _in == PIPE: |
80 |
|
stdin = _in |
81 |
|
elif isinstance(_in, self._strtypes): |
82 |
< |
stdin = open(_in, 'rb') |
82 |
> |
if self.donothing: stdin = None |
83 |
> |
else: stdin = open(_in, 'rb') |
84 |
|
instr = ' < "%s"' % _in |
85 |
|
elif hasattr(_in, 'read'): |
86 |
|
stdin = _in |
90 |
|
if out == PIPE: |
91 |
|
stdout = out |
92 |
|
elif isinstance(out, self._strtypes): |
93 |
< |
stdout = open(out, 'wb') |
93 |
> |
if self.donothing: stdout = None |
94 |
> |
else: stdout = open(out, 'wb') |
95 |
|
outstr = ' > "%s"' % out |
96 |
|
elif hasattr(out, 'write'): |
97 |
|
stdout = out |
132 |
|
stdin=stdin, stdout=stdout, stderr=self._stderr, |
133 |
|
universal_newlines=universal_newlines, **self._pipeargs) |
134 |
|
except Exception as e: |
135 |
< |
self.raise_on_error(actstr, str(e)) |
135 |
> |
self.raise_on_error(actstr, e) |
136 |
|
if stdin != PIPE and stdout != PIPE: |
137 |
|
# caller needs to wait after reading or writing (else deadlock) |
138 |
|
res = p.wait() |
162 |
|
stdin=stdin, stdout=PIPE, stderr=self._stderr, |
163 |
|
**self._pipeargs) |
164 |
|
except Exception as e: |
165 |
< |
self.raise_on_error(actstr_1, str(e)) |
165 |
> |
self.raise_on_error(actstr_1, e) |
166 |
|
if getattr(self, 'verbose', None): |
167 |
|
sys.stderr.write(self.qjoin(cmdl_2) + outstr + '\n') |
168 |
|
if not getattr(self, 'donothing', None): |
172 |
|
universal_newlines=universal_newlines, **self._pipeargs) |
173 |
|
p1.stdout.close() |
174 |
|
except Exception as e: |
175 |
< |
self.raise_on_error(actstr_2, str(e)) |
175 |
> |
self.raise_on_error(actstr_2, e) |
176 |
|
if stdin != PIPE and stdout != PIPE: |
177 |
|
# caller needs to wait after reading or writing (else deadlock) |
178 |
|
res = p1.wait() |
217 |
|
stdout=PIPE, stderr=self._stderr, **self._pipeargs) |
218 |
|
procs.append(prevproc) |
219 |
|
except Exception as e: |
220 |
< |
self.raise_on_error(actstr, str(e)) |
220 |
> |
self.raise_on_error(actstr, e) |
221 |
|
|
222 |
|
for cmdl in cmdlines[1:-1]: |
223 |
|
if getattr(self, 'verbose', None): |
230 |
|
prevproc.stdout.close() |
231 |
|
prevproc = nextproc |
232 |
|
except Exception as e: |
233 |
< |
self.raise_on_error(actstr, str(e)) |
233 |
> |
self.raise_on_error(actstr, e) |
234 |
|
|
235 |
|
if getattr(self, 'verbose', None): |
236 |
|
sys.stderr.write(self.qjoin(cmdlines[-1]) + outstr + '\n') |
243 |
|
procs.append(lastproc) |
244 |
|
prevproc.stdout.close() |
245 |
|
except Exception as e: |
246 |
< |
self.raise_on_error(actstr, str(e)) |
246 |
> |
self.raise_on_error(actstr, e) |
247 |
|
|
248 |
|
if stdin != PIPE and stdout!= PIPE: |
249 |
|
# caller needs to wait after reading or writing (else deadlock) |