Author: andar
Revision: 6135
Log:
Use torrent status diffs in the TorrentView to reduce the amount of rpc
traffic from the core->gtkui
Diff:
Modified: trunk/deluge/core/core.py
===================================================================
--- trunk/deluge/core/core.py 2010-01-24 22:44:44 UTC (rev 6134)
+++ trunk/deluge/core/core.py 2010-01-25 00:15:12 UTC (rev 6135)
@@ -385,9 +385,9 @@
self.torrentmanager[torrent_id].resume()
@export
- def get_torrent_status(self, torrent_id, keys):
+ def get_torrent_status(self, torrent_id, keys, diff=False):
# Build the status dictionary
- status = self.torrentmanager[torrent_id].get_status(keys)
+ status = self.torrentmanager[torrent_id].get_status(keys, diff)
# Get the leftover fields and ask the plugin manager to fill them
leftover_fields = list(set(keys) - set(status.keys()))
@@ -396,7 +396,7 @@
return status
@export
- def get_torrents_status(self, filter_dict, keys):
+ def get_torrents_status(self, filter_dict, keys, diff=False):
"""
returns all torrents , optionally filtered by filter_dict.
"""
@@ -405,7 +405,7 @@
# Get the torrent status for each torrent_id
for torrent_id in torrent_ids:
- status_dict[torrent_id] = self.get_torrent_status(torrent_id, keys)
+ status_dict[torrent_id] = self.get_torrent_status(torrent_id,
keys, diff)
return status_dict
Modified: trunk/deluge/core/pluginmanager.py
===================================================================
--- trunk/deluge/core/pluginmanager.py 2010-01-24 22:44:44 UTC (rev 6134)
+++ trunk/deluge/core/pluginmanager.py 2010-01-25 00:15:12 UTC (rev 6135)
@@ -96,8 +96,7 @@
try:
status[field] = self.status_fields[field](torrent_id)
except KeyError:
- log.warning("Status field %s is not registered with the\
- PluginManager.", field)
+ pass
return status
def register_status_field(self, field, function):
Modified: trunk/deluge/core/torrent.py
===================================================================
--- trunk/deluge/core/torrent.py 2010-01-24 22:44:44 UTC (rev 6134)
+++ trunk/deluge/core/torrent.py 2010-01-25 00:15:12 UTC (rev 6135)
@@ -72,7 +72,7 @@
self["file_priorities"] = []
self["mapped_files"] = {}
-class Torrent:
+class Torrent(object):
"""Torrent holds information about torrents added to the libtorrent
session.
"""
def __init__(self, handle, options, state=None, filename=None,
magnet=None):
@@ -80,6 +80,16 @@
# Get the core config
self.config = ConfigManager("core.conf")
+ self.rpcserver = component.get("RPCServer")
+
+ # This dict holds previous status dicts returned for this torrent
+ # We use this to return dicts that only contain changes from the
previous
+ # {session_id: status_dict, ...}
+ self.prev_status = {}
+ from twisted.internet.task import LoopingCall
+ self.prev_status_cleanup_loop = LoopingCall(self.cleanup_prev_status)
+ self.prev_status_cleanup_loop.start(10)
+
# Set the libtorrent handle
self.handle = handle
# Set the torrent_id for this torrent
@@ -525,8 +535,21 @@
return host
return ""
- def get_status(self, keys):
- """Returns the status of the torrent based on the keys provided"""
+ def get_status(self, keys, diff=False):
+ """
+ Returns the status of the torrent based on the keys provided
+
+ :param keys: the keys to get the status on
+ :type keys: list of str
+ :param diff: if True, will return a diff of the changes since the last
+ call to get_status based on the session_id
+ :type diff: bool
+
+ :returns: a dictionary of the status keys and their values
+ :rtype: dict
+
+ """
+
# Create the full dictionary
self.status = self.handle.status()
if self.handle.has_metadata():
@@ -656,7 +679,25 @@
status_dict[key] = full_status[key]
elif key in fns:
status_dict[key] = fns[key]()
+
+ session_id = self.rpcserver.get_session_id()
+ if diff:
+ if session_id in self.prev_status:
+ # We have a previous status dict, so lets make a diff
+ status_diff = {}
+ for key, value in status_dict.items():
+ if key in self.prev_status[session_id]:
+ if value != self.prev_status[session_id][key]:
+ status_diff[key] = value
+ else:
+ status_diff[key] = value
+
+ self.prev_status[session_id] = status_dict
+ return status_diff
+ self.prev_status[session_id] = status_dict
+ return status_dict
+
return status_dict
def apply_options(self):
@@ -828,3 +869,14 @@
wait_on_folder[2].append(f["index"])
self.handle.rename_file(f["index"], f["path"].replace(folder,
new_folder, 1).encode("utf-8"))
self.waiting_on_folder_rename.append(wait_on_folder)
+
+ def cleanup_prev_status(self):
+ """
+ This method gets called to check the validity of the keys in the
prev_status
+ dict. If the key is no longer valid, the dict will be deleted.
+
+ """
+ for key in self.prev_status.keys():
+ if not self.rpcserver.is_session_valid(key):
+ del self.prev_status[key]
+
Modified: trunk/deluge/core/torrentmanager.py
===================================================================
--- trunk/deluge/core/torrentmanager.py 2010-01-24 22:44:44 UTC (rev 6134)
+++ trunk/deluge/core/torrentmanager.py 2010-01-25 00:15:12 UTC (rev 6135)
@@ -387,6 +387,8 @@
if options["mapped_files"]:
for index, name in options["mapped_files"].items():
log.debug("renaming file index %s to %s", index, name)
+ import code
+ code.interact(local=locals())
torrent_info.rename_file(index, name.encode("utf-8"))
add_torrent_params["ti"] = torrent_info
Modified: trunk/deluge/ui/gtkui/torrentview.py
===================================================================
--- trunk/deluge/ui/gtkui/torrentview.py 2010-01-24 22:44:44 UTC (rev
6134)
+++ trunk/deluge/ui/gtkui/torrentview.py 2010-01-25 00:15:12 UTC (rev
6135)
@@ -325,7 +325,7 @@
# Request the statuses for all these torrent_ids, this is async so we
# will deal with the return in a signal callback.
client.core.get_torrents_status(
- self.filter, status_keys).addCallback(self._on_get_torrents_status)
+ self.filter, status_keys,
True).addCallback(self._on_get_torrents_status)
def update(self):
# Send a status request
--
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en.