[svn r37780] simplifying code a bit (but test_confusion* for Ssh still fails)

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-02 00:57:55 +01:00
parent cf7e2d7c28
commit 3634701598
4 changed files with 9 additions and 17 deletions

View File

@ -31,12 +31,12 @@ debug = 0 # open('/tmp/execnet-debug-%d' % os.getpid() , 'wa')
sysex = (KeyboardInterrupt, SystemExit) sysex = (KeyboardInterrupt, SystemExit)
class Gateway(object): class Gateway(object):
num_worker_threads = 2
ThreadOut = ThreadOut ThreadOut = ThreadOut
remoteaddress = ""
def __init__(self, io, startcount=2, maxthreads=None): def __init__(self, io, startcount=2, maxthreads=None):
global registered_cleanup global registered_cleanup
self._execpool = WorkerPool() self._execpool = WorkerPool(maxthreads=maxthreads)
## self.running = True ## self.running = True
self.io = io self.io = io
self._outgoing = Queue.Queue() self._outgoing = Queue.Queue()
@ -50,7 +50,7 @@ class Gateway(object):
sender = self.thread_sender) sender = self.thread_sender)
def __repr__(self): def __repr__(self):
addr = self._getremoteaddress() addr = self.remoteaddress
if addr: if addr:
addr = '[%s]' % (addr,) addr = '[%s]' % (addr,)
else: else:
@ -67,9 +67,6 @@ class Gateway(object):
return "<%s%s %s/%s (%s active channels)>" %( return "<%s%s %s/%s (%s active channels)>" %(
self.__class__.__name__, addr, r, s, i) self.__class__.__name__, addr, r, s, i)
def _getremoteaddress(self):
return None
## def _local_trystopexec(self): ## def _local_trystopexec(self):
## self._execpool.shutdown() ## self._execpool.shutdown()

View File

@ -136,9 +136,7 @@ class SocketGateway(InstallableGateway):
sock.connect((host, port)) sock.connect((host, port))
io = inputoutput.SocketIO(sock) io = inputoutput.SocketIO(sock)
super(SocketGateway, self).__init__(io=io) super(SocketGateway, self).__init__(io=io)
self.remoteaddress = '%s:%d' % (self.host, self.port)
def _getremoteaddress(self):
return '%s:%d' % (self.host, self.port)
def remote_install(cls, gateway, hostport=None): def remote_install(cls, gateway, hostport=None):
""" return a connected socket gateway through the """ return a connected socket gateway through the
@ -167,7 +165,7 @@ class SocketGateway(InstallableGateway):
class SshGateway(PopenCmdGateway): class SshGateway(PopenCmdGateway):
def __init__(self, sshaddress, remotepython='python', identity=None): def __init__(self, sshaddress, remotepython='python', identity=None):
self.sshaddress = sshaddress self.remoteaddress = sshaddress
remotecmd = '%s -u -c "exec input()"' % (remotepython,) remotecmd = '%s -u -c "exec input()"' % (remotepython,)
cmdline = [sshaddress, remotecmd] cmdline = [sshaddress, remotecmd]
# XXX Unix style quoting # XXX Unix style quoting
@ -179,9 +177,6 @@ class SshGateway(PopenCmdGateway):
cmdline.insert(0, cmd) cmdline.insert(0, cmd)
super(SshGateway, self).__init__(' '.join(cmdline)) super(SshGateway, self).__init__(' '.join(cmdline))
def _getremoteaddress(self):
return self.sshaddress
class ExecGateway(PopenGateway): class ExecGateway(PopenGateway):
def remote_exec_sync_stdcapture(self, lines, callback): def remote_exec_sync_stdcapture(self, lines, callback):
# hack: turn the content of the cell into # hack: turn the content of the cell into

View File

@ -110,7 +110,7 @@ class RSync(object):
# sharing multiple copies of the file's data # sharing multiple copies of the file's data
data = intern(data) data = intern(data)
print '%s <= %s' % ( print '%s <= %s' % (
channel.gateway._getremoteaddress(), channel.gateway.remoteaddress,
modified_rel_path) modified_rel_path)
channel.send(data) channel.send(data)
del data del data

View File

@ -62,8 +62,8 @@ class PopenGatewayTestSetup:
def setup_class(cls): def setup_class(cls):
cls.gw = py.execnet.PopenGateway() cls.gw = py.execnet.PopenGateway()
## def teardown_class(cls): def teardown_class(cls):
## cls.gw.exit() cls.gw.exit()
class BasicRemoteExecution: class BasicRemoteExecution:
def test_correct_setup(self): def test_correct_setup(self):
@ -455,7 +455,7 @@ class TestSshGateway(BasicRemoteExecution):
cls.gw = py.execnet.SshGateway(option.sshtarget) cls.gw = py.execnet.SshGateway(option.sshtarget)
def test_sshaddress(self): def test_sshaddress(self):
assert self.gw.sshaddress == option.sshtarget assert self.gw.remoteaddress == option.sshtarget
def test_failed_connexion(self): def test_failed_connexion(self):
gw = py.execnet.SshGateway('nowhere.codespeak.net') gw = py.execnet.SshGateway('nowhere.codespeak.net')