remove py._path.gateway.* - its weird and unused
--HG-- branch : trunk
This commit is contained in:
parent
10b8de060a
commit
8ece058256
|
@ -1 +0,0 @@
|
|||
#
|
|
@ -1,65 +0,0 @@
|
|||
import threading
|
||||
|
||||
|
||||
class PathServer:
|
||||
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
self.C2P = {}
|
||||
self.next_id = 0
|
||||
threading.Thread(target=self.serve).start()
|
||||
|
||||
def p2c(self, path):
|
||||
id = self.next_id
|
||||
self.next_id += 1
|
||||
self.C2P[id] = path
|
||||
return id
|
||||
|
||||
def command_LIST(self, id, *args):
|
||||
path = self.C2P[id]
|
||||
answer = [(self.p2c(p), p.basename) for p in path.listdir(*args)]
|
||||
self.channel.send(answer)
|
||||
|
||||
def command_DEL(self, id):
|
||||
del self.C2P[id]
|
||||
|
||||
def command_GET(self, id, spec):
|
||||
path = self.C2P[id]
|
||||
self.channel.send(path._getbyspec(spec))
|
||||
|
||||
def command_READ(self, id):
|
||||
path = self.C2P[id]
|
||||
self.channel.send(path.read())
|
||||
|
||||
def command_JOIN(self, id, resultid, *args):
|
||||
path = self.C2P[id]
|
||||
assert resultid not in self.C2P
|
||||
self.C2P[resultid] = path.join(*args)
|
||||
|
||||
def command_DIRPATH(self, id, resultid):
|
||||
path = self.C2P[id]
|
||||
assert resultid not in self.C2P
|
||||
self.C2P[resultid] = path.dirpath()
|
||||
|
||||
def serve(self):
|
||||
try:
|
||||
while 1:
|
||||
msg = self.channel.receive()
|
||||
meth = getattr(self, 'command_' + msg[0])
|
||||
meth(*msg[1:])
|
||||
except EOFError:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
import py
|
||||
gw = execnet.PopenGateway()
|
||||
channel = gw._channelfactory.new()
|
||||
srv = PathServer(channel)
|
||||
c = gw.remote_exec("""
|
||||
import remotepath
|
||||
p = remotepath.RemotePath(channel.receive(), channel.receive())
|
||||
channel.send(len(p.listdir()))
|
||||
""")
|
||||
c.send(channel)
|
||||
c.send(srv.p2c(py.path.local('/tmp')))
|
||||
print(c.receive())
|
|
@ -1,21 +0,0 @@
|
|||
import py
|
||||
from remotepath import RemotePath
|
||||
|
||||
|
||||
SRC = open('channeltest.py', 'r').read()
|
||||
|
||||
SRC += '''
|
||||
import py
|
||||
srv = PathServer(channel.receive())
|
||||
channel.send(srv.p2c(py.path.local("/tmp")))
|
||||
'''
|
||||
|
||||
|
||||
#gw = execnet.SshGateway('codespeak.net')
|
||||
gw = execnet.PopenGateway()
|
||||
gw.remote_init_threads(5)
|
||||
c = gw.remote_exec(SRC, stdout=py.std.sys.stdout, stderr=py.std.sys.stderr)
|
||||
subchannel = gw._channelfactory.new()
|
||||
c.send(subchannel)
|
||||
|
||||
p = RemotePath(subchannel, c.receive())
|
|
@ -1,47 +0,0 @@
|
|||
import py, itertools
|
||||
from py._path import common
|
||||
|
||||
COUNTER = itertools.count()
|
||||
|
||||
class RemotePath(common.PathBase):
|
||||
sep = '/'
|
||||
|
||||
def __init__(self, channel, id, basename=None):
|
||||
self._channel = channel
|
||||
self._id = id
|
||||
self._basename = basename
|
||||
self._specs = {}
|
||||
|
||||
def __del__(self):
|
||||
self._channel.send(('DEL', self._id))
|
||||
|
||||
def __repr__(self):
|
||||
return 'RemotePath(%s)' % self.basename
|
||||
|
||||
def listdir(self, *args):
|
||||
self._channel.send(('LIST', self._id) + args)
|
||||
return [RemotePath(self._channel, id, basename)
|
||||
for (id, basename) in self._channel.receive()]
|
||||
|
||||
def dirpath(self):
|
||||
id = ~COUNTER.next()
|
||||
self._channel.send(('DIRPATH', self._id, id))
|
||||
return RemotePath(self._channel, id)
|
||||
|
||||
def join(self, *args):
|
||||
id = ~COUNTER.next()
|
||||
self._channel.send(('JOIN', self._id, id) + args)
|
||||
return RemotePath(self._channel, id)
|
||||
|
||||
def _getbyspec(self, spec):
|
||||
parts = spec.split(',')
|
||||
ask = [x for x in parts if x not in self._specs]
|
||||
if ask:
|
||||
self._channel.send(('GET', self._id, ",".join(ask)))
|
||||
for part, value in zip(ask, self._channel.receive()):
|
||||
self._specs[part] = value
|
||||
return [self._specs[x] for x in parts]
|
||||
|
||||
def read(self):
|
||||
self._channel.send(('READ', self._id))
|
||||
return self._channel.receive()
|
Loading…
Reference in New Issue