Module: deluge Branch: 1.3-stable Commit: a549eac0635068e581730fd83136bae2b83f4dd0
Author: Eirik Byrkjeflot Anonsen <[email protected]> Date: Tue May 17 20:51:14 2011 +0200 Add --sort option to deluge-console's "info" command. --- deluge/ui/console/commands/info.py | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-) diff --git a/deluge/ui/console/commands/info.py b/deluge/ui/console/commands/info.py index 1877e60..f748178 100644 --- a/deluge/ui/console/commands/info.py +++ b/deluge/ui/console/commands/info.py @@ -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) -- You received this message because you are subscribed to the Google Groups "deluge-commit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/deluge-commit?hl=en.
