From 7305cf3bcfa9b45c6b8ad8fe4a1b4270fabc4ef2 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 2/4] Add --sort option to deluge-console's "info" command.
---
deluge/ui/console/commands/info.py | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/deluge/ui/console/commands/info.py b/deluge/ui/console/commands/info.py
index 7852399..e775bbe 100644
a
|
b
|
def format_progressbar(progress, width):
|
93 | 93 | class Command(BaseCommand): |
94 | 94 | """Show information about the torrents""" |
95 | 95 | |
| 96 | sort_help = 'sort items. append "_rev" to the key to sort in reverse (e.g. eta -> eta_rev). Possible keys: ' + ', '.join(status_keys) |
| 97 | |
96 | 98 | option_list = BaseCommand.option_list + ( |
97 | 99 | make_option('-v', '--verbose', action='store_true', default=False, dest='verbose', |
98 | 100 | help='shows more information per torrent'), |
99 | 101 | make_option('-i', '--id', action='store_true', default=False, dest='tid', |
100 | 102 | help='use internal id instead of torrent name'), |
| 103 | make_option('--sort', action='store', type='string', default='', dest='sort', |
| 104 | help=sort_help) |
101 | 105 | ) |
102 | 106 | |
103 | 107 | usage = "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\ |
… |
… |
def handle(self, *args, **options):
|
115 | 119 | |
116 | 120 | def on_torrents_status(status): |
117 | 121 | # Print out the information for each torrent |
118 | | for key, value in status.items(): |
119 | | self.show_info(key, value, options["verbose"]) |
| 122 | keys = [ k for k in status.keys() ] |
| 123 | if options["sort"]: |
| 124 | reverse = False |
| 125 | sort_key = options["sort"] |
| 126 | if sort_key.endswith("_rev"): |
| 127 | reverse = True |
| 128 | sort_key = sort_key[:-4] |
| 129 | if sort_key not in status_keys: |
| 130 | self.console.write('') |
| 131 | self.console.write("{!error!}Unknown sort key: " + sort_key) |
| 132 | keys.sort(key=lambda x : status[x].get(sort_key), reverse=reverse) |
| 133 | for key in keys: |
| 134 | self.show_info(key, status[key], options["verbose"]) |
120 | 135 | |
121 | 136 | def on_torrents_status_fail(reason): |
122 | 137 | self.console.write("{!error!}Error getting torrent info: %s" % reason) |