Add an Error filter to the Trackers filter list

This commit is contained in:
Andrew Resch 2009-03-15 00:59:29 +00:00
parent 1c2b06a4f7
commit f787e013ee

View File

@ -66,6 +66,20 @@ def filter_one_keyword(torrent_ids, keyword):
yield torrent_id
break
def tracker_error_filter(torrent_ids, values):
# We only care about Error here
if values[0] != "Error":
return torrent_ids
# Check all the torrent's tracker_status for 'Error:' and only return torrent_ids
# that have this substring in their tracker_status
filtered_torrent_ids = []
tm = component.get("TorrentManager")
for torrent_id in torrent_ids:
if "Error:" in tm[torrent_id].get_status(["tracker_status"])["tracker_status"]:
filtered_torrent_ids.append(torrent_id)
return filtered_torrent_ids
class FilterManager(component.Component):
"""FilterManager
@ -81,7 +95,11 @@ class FilterManager(component.Component):
self.tree_fields = {}
self.register_tree_field("state", self._init_state_tree)
self.register_tree_field("tracker_host")
def _init_tracker_tree():
return {"Error": 0}
self.register_tree_field("tracker_host", _init_tracker_tree)
self.register_filter("tracker_host", tracker_error_filter)
def filter_torrent_ids(self, filter_dict):
"""
@ -163,6 +181,8 @@ class FilterManager(component.Component):
value = status[field]
items[field][value] = items[field].get(value, 0) + 1
items["tracker_host"]["Error"] = len(tracker_error_filter(torrent_ids, ("Error",)))
if "state" in tree_keys and not show_zero_hits:
self._hide_state_items(items["state"])