Author: damoxc
Revision: 4929
Log:
add a method to return a torrents files as a tree
Diff:
Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py 2009-03-23 23:17:04 UTC (rev 4928)
+++ trunk/deluge/ui/web/json_api.py 2009-03-25 09:12:48 UTC (rev 4929)
@@ -254,6 +254,8 @@
DEFAULT_HOST, DEFAULT_PORT, "", "")]
}
+FILES_KEYS = ["files", "file_progress", "file_priorities"]
+
class WebApi(JSONComponent):
def __init__(self):
super(WebApi, self).__init__("Web")
@@ -315,8 +317,36 @@
client.core.get_filter_tree().addCallback(got_filters)
client.core.get_torrents_status(filter_dict,
keys).addCallback(got_torrents)
return d
+
+ def _on_got_files(self, torrent, d):
+ files = torrent.get("files")
+ file_progress = torrent.get("file_progress")
+ paths = []
+ info = {}
+ for index, torrent_file in enumerate(files):
+ path = torrent_file["path"]
+ paths.append(path)
+ torrent_file["progress"] = file_progress[index]
+ info[path] = torrent_file
+
+ def walk(path, item):
+ if type(item) is dict:
+ return item
+ return [info[path]["size"], info[path]["progress"]]
+
+ file_tree = uicommon.FileTree(paths)
+ file_tree.walk(walk)
+ d.callback(file_tree.get_tree())
+
@export
+ def get_torrent_files(self, torrent_id):
+ main_deferred = Deferred()
+ d = client.core.get_torrent_status(torrent_id, FILES_KEYS)
+ d.addCallback(self._on_got_files, main_deferred)
+ return main_deferred
+
+ @export
def download_torrent_from_url(self, url):
"""
input:
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---