| 22 |
|
'''Process and pipeline management for Python Radiance scripts |
| 23 |
|
''' |
| 24 |
|
def raise_on_error(self, actstr, e): |
| 25 |
+ |
try: self._strtypes |
| 26 |
+ |
except AttributeError: self.__configure_subprocess() |
| 27 |
|
if hasattr(e, 'strerror'): eb = e.strerror |
| 28 |
|
elif isinstance(e, self._strtypes): eb = e |
| 29 |
|
else: eb = e |
| 60 |
|
else: self._pipeargs = {} |
| 61 |
|
# type names vary between Py2.7 and 3.x |
| 62 |
|
self._strtypes = (type(b''), type(u'')) |
| 61 |
– |
# private attribute to indicate established configuration |
| 62 |
– |
self.__proc_mixin_setup = True |
| 63 |
|
|
| 64 |
|
def qjoin(self, sl): |
| 65 |
|
'''Join a list with quotes around each element containing whitespace. |
| 73 |
|
return ' '.join([_q(s) for s in sl]) |
| 74 |
|
|
| 75 |
|
def __parse_args(self, _in, out): |
| 76 |
< |
try: self.__proc_mixin_setup |
| 76 |
> |
try: self._strtypes |
| 77 |
|
except AttributeError: self.__configure_subprocess() |
| 78 |
|
instr = '' |
| 79 |
|
if _in == PIPE: |
| 80 |
|
stdin = _in |
| 81 |
|
elif isinstance(_in, self._strtypes): |
| 82 |
< |
if self.donothing: stdin = None |
| 83 |
< |
else: stdin = open(_in, 'rb') |
| 82 |
> |
if not getattr(self, 'donothing', None): |
| 83 |
> |
stdin = open(_in, 'rb') |
| 84 |
> |
else: stdin = None |
| 85 |
|
instr = ' < "%s"' % _in |
| 86 |
|
elif hasattr(_in, 'read'): |
| 87 |
|
stdin = _in |
| 91 |
|
if out == PIPE: |
| 92 |
|
stdout = out |
| 93 |
|
elif isinstance(out, self._strtypes): |
| 94 |
< |
if self.donothing: stdout = None |
| 95 |
< |
else: stdout = open(out, 'wb') |
| 94 |
> |
if not getattr(self, 'donothing', None): |
| 95 |
> |
stdout = open(out, 'wb') |
| 96 |
> |
else: stdout = None |
| 97 |
|
outstr = ' > "%s"' % out |
| 98 |
|
elif hasattr(out, 'write'): |
| 99 |
|
stdout = out |