mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
Add path tab-complete to the add command
This commit is contained in:
parent
96b38188fc
commit
e856e65db5
@ -48,6 +48,9 @@ class Command(BaseCommand):
|
||||
t_options["download_location"] = options["path"]
|
||||
|
||||
for arg in args:
|
||||
if not os.path.isfile(arg):
|
||||
self.console.write("{!error!}This is a directory!")
|
||||
continue
|
||||
self.console.write("{!info!}Attempting to add torrent: %s" % arg)
|
||||
filename = os.path.split(arg)[-1]
|
||||
filedump = base64.encodestring(open(arg).read())
|
||||
@ -58,3 +61,39 @@ class Command(BaseCommand):
|
||||
self.console.write("{!error!}Torrent was not added! %s" % result)
|
||||
|
||||
client.core.add_torrent_file(filename, filedump, t_options).addCallback(on_success).addErrback(on_fail)
|
||||
|
||||
def complete(self, line):
|
||||
line = os.path.abspath(os.path.expanduser(line))
|
||||
ret = []
|
||||
if os.path.exists(line):
|
||||
# This is a correct path, check to see if it's a directory
|
||||
if os.path.isdir(line):
|
||||
# Directory, so we need to show contents of directory
|
||||
#ret.extend(os.listdir(line))
|
||||
for f in os.listdir(line):
|
||||
# Skip hidden
|
||||
if f.startswith("."):
|
||||
continue
|
||||
f = os.path.join(line, f)
|
||||
if os.path.isdir(f):
|
||||
f += "/"
|
||||
ret.append(f)
|
||||
else:
|
||||
# This is a file, but we could be looking for another file that
|
||||
# shares a common prefix.
|
||||
for f in os.listdir(os.path.dirname(line)):
|
||||
if f.startswith(os.path.split(line)[1]):
|
||||
ret.append(os.path.join( os.path.dirname(line), f))
|
||||
else:
|
||||
# This path does not exist, so lets do a listdir on it's parent
|
||||
# and find any matches.
|
||||
ret = []
|
||||
for f in os.listdir(os.path.dirname(line)):
|
||||
if f.startswith(os.path.split(line)[1]):
|
||||
p = os.path.join(os.path.dirname(line), f)
|
||||
|
||||
if os.path.isdir(p):
|
||||
p += "/"
|
||||
ret.append(p)
|
||||
|
||||
return ret
|
||||
|
@ -244,7 +244,7 @@ class ConsoleUI(component.Component):
|
||||
# line.
|
||||
for cmd in self._commands:
|
||||
if cmd.startswith(line):
|
||||
possible_matches.append(cmd)
|
||||
possible_matches.append(cmd + " ")
|
||||
|
||||
line_prefix = ""
|
||||
else:
|
||||
@ -264,7 +264,7 @@ class ConsoleUI(component.Component):
|
||||
# return it, else we need to print out the matches without modifying
|
||||
# the line.
|
||||
elif len(possible_matches) == 1:
|
||||
new_line = line_prefix + possible_matches[0] + " "
|
||||
new_line = line_prefix + possible_matches[0]
|
||||
return (new_line, len(new_line))
|
||||
else:
|
||||
if second_hit:
|
||||
@ -272,6 +272,12 @@ class ConsoleUI(component.Component):
|
||||
self.write(" ")
|
||||
for match in possible_matches:
|
||||
self.write(match)
|
||||
else:
|
||||
p = " ".join(line.split(" ")[:-1])
|
||||
new_line = " ".join([p, os.path.commonprefix(possible_matches)])
|
||||
if len(new_line) > len(line):
|
||||
line = new_line
|
||||
cursor = len(line)
|
||||
return (line, cursor)
|
||||
|
||||
def tab_complete_torrent(self, line):
|
||||
@ -289,9 +295,9 @@ class ConsoleUI(component.Component):
|
||||
# Find all possible matches
|
||||
for torrent_id, torrent_name in self.torrents:
|
||||
if torrent_id.startswith(line):
|
||||
possible_matches.append(torrent_id)
|
||||
possible_matches.append(torrent_id + " ")
|
||||
if torrent_name.startswith(line):
|
||||
possible_matches.append(torrent_name)
|
||||
possible_matches.append(torrent_name + " ")
|
||||
|
||||
return possible_matches
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user