mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 04:24:27 +00:00
Add --sort option to deluge-console's "info" command.
This commit is contained in:
parent
6fa2728ddc
commit
a549eac063
@ -106,11 +106,17 @@ def format_time(seconds):
|
|||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
"""Show information about the torrents"""
|
"""Show information about the torrents"""
|
||||||
|
|
||||||
|
sort_help = 'sort items. Possible keys: ' + ', '.join(status_keys)
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('-v', '--verbose', action='store_true', default=False, dest='verbose',
|
make_option('-v', '--verbose', action='store_true', default=False, dest='verbose',
|
||||||
help='shows more information per torrent'),
|
help='shows more information per torrent'),
|
||||||
make_option('-i', '--id', action='store_true', default=False, dest='tid',
|
make_option('-i', '--id', action='store_true', default=False, dest='tid',
|
||||||
help='use internal id instead of torrent name'),
|
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"\
|
usage = "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\
|
||||||
@ -128,8 +134,23 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def on_torrents_status(status):
|
def on_torrents_status(status):
|
||||||
# Print out the information for each torrent
|
# Print out the information for each torrent
|
||||||
for key, value in status.items():
|
sort_key = options['sort']
|
||||||
self.show_info(key, value, options["verbose"])
|
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):
|
def on_torrents_status_fail(reason):
|
||||||
self.console.write("{!error!}Error getting torrent info: %s" % reason)
|
self.console.write("{!error!}Error getting torrent info: %s" % reason)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user