Various remote store improvements

This commit is contained in:
Jonas Borgström 2010-11-17 22:40:39 +01:00
parent f300051fe4
commit 58f51f1789
2 changed files with 15 additions and 13 deletions

View File

@ -45,11 +45,7 @@ class Archiver(object):
return self.exit_code
def do_serve(self, args):
try:
return StoreServer().serve()
except Exception, e:
self.print_error('eek', repr(e))
return 1
return StoreServer().serve()
def do_create(self, args):
store = self.open_store(args.archive)

View File

@ -31,11 +31,11 @@ class StoreServer(object):
unpacker.feed(data)
for type, msgid, method, args in unpacker:
try:
if method == 'open':
self.store = Store(*args)
res = self.store.id, self.store.tid
else:
res = getattr(self.store, method)(*args)
try:
f = getattr(self, method)
except AttributeError:
f = getattr(self.store, method)
res = f(*args)
except Exception, e:
sys.stdout.write(msgpack.packb((1, msgid, e.__class__.__name__, None)))
else:
@ -44,6 +44,12 @@ class StoreServer(object):
if es:
return
def open(self, path, create=False):
if path.startswith('/~'):
path = path[1:]
self.store = Store(os.path.expanduser(path), create)
return self.store.id, self.store.tid
class RemoteStore(object):
@ -84,16 +90,16 @@ class RemoteStore(object):
while True:
r, w, e = select.select([self.channel], [], [self.channel], 10)
if r:
if self.channel.closed:
raise Exception('Connection closed')
if self.channel.recv_stderr_ready():
print >> sys.stderr, self.channel.recv_stderr(BUFSIZE)
print >> sys.stderr, 'remote stderr:', self.channel.recv_stderr(BUFSIZE)
elif self.channel.recv_ready():
self.unpacker.feed(self.channel.recv(BUFSIZE))
for type, msgid, error, res in self.unpacker:
if error:
raise self.RPCError(error)
return res
else:
raise Exception('Read event but no data?!?')
if e:
raise Exception('ssh channel error')