add a path completer for weboorrents command 'getfile'

This commit is contained in:
Romain Bignon 2010-11-14 14:11:10 +01:00
commit 916fc3d98e
2 changed files with 30 additions and 5 deletions

View file

@ -119,10 +119,12 @@ class Weboorrents(ReplApplication):
else:
self.flush()
def complete_info(self, text, line, *ignored):
args = line.split(' ')
def complete_getfile(self, text, line, *ignored):
args = line.split(' ', 2)
if len(args) == 2:
return self._complete_id()
elif len(args) >= 3:
return self.path_completer(args[2])
def do_getfile(self, line):
"""
@ -141,8 +143,12 @@ class Weboorrents(ReplApplication):
if dest == '-':
print buf
else:
with open(dest, 'w') as f:
f.write(buf)
try:
with open(dest, 'w') as f:
f.write(buf)
except IOError, e:
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
return 1
return
print >>sys.stderr, 'Torrent "%s" not found' % id