[svn r63135] adding a new gateway specification method

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-20 14:22:07 +01:00
parent cfd28db4a6
commit 250f17b609
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import py
def test_XSpec_attributes():
XSpec = py.execnet.XSpec
spec = XSpec("socket=192.168.102.2:8888//python=c:/this/python2.5//path=d:\hello")
assert spec.socket == "192.168.102.2:8888"
assert spec.python == "c:/this/python2.5"
assert spec.path == "d:\hello"
assert spec.xyz is None
py.test.raises(AttributeError, "spec._hello")
spec = XSpec("socket=192.168.102.2:8888//python=python2.5")
assert spec.socket == "192.168.102.2:8888"
assert spec.python == "python2.5"
assert spec.path is None
spec = XSpec("ssh=user@host//path=/hello/this//python=/usr/bin/python2.5")
assert spec.ssh == "user@host"
assert spec.python == "/usr/bin/python2.5"
assert spec.path == "/hello/this"
spec = XSpec("popen")
assert spec.popen == True
@py.test.mark.xfail
def test_makegateway_popen():
spec = py.execnet.XSpec("popen")
gw = py.execnet.makegateway(spec)
assert gw.spec == spec
rinfo = gw.remote_info()
assert rinfo.executable == py.std.sys.executable
assert rinfo.curdir == py.std.os.getcwd()
assert rinfo.version_info == py.std.sys.version_info

29
py/execnet/xspec.py Normal file
View File

@ -0,0 +1,29 @@
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
def makegateway(spec):
pass