From 0469d467175edfda0a1cb70de7e4001ca77965b3 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Fri, 15 Aug 2008 20:39:32 +0000 Subject: [PATCH] add get_status_keys() --- deluge/core/core.py | 16 ++++++++++++++++ deluge/core/torrent.py | 2 +- deluge/tests/test_filters.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 deluge/tests/test_filters.py diff --git a/deluge/core/core.py b/deluge/core/core.py index 87088b046..e95490781 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -121,6 +121,16 @@ DEFAULT_PREFS = { "peer_tos": "0x00", } +STATUS_KEYS = ['active_time', 'compact', 'distributed_copies', 'download_payload_rate', 'eta', + 'file_priorities', 'file_progress', 'files', 'hash', 'is_auto_managed', 'is_seed', 'max_connections', + 'max_download_speed', 'max_upload_slots', 'max_upload_speed', 'message', 'move_on_completed', + 'move_on_completed_path', 'name', 'next_announce', 'num_files', 'num_peers', 'num_pieces', + 'num_seeds', 'paused', 'peers', 'piece_length', 'prioritize_first_last', 'private', 'progress', + 'queue', 'ratio', 'remove_at_ratio', 'save_path', 'seed_rank', 'seeding_time', 'state', 'stop_at_ratio', + 'stop_ratio', 'total_done', 'total_payload_download', 'total_payload_upload', 'total_peers', + 'total_seeds', 'total_size', 'total_uploaded', 'total_wanted', 'tracker', 'tracker_host', + 'tracker_status', 'trackers', 'upload_payload_rate'] + class Core( ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer, @@ -477,6 +487,12 @@ class Core( if self.torrents[torrent_id].resume(): self.torrent_resumed(torrent_id) + def export_get_status_keys(self): + """ + returns all possible keys for the keys argument in get_torrent(s)_status. + """ + return STATUS_KEYS + self.plugins.status_fields.keys() + def export_get_torrent_status(self, torrent_id, keys): # Build the status dictionary try: diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 4ae3a62ac..323c094b9 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -431,7 +431,7 @@ class Torrent: if distributed_copies < 0: distributed_copies = 0.0 - #if you add a key here->add it to core.get_status_keys too. + #if you add a key here->add it to core.py STATUS_KEYS too. full_status = { "distributed_copies": distributed_copies, "total_done": self.status.total_done, diff --git a/deluge/tests/test_filters.py b/deluge/tests/test_filters.py new file mode 100644 index 000000000..e9cde54b6 --- /dev/null +++ b/deluge/tests/test_filters.py @@ -0,0 +1,35 @@ +# +# moving and refactoring torrent-filtering from labels-plugin to core. +# + +#init: +from deluge.ui.client import sclient +sclient.set_core_uri() +torrent_id = sclient.get_session_state()[0] +print torrent_id +#/init + + +#get_status_keys +#both lines should return the same if all plugins are disabled. +#the 1st should be longer if the label plugin is enabled. +print sorted(sclient.get_torrent_status(torrent_id,[]).keys()) +print sorted(sclient.get_status_keys()) + + +#filters on default state fields +print sclient.get_status(["name","state"], {"state":"Paused"}) +print sclient.get_status(["name","state"], {"tracker_host":"aelitis.com"}) + +#plugin status fields: +print sclient.get_status(["name","state"], {"label":"test"}) + +#special filters: +print sclient.get_status(["name","state"], {"keyword":"az"}) + + + + + + +