Ticket #1856: 0001-Add-sort-option-to-deluge-console-s-info-command.patch

File 0001-Add-sort-option-to-deluge-console-s-info-command.patch, 2.7 KB (added by eirikba, 14 years ago)
  • deluge/ui/console/commands/info.py

    From eec89fe4a7b0340e7106b5e523ac6195a38d1dc9 Mon Sep 17 00:00:00 2001
    From: Eirik Byrkjeflot Anonsen <eirik@eirikba.org>
    Date: Tue, 17 May 2011 20:51:14 +0200
    Subject: [PATCH] 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 7852399..da92750 100644
    a b def format_progressbar(progress, width):  
    9393class Command(BaseCommand):
    9494    """Show information about the torrents"""
    9595
     96    sort_help = 'sort items.  Possible keys: ' + ', '.join(status_keys)
     97
    9698    option_list = BaseCommand.option_list + (
    9799            make_option('-v', '--verbose', action='store_true', default=False, dest='verbose',
    98100                        help='shows more information per torrent'),
    99101            make_option('-i', '--id', action='store_true', default=False, dest='tid',
    100102                        help='use internal id instead of torrent name'),
     103            make_option('--sort', action='store', type='string', default='', dest='sort',
     104                        help=sort_help),
     105            make_option('--sort-reverse', action='store', type='string', default='', dest='sort_rev',
     106                        help='sort items in reverse order.  Same keys allowed as for --sort.')
    101107    )
    102108
    103109    usage =  "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\
    def handle(self, *args, **options):  
    115121
    116122        def on_torrents_status(status):
    117123            # Print out the information for each torrent
    118             for key, value in status.items():
    119                 self.show_info(key, value, options["verbose"])
     124            sort_key = options['sort']
     125            sort_reverse = False
     126            if not sort_key:
     127                sort_key = options['sort_rev']
     128                sort_reverse = True
     129            if not sort_key:
     130                sort_key = 'name'
     131                sort_reverse = False
     132            if sort_key not in status_keys:
     133                self.console.write('')
     134                self.console.write("{!error!}Unknown sort key: " + sort_key + ", will sort on name")
     135                sort_key = 'name'
     136                sort_reverse = False
     137            for key, value in sorted(status.items(),
     138                                     key=lambda x : x[1].get(sort_key),
     139                                     reverse=sort_reverse):
     140                self.show_info(key, status[key], options["verbose"])
    120141
    121142        def on_torrents_status_fail(reason):
    122143            self.console.write("{!error!}Error getting torrent info: %s" % reason)