From 40a572298770c8d62d1fe20791988de4949e2464 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Tue, 22 Feb 2011 16:57:56 +0100 Subject: [PATCH] support -s STATE in info --- deluge/ui/console/commands/info.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/deluge/ui/console/commands/info.py b/deluge/ui/console/commands/info.py index cf5ae48bd..7e6ed99ac 100644 --- a/deluge/ui/console/commands/info.py +++ b/deluge/ui/console/commands/info.py @@ -70,6 +70,8 @@ status_keys = ["state", "is_finished" ] +states = ["Active", "Downloading", "Seeding", "Paused", "Checking", "Error", "Queued"] + def format_progressbar(progress, width): """ @@ -98,11 +100,17 @@ class Command(BaseCommand): 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('-s', '--state', action='store', dest='state', + help="Only retrieve torrents in state STATE. " + "Allowable values are: %s "%(", ".join(states))), ) - usage = "Usage: info [ [ ...]]\n"\ + usage = "Usage: info [-v | -i | -s ] [ [ ...]]\n"\ + " info -s will show only torrents in state \n"\ " You can give the first few characters of a torrent-id to identify the torrent." + + def handle(self, *args, **options): self.console = component.get("ConsoleUI") # Compile a list of torrent_ids to request the status of @@ -121,7 +129,17 @@ class Command(BaseCommand): def on_torrents_status_fail(reason): self.console.write("{!error!}Error getting torrent info: %s" % reason) - d = client.core.get_torrents_status({"id": torrent_ids}, status_keys) + status_dict = {"id": torrent_ids} + + if options["state"]: + if options["state"] not in states: + self.console.write("Invalid state: %s"%options["state"]) + self.console.write("Allowble values are: %s."%(", ".join(states))) + return + else: + status_dict["state"] = options["state"] + + d = client.core.get_torrents_status(status_dict, status_keys) d.addCallback(on_torrents_status) d.addErrback(on_torrents_status_fail) return d