[py-svn] r7942 - in py/dist/py: . execnet

arigo at codespeak.net arigo at codespeak.net
Mon Dec 20 12:56:15 CET 2004


Author: arigo
Date: Mon Dec 20 12:56:14 2004
New Revision: 7942

Modified:
   py/dist/py/__init__.py
   py/dist/py/execnet/gateway.py
   py/dist/py/execnet/message.py
   py/dist/py/execnet/register.py
Log:
- SshGateway
- gateways now use repr/eval instead of marshal to avoid issues with
    Python 2.4, whose format changed :-(
- the remote side was again importing 'py' locally for Source...


Modified: py/dist/py/__init__.py
==============================================================================
--- py/dist/py/__init__.py	(original)
+++ py/dist/py/__init__.py	Mon Dec 20 12:56:14 2004
@@ -59,4 +59,5 @@
 
     'execnet.SocketGateway'  : ('./execnet/register.py', 'SocketGateway'),
     'execnet.PopenGateway'   : ('./execnet/register.py', 'PopenGateway'),
+    'execnet.SshGateway'     : ('./execnet/register.py', 'SshGateway'),
 })

Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py	(original)
+++ py/dist/py/execnet/gateway.py	Mon Dec 20 12:56:14 2004
@@ -7,12 +7,12 @@
 
 # XXX the following line should not be here
 g = globals()
-if 'Source' not in g:
+if 'Message' not in g:
     from py.code import Source 
     from py.__impl__.execnet.channel import ChannelFactory, Channel
     from py.__impl__.execnet.message import Message 
 
-assert Message and Source and ChannelFactory, "Import/Configuration Error"
+assert Message and ChannelFactory, "Import/Configuration Error"
 
 import os
 debug = 0 # open('/tmp/execnet-debug-%d' % os.getpid()  , 'wa') 

Modified: py/dist/py/execnet/message.py
==============================================================================
--- py/dist/py/execnet/message.py	(original)
+++ py/dist/py/execnet/message.py	Mon Dec 20 12:56:14 2004
@@ -1,5 +1,5 @@
 import struct
-import marshal 
+#import marshal 
 
 # ___________________________________________________________________________
 #
@@ -16,7 +16,11 @@
         self.data = data 
 
     def writeto(self, io):
-        data = marshal.dumps(self.data) 
+        # big XXX and all this
+        #     data = marshal.dumps(self.data)
+        # doesn't work for exchanging data across Python version :-(((
+        data = repr(self.data)  # argh
+        
         header = struct.pack("!iii", self.msgtype, self.channelid, len(data))
         io.write(header)
         io.write(data) 
@@ -26,9 +30,11 @@
         msgtype, senderid, stringlen = struct.unpack("!iii", header)
         if stringlen: 
             string = io.read(stringlen)
+            # same big XXX as in writeto()
+            #     string = marshal.loads(string)
+            string = eval(string, {})
         else:
             string = '' 
-        string = marshal.loads(string)
         msg = cls._types[msgtype](senderid, string)
         return msg 
     readfrom = classmethod(readfrom) 

Modified: py/dist/py/execnet/register.py
==============================================================================
--- py/dist/py/execnet/register.py	(original)
+++ py/dist/py/execnet/register.py	Mon Dec 20 12:56:14 2004
@@ -33,29 +33,19 @@
         self.trace("sending gateway bootstrap code")
         io.write('%r\n' % source)
 
-class PopenGateway(InstallableGateway):
-    def __init__(self, python=sys.executable): 
-        cmd = '%s -u -c "exec input()"' % python
+class PopenCmdGateway(InstallableGateway):
+    def __init__(self, cmd):
         infile, outfile = os.popen2(cmd)
         io = inputoutput.Popen2IO(infile, outfile) 
-        InstallableGateway.__init__(self, io=io) 
+        super(PopenCmdGateway, self).__init__(io=io)
 
         self._pidchannel = self.remote_exec(""" 
             import os 
             channel.send(os.getpid()) 
         """) 
 
-    def remote_bootstrap_gateway(self, io, extra=''): 
-        # XXX the following hack helps us to import the same version 
-        #     of the py lib, but only works for PopenGateways 
-        #     --> we need proper remote imports working 
-        #         across any kind of gateway!
-        s = "import sys ; sys.path[:] = %r" % (sys.path,) 
-        s = "\n".join([extra, s]) 
-        super(PopenGateway, self).remote_bootstrap_gateway(io, s) 
-
     def exit(self):
-        if not super(PopenGateway, self).exit():
+        if not super(PopenCmdGateway, self).exit():
             return
         try:
             pid = self._pidchannel.receive()
@@ -69,6 +59,20 @@
             except OSError: 
                 self.trace("child process %s already dead?" %pid) 
 
+class PopenGateway(PopenCmdGateway):
+    def __init__(self, python=sys.executable):
+        cmd = '%s -u -c "exec input()"' % python
+        super(PopenGateway, self).__init__(cmd)
+
+    def remote_bootstrap_gateway(self, io, extra=''): 
+        # XXX the following hack helps us to import the same version 
+        #     of the py lib, but only works for PopenGateways 
+        #     --> we need proper remote imports working 
+        #         across any kind of gateway!
+        s = "import sys ; sys.path[:] = %r" % (sys.path,) 
+        s = "\n".join([extra, s]) 
+        super(PopenGateway, self).remote_bootstrap_gateway(io, s) 
+
 class SocketGateway(InstallableGateway):
     def __init__(self, host, port): 
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -77,7 +81,21 @@
         sock.connect((host, port))
         io = inputoutput.SocketIO(sock) 
         InstallableGateway.__init__(self, io=io) 
-        
+
+class SshGateway(PopenCmdGateway):
+    def __init__(self, host, port=None, username=None, remotepython='python'):
+        if port is not None:
+            host = '%s:%d' % (host, port)
+        remotecmd = '%s -u -c "exec input()"' % (remotepython,)
+        cmdline = [host, remotecmd]
+        if username is not None:
+            cmdline[:0] = ['-l', username]
+        # XXX Unix style quoting
+        for i in range(len(cmdline)):
+            cmdline[i] = "'" + cmdline[i].replace("'", "'\\''") + "'"
+        cmdline.insert(0, 'ssh')
+        super(SshGateway, self).__init__(' '.join(cmdline))
+
 class ExecGateway(PopenGateway):
     def remote_exec_sync_stdcapture(self, lines, callback):
         # hack: turn the content of the cell into



More information about the pytest-commit mailing list