2009-03-20 21:22:07 +08:00
|
|
|
|
|
|
|
import py
|
|
|
|
|
|
|
|
class XSpec:
|
|
|
|
""" Execution Specification: key1=value1//key2=value2 ...
|
|
|
|
* keys need to be unique within the specification scope
|
|
|
|
* neither key nor value are allowed to contain "//"
|
|
|
|
* keys are not allowed to contain "="
|
|
|
|
* keys are not allowed to start with underscore
|
|
|
|
* if no "=value" is given, assume a boolean True value
|
|
|
|
"""
|
|
|
|
def __init__(self, *strings):
|
|
|
|
for string in strings:
|
|
|
|
for keyvalue in string.split("//"):
|
|
|
|
i = keyvalue.find("=")
|
|
|
|
if i == -1:
|
|
|
|
setattr(self, keyvalue, True)
|
|
|
|
else:
|
|
|
|
setattr(self, keyvalue[:i], keyvalue[i+1:])
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
if name[0] == "_":
|
|
|
|
raise AttributeError(name)
|
|
|
|
return None
|
|
|
|
|
2009-03-20 22:20:40 +08:00
|
|
|
def _samefilesystem(self):
|
|
|
|
return bool(self.popen and not self.path)
|
2009-03-20 21:22:07 +08:00
|
|
|
|
2009-03-20 22:20:40 +08:00
|
|
|
def makegateway(spec):
|
|
|
|
if not isinstance(spec, XSpec):
|
|
|
|
spec = XSpec(spec)
|
|
|
|
if spec.popen:
|
|
|
|
gw = py.execnet.PopenGateway(python=spec.python)
|
|
|
|
gw.spec = spec
|
|
|
|
return gw
|