Add --sort option to deluge-console's "info" command.

This commit is contained in:
Eirik Byrkjeflot Anonsen 2011-05-17 20:51:14 +02:00 committed by Calum Lind
parent 6fa2728ddc
commit a549eac063

View File

@ -106,11 +106,17 @@ def format_time(seconds):
class Command(BaseCommand):
"""Show information about the torrents"""
sort_help = 'sort items. Possible keys: ' + ', '.join(status_keys)
option_list = BaseCommand.option_list + (
make_option('-v', '--verbose', action='store_true', default=False, dest='verbose',
help='shows more information per torrent'),
make_option('-i', '--id', action='store_true', default=False, dest='tid',
help='use internal id instead of torrent name'),
make_option('--sort', action='store', type='string', default='', dest='sort',
help=sort_help),
make_option('--sort-reverse', action='store', type='string', default='', dest='sort_rev',
help='sort items in reverse order. Same keys allowed as for --sort.')
)
usage = "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\
@ -128,8 +134,23 @@ class Command(BaseCommand):
def on_torrents_status(status):
# Print out the information for each torrent
for key, value in status.items():
self.show_info(key, value, options["verbose"])
sort_key = options['sort']
sort_reverse = False
if not sort_key:
sort_key = options['sort_rev']
sort_reverse = True
if not sort_key:
sort_key = 'name'
sort_reverse = False
if sort_key not in status_keys:
self.console.write('')
self.console.write("{!error!}Unknown sort key: " + sort_key + ", will sort on name")
sort_key = 'name'
sort_reverse = False
for key, value in sorted(status.items(),
key=lambda x : x[1].get(sort_key),
reverse=sort_reverse):
self.show_info(key, status[key], options["verbose"])
def on_torrents_status_fail(reason):
self.console.write("{!error!}Error getting torrent info: %s" % reason)