json:add get_stats method

This commit is contained in:
Martijn Voncken 2008-06-30 17:33:01 +00:00
parent 7e076a82a0
commit 6f87ba0646
4 changed files with 53 additions and 3 deletions

View File

@ -43,9 +43,10 @@ design:
from traceback import format_exc
import web
from web import webapi
from deluge.ui.client import sclient
from deluge.ui.client import sclient,aclient
from deluge.log import LOG as log
from deluge import component
from utils import dict_cb
from page_decorators import check_session
try:
@ -82,6 +83,8 @@ class json_rpc:
result = self.exec_system_method(method, params,id)
elif method == ("list_torrents"):
result = self.list_torrents(method, params,id)
elif method == ("get_stats"):
result = self.exec_get_stats(method, params,id)
else:
result = self.exec_client_method(method, params,id)
@ -121,9 +124,37 @@ class json_rpc:
def exec_system_method(self, method, params, id):
if method == "system.listMethods":
return self.exec_client_method("list_methods", params, id)
methods = sclient.list_methods()
return {
"version":"1.1",
"result":methods + ["get_stats"],
"id":id
}
raise Exception('Unknown method:%s', method)
def exec_get_stats(self, method, params, id):
stats = {}
aclient.get_download_rate(dict_cb('download_rate',stats))
aclient.get_upload_rate(dict_cb('upload_rate',stats))
aclient.get_config_value(dict_cb('max_download',stats)
,"max_download_speed")
aclient.get_config_value(dict_cb('max_upload',stats)
,"max_upload_speed")
aclient.get_num_connections(dict_cb("num_connections",stats))
aclient.get_config_value(dict_cb('max_num_connections',stats)
,"max_connections_global")
aclient.get_dht_nodes(dict_cb('dht_nodes',stats))
aclient.force_call(block=True)
return {
"version":"1.1",
"result":stats,
"id":id
}
def list_torrents(self,params,id):
"""

View File

@ -75,7 +75,7 @@ class login:
if utils.check_pwd(vars.pwd):
#start new session
start_session()
do_redirect()
utils.seeother('/index')
elif vars.redir:
utils.seeother(url('/login', error=1, redir=vars.redir))
else:

View File

@ -62,6 +62,20 @@ function update_torrent(torrent) {
};
function get_stats() {
service.get_stats({params:[],
onSuccess:function(stats){
alert(stats.download_rate);
},
onException:function(errorObj){
alert("Error: " + errorObj);
}
});
};
@ -72,6 +86,7 @@ function update_torrent(torrent) {
<button onclick="list_torrents()">List torrents</button>
<button onclick="get_stats()">get_stats()</button>
<div id="torrent_list">

View File

@ -87,12 +87,16 @@ def self_url(**kwargs):
return config["base"] + changequery(**kwargs)
def do_redirect():
import render
"""go to /index unless the redir var is set."""
vars = web.input(redir=None)
if vars.redir:
w_seeother(vars.redir) #redir variable contains base
return
#test-alt-home
if hasattr(render,"home"):
return render.home()
#default:
seeother('/index')