async status-bar + pause/resume

This commit is contained in:
Martijn Voncken 2008-01-21 19:31:36 +00:00
parent c9a5caa3ec
commit 3807b372ff
3 changed files with 49 additions and 22 deletions

View File

@ -27,7 +27,6 @@ print "sync-stats:",time.time() - start
print stats
#
#pattern:
#map callback to a a dict-setter
def dict_cb(key,d):
def callback(result):
@ -39,11 +38,10 @@ d = {}
async_proxy.get_download_rate(dict_cb('download_rate',d))
async_proxy.get_upload_rate(dict_cb('upload_rate',d))
async_proxy.get_config_value(dict_cb('max_download',d),"max_download_speed")
async_proxy.get_config_value(dict_cb('max_download',d),"max_upload_speed")
async_proxy.get_config_value(dict_cb('max_upload',d),"max_upload_speed")
async_proxy.get_num_connections(dict_cb("num_connections",d))
async_proxy.get_config_value(dict_cb('max_num_connections',d),"max_connections_global")
async_proxy.force_call(block=True)
print "Async-stats:",time.time() - start
@ -55,22 +53,25 @@ print d
#old-sync:
start = time.time()
torrent_list = [ws.proxy.get_torrent_status(id,[])
for id in ws.proxy.get_session_state()
]
print "sync-list:",time.time() - start
print torrent_list
#new async:
start = time.time()
torrent_ids = ws.proxy.get_session_state() #Syc-api.
torrent_list = []
for id in torrent_ids:
async_proxy.get_torrent_status(torrent_list.append, id, [])
async_proxy.force_call(block=True)
print "Async-list:",time.time() - start
print "Async-list:",time.time() - start
print torrent_list

View File

@ -51,6 +51,12 @@ from webserver_common import ws
debug_unicode = False
#async-proxy: map callback to a a dict-setter
def dict_cb(key,d):
def callback(result):
d[key] = result
return callback
#methods:
def setcookie(key, val):
"""add 30 days expires header for persistent cookies"""
@ -105,23 +111,37 @@ def getcookie(key, default = None):
def get_stats():
stats = Storage({
'download_rate':fspeed(ws.proxy.get_download_rate()),
'upload_rate':fspeed(ws.proxy.get_upload_rate()),
'max_download':ws.proxy.get_config_value('max_download_speed_bps'),
'max_upload':ws.proxy.get_config_value('max_upload_speed_bps'),
'num_connections':ws.proxy.get_num_connections(),
'max_num_connections':ws.proxy.get_config_value('max_connections_global')
})
stats = Storage()
ws.async_proxy.get_download_rate(dict_cb('download_rate',stats))
ws.async_proxy.get_upload_rate(dict_cb('upload_rate',stats))
ws.async_proxy.get_config_value(dict_cb('max_download',stats)
,"max_download_speed")
ws.async_proxy.get_config_value(dict_cb('max_upload',stats)
,"max_upload_speed")
ws.async_proxy.get_num_connections(dict_cb("num_connections",stats))
ws.async_proxy.get_config_value(dict_cb('max_num_connections',stats)
,"max_connections_global")
ws.async_proxy.force_call(block=True)
ws.log.debug(str(stats))
stats.download_rate = fspeed(stats.download_rate)
stats.upload_rate = fspeed(stats.upload_rate)
#stats.max_upload = stats.max_upload
#stats.max_download = stats.max_download
if stats.max_upload < 0:
stats.max_upload = _("Unlimited")
else:
stats.max_upload = fspeed(stats.max_upload)
stats.max_upload = "%s KiB/s" % stats.max_upload
if stats.max_download < 0:
stats.max_download = _("Unlimited")
else:
stats.max_download = fspeed(stats.max_download)
stats.max_download = "%s KiB/s" % stats.max_download
return stats
@ -167,7 +187,7 @@ def get_torrent_status(torrent_id):
status.calc_state_str = "seeding"
#action for torrent_pause
if status.user_paused:
if status.paused: #no user-paused in 0.6 !!!
status.action = "start"
else:
status.action = "stop"

View File

@ -42,6 +42,7 @@ import pickle
import sys
import base64
from md5 import md5
import inspect
random.seed()
@ -118,16 +119,21 @@ class SyncProxyFunction():
def __call__(self,*args,**kwargs):
sync_result = []
def callback( result):
sync_result.append(result)
func = getattr(self.client,self.func_name)
func(callback,*args)
if self.has_callback(func):
func(sync_result.append,*args, **kwargs)
self.client.force_call(block=True)
return sync_result[0]
else:
ws.log.debug('no-cb: %s' % self.func_name)
func(*args, **kwargs)
self.client.force_call(block=True)
return
self.client.force_call(block=True)
return sync_result[0]
@staticmethod
def has_callback(func):
return "callback" in inspect.getargspec(func)[0]
class SyncProxy(object):
"""acts like the old synchonous proxy"""