mirror of
https://git.deluge-torrent.org/deluge
synced 2025-09-03 00:25:33 +00:00
change get_torrents_status() api for filtering in core
This commit is contained in:
parent
f1427b7dd5
commit
14db4bc999
6 changed files with 107 additions and 97 deletions
|
@ -507,32 +507,45 @@ class Core(
|
|||
status.update(self.plugins.get_status(torrent_id, leftover_fields))
|
||||
return status
|
||||
|
||||
def export_get_dev_torrents_status(self, filter_dict, keys ):
|
||||
def filter_torrent_ids(self, filter_dict):
|
||||
"""
|
||||
internal :
|
||||
returns a list of torrent_id's matching filter_dict.
|
||||
"""
|
||||
if not filter_dict:
|
||||
return self.torrents.get_torrent_list()
|
||||
|
||||
if "id"in filter_dict: #optimized filter for id:
|
||||
torrent_ids = filter_dict["id"]
|
||||
del filter_dict["id"]
|
||||
else:
|
||||
torrent_ids = self.torrents.get_torrent_list()
|
||||
|
||||
#todo:
|
||||
#register/deregister special filters like "text search" and "active"
|
||||
#
|
||||
|
||||
#leftover filter arguments:
|
||||
#default filter on status fields.
|
||||
if filter_dict:
|
||||
for torrent_id in list(torrent_ids):
|
||||
status = self.export_get_torrent_status(torrent_id, filter_dict.keys()) #status={id:{key:value}}
|
||||
for field, value_list in filter_dict.iteritems():
|
||||
if (not status[field] in value_list) and torrent_id in torrent_ids:
|
||||
torrent_ids.remove(torrent_id)
|
||||
|
||||
return torrent_ids
|
||||
|
||||
def export_get_torrents_status(self, filter_dict, keys ):
|
||||
"""
|
||||
returns all torrents , optionally filtered by filter_dict.
|
||||
"""
|
||||
if filter_dict:
|
||||
raise NotImplementedError("not yet")
|
||||
|
||||
torrent_ids = self.torrents.get_torrent_list()
|
||||
return self.export_get_torrents_status(torrent_ids, keys)
|
||||
|
||||
def export_get_torrents_status(self, torrent_ids, keys):
|
||||
torrent_ids = self.filter_torrent_ids(filter_dict)
|
||||
status_dict = {}.fromkeys(torrent_ids)
|
||||
|
||||
# Get the torrent status for each torrent_id
|
||||
for torrent_id in torrent_ids:
|
||||
try:
|
||||
status = self.torrents[torrent_id].get_status(keys)
|
||||
except KeyError:
|
||||
return None
|
||||
# Get the leftover fields and ask the plugin manager to fill them
|
||||
leftover_fields = list(set(keys) - set(status.keys()))
|
||||
if len(leftover_fields) > 0:
|
||||
status.update(
|
||||
self.plugins.get_status(torrent_id, leftover_fields))
|
||||
|
||||
status_dict[torrent_id] = status
|
||||
status_dict[torrent_id] = self.export_get_torrent_status(torrent_id, keys)
|
||||
# Emit the torrent_status signal to the clients
|
||||
return status_dict
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ print len(sclient.label_get_filtered_ids({'state':'Paused','tracker':'tracker.ae
|
|||
print "#test status-fields:"
|
||||
ids = sclient.get_session_state()
|
||||
|
||||
torrents = sclient.get_torrents_status(ids,['name', 'tracker_host', 'label'])
|
||||
torrents = sclient.get_torrents_status({"id":ids},['name', 'tracker_host', 'label'])
|
||||
|
||||
for id,torrent in torrents.iteritems():
|
||||
print id, torrent
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# moving and refactoring torrent-filtering from labels-plugin to core.
|
||||
#
|
||||
|
||||
KEYS = ["name","state", "label"]
|
||||
#init:
|
||||
from deluge.ui.client import sclient
|
||||
sclient.set_core_uri()
|
||||
|
@ -17,31 +18,27 @@ print torrent_id
|
|||
print sorted(sclient.get_torrent_status(torrent_id,[]).keys())
|
||||
print sorted(sclient.get_status_keys())
|
||||
|
||||
#default, no filter argument.
|
||||
print sclient.get_dev_torrents_status(None, ["name","state"])
|
||||
|
||||
print "HI! , after this the errors start"
|
||||
|
||||
#torrent_id filters and list-arguments:
|
||||
print sclient.get_dev_torrents_status({"id":torrent_id}, ["name","state"])
|
||||
print sclient.get_dev_torrents_status({"id":[torrent_id, torrent_id2]}, ["name","state"])
|
||||
|
||||
#filters on default state fields
|
||||
print sclient.get_dev_torrents_status({"state":"Paused"}, ["name","state"])
|
||||
print sclient.get_dev_torrents_status({"state":["Paused","Downloading"]}, ["name","state"])
|
||||
print sclient.get_dev_torrents_status({"tracker_host":"aelitis.com"}, ["name","state"])
|
||||
|
||||
|
||||
#plugin status fields:
|
||||
print sclient.get_dev_torrents_status({"label":"test"}, ["name","state"])
|
||||
print sclient.get_dev_torrents_status({"label":["test","tpb"]}, ["name","state"])
|
||||
|
||||
#special filters:
|
||||
print sclient.get_dev_torrents_status({"keyword":"az"}, ["name","state"])
|
||||
print "#default, no filter argument."
|
||||
print sclient.get_torrents_status(None, KEYS)
|
||||
|
||||
|
||||
|
||||
print "#torrent_id filter:"
|
||||
print sclient.get_torrents_status({"id":[torrent_id, torrent_id2]}, KEYS)
|
||||
|
||||
|
||||
print "#filters on default status fields:"
|
||||
#print sclient.get_torrents_status({"state":"Paused"}, KEYS)
|
||||
print sclient.get_torrents_status({"state":["Paused","Downloading"]}, KEYS)
|
||||
print sclient.get_torrents_status({"tracker_host":["aelitis.com"]}, KEYS)
|
||||
|
||||
|
||||
|
||||
print "#status fields from plugins:"
|
||||
#print sclient.get_torrents_status({"label":"test"}, KEYS)
|
||||
print sclient.get_torrents_status({"label":["test","tpb"]}, KEYS)
|
||||
|
||||
|
||||
print "#special filters (ERRORS START HERE!):"
|
||||
print sclient.get_torrents_status({"keyword":"az"}, KEYS)
|
||||
print sclient.get_torrents_status({"state":"Active"}, KEYS)
|
||||
|
|
|
@ -258,7 +258,7 @@ class TorrentView(listview.ListView, component.Component):
|
|||
# Request the statuses for all these torrent_ids, this is async so we
|
||||
# will deal with the return in a signal callback.
|
||||
client.get_torrents_status(
|
||||
self._on_get_torrents_status, torrent_ids, status_keys)
|
||||
self._on_get_torrents_status, {"id":torrent_ids}, status_keys)
|
||||
|
||||
def update_filter(self):
|
||||
# Update the filter view
|
||||
|
|
|
@ -203,7 +203,7 @@ class json_rpc:
|
|||
filters = {"state":[["All",-1]],"tracker":[],"label":[]}
|
||||
|
||||
return {
|
||||
"torrents":sclient.get_torrents_status(torrent_ids, keys),
|
||||
"torrents":sclient.get_torrents_status({"id":torrent_ids}, keys),
|
||||
"filters":filters,
|
||||
"stats":self.get_stats(),
|
||||
"cache_id":-1
|
||||
|
|
|
@ -166,7 +166,7 @@ def get_enhanced_torrent_list(torrent_ids):
|
|||
"""
|
||||
returns a list of storified-torrent-dicts.
|
||||
"""
|
||||
torrent_dict = sclient.get_torrents_status(torrent_ids, TORRENT_KEYS)
|
||||
torrent_dict = sclient.get_torrents_status({"id":torrent_ids}, TORRENT_KEYS)
|
||||
return [enhance_torrent_status(id, status)
|
||||
for id, status in torrent_dict.iteritems()]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue