add a path completer for weboorrents command 'getfile'
This commit is contained in:
parent
f5bf9a4d13
commit
916fc3d98e
2 changed files with 30 additions and 5 deletions
|
|
@ -119,10 +119,12 @@ class Weboorrents(ReplApplication):
|
||||||
else:
|
else:
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def complete_info(self, text, line, *ignored):
|
def complete_getfile(self, text, line, *ignored):
|
||||||
args = line.split(' ')
|
args = line.split(' ', 2)
|
||||||
if len(args) == 2:
|
if len(args) == 2:
|
||||||
return self._complete_id()
|
return self._complete_id()
|
||||||
|
elif len(args) >= 3:
|
||||||
|
return self.path_completer(args[2])
|
||||||
|
|
||||||
def do_getfile(self, line):
|
def do_getfile(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
@ -141,8 +143,12 @@ class Weboorrents(ReplApplication):
|
||||||
if dest == '-':
|
if dest == '-':
|
||||||
print buf
|
print buf
|
||||||
else:
|
else:
|
||||||
with open(dest, 'w') as f:
|
try:
|
||||||
f.write(buf)
|
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
|
return
|
||||||
|
|
||||||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||||
|
|
|
||||||
|
|
@ -567,6 +567,21 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
def completenames(self, text, *ignored):
|
def completenames(self, text, *ignored):
|
||||||
return [name for name in Cmd.completenames(self, text, *ignored) if name not in self.hidden_commands]
|
return [name for name in Cmd.completenames(self, text, *ignored) if name not in self.hidden_commands]
|
||||||
|
|
||||||
|
def path_completer(self, arg):
|
||||||
|
dirname = os.path.dirname(arg)
|
||||||
|
try:
|
||||||
|
childs = os.listdir(dirname or '.')
|
||||||
|
except OSError:
|
||||||
|
return ()
|
||||||
|
l = []
|
||||||
|
for child in childs:
|
||||||
|
path = os.path.join(dirname, child)
|
||||||
|
if os.path.isdir(path):
|
||||||
|
child += '/'
|
||||||
|
l.append(child)
|
||||||
|
return l
|
||||||
|
|
||||||
|
|
||||||
def complete(self, text, state):
|
def complete(self, text, state):
|
||||||
"""
|
"""
|
||||||
Override of the Cmd.complete() method to:
|
Override of the Cmd.complete() method to:
|
||||||
|
|
@ -584,9 +599,13 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
self.completion_matches = [choice for choice in self.completion_matches if choice.startswith(text)]
|
self.completion_matches = [choice for choice in self.completion_matches if choice.startswith(text)]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return '%s ' % self.completion_matches[state]
|
match = self.completion_matches[state]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
|
if match[-1] != '/':
|
||||||
|
return '%s ' % match
|
||||||
|
return match
|
||||||
|
|
||||||
def do_backends(self, line):
|
def do_backends(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue