From 86eeef4b92f5fcbff8f561c42833cef389808327 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Tue, 19 Feb 2008 20:50:29 +0000 Subject: [PATCH] refactor:remove ws.(part1) --- deluge/ui/webui/webui_plugin/config.py | 10 +-- .../webui/webui_plugin/config_tabs_deluge.py | 8 +- deluge/ui/webui/webui_plugin/json_api.py | 8 +- .../ui/webui/webui_plugin/page_decorators.py | 6 +- deluge/ui/webui/webui_plugin/pages.py | 28 +++--- .../webui_plugin/tests/multicall_notepad.py | 30 +++---- .../ui/webui/webui_plugin/tests/test_all.py | 24 +++--- deluge/ui/webui/webui_plugin/torrent_add.py | 18 ++-- deluge/ui/webui/webui_plugin/torrent_move.py | 6 +- deluge/ui/webui/webui_plugin/utils.py | 38 ++++---- .../ui/webui/webui_plugin/webserver_common.py | 86 ++++++------------- 11 files changed, 111 insertions(+), 151 deletions(-) diff --git a/deluge/ui/webui/webui_plugin/config.py b/deluge/ui/webui/webui_plugin/config.py index 8b8ea05c8..c4c3ab3f2 100644 --- a/deluge/ui/webui/webui_plugin/config.py +++ b/deluge/ui/webui/webui_plugin/config.py @@ -32,7 +32,7 @@ import lib.newforms_plus as forms import page_decorators as deco import lib.webpy022 as web -from webserver_common import ws +from webserver_common import ws, proxy, log from render import render from lib.webpy022.http import seeother import sys @@ -64,9 +64,9 @@ class CookieCfgForm(forms.Form): class CfgForm(forms.Form): "config base for deluge-cfg" def initial_data(self): - return ws.proxy.get_config() + return proxy.get_config() def save(self, data): - ws.proxy.set_config(dict(data)) + proxy.set_config(dict(data)) class config_page: """ @@ -95,12 +95,12 @@ class config_page: form_data = web.Storage(utils.get_newforms_data(form_class)) form = form_class(form_data) if form.is_valid(): - ws.log.debug('save config %s' % form_data) + log.debug('save config %s' % form_data) try: form.start_save() return self.render(form , name, _('These changes were saved')) except forms.ValidationError, e: - ws.log.debug(e.message) + log.debug(e.message) return self.render(form , name, error = e.message) else: return self.render(form , name, diff --git a/deluge/ui/webui/webui_plugin/config_tabs_deluge.py b/deluge/ui/webui/webui_plugin/config_tabs_deluge.py index 97c832a2b..0c9ef5ce4 100644 --- a/deluge/ui/webui/webui_plugin/config_tabs_deluge.py +++ b/deluge/ui/webui/webui_plugin/config_tabs_deluge.py @@ -34,7 +34,7 @@ import lib.newforms_plus as forms import config import utils -from webserver_common import ws +from webserver_common import ws, proxy , log class NetworkPorts(config.CfgForm ): @@ -126,15 +126,15 @@ config.register_block('deluge','daemon', Daemon) class Plugins(forms.Form): title = _("Enabled Plugins") try: - _choices = [(p,p) for p in ws.proxy.get_available_plugins()] + _choices = [(p,p) for p in proxy.get_available_plugins()] enabled_plugins = forms.MultipleChoice(_(""), _choices) except: - ws.log.error("Not connected to daemon, Unable to load plugin-list") + log.error("Not connected to daemon, Unable to load plugin-list") #TODO: reload on reconnect! def initial_data(self): - return {'enabled_plugins':ws.proxy.get_enabled_plugins()} + return {'enabled_plugins':proxy.get_enabled_plugins()} def save(self, value): raise forms.ValidationError("SAVE:TODO") diff --git a/deluge/ui/webui/webui_plugin/json_api.py b/deluge/ui/webui/webui_plugin/json_api.py index 92aece07d..e159fbd02 100644 --- a/deluge/ui/webui/webui_plugin/json_api.py +++ b/deluge/ui/webui/webui_plugin/json_api.py @@ -38,11 +38,11 @@ it would be possible not to include the python-json dependency. from new import instancemethod from inspect import getargspec -from utils import ws,get_torrent_status,get_category_choosers, get_stats,filter_torrent_state,fsize,fspeed +from utils import get_torrent_status,get_category_choosers, get_stats,filter_torrent_state,fsize,fspeed from page_decorators import remote from operator import attrgetter import lib.webpy022 as web -proxy = ws.proxy +from webserver_common import proxy, log def to_json(obj): from lib.pythonize import pythonize @@ -80,7 +80,7 @@ class json_api: method = getattr(self,name) vars = web.input(kwargs= None) - ws.log.debug('vars=%s' % vars) + log.debug('vars=%s' % vars) if vars.kwargs: kwargs = json.read(vars.kwargs) else: @@ -118,7 +118,7 @@ class json_api: #extra's: def list_torrents(self): return [get_torrent_status(torrent_id) - for torrent_id in ws.proxy.get_session_state()] + for torrent_id in proxy.get_session_state()] def simplify_torrent_status(self, torrent): """smaller subset and preformatted data for the treelist""" diff --git a/deluge/ui/webui/webui_plugin/page_decorators.py b/deluge/ui/webui/webui_plugin/page_decorators.py index 023193329..a9bfabb25 100644 --- a/deluge/ui/webui/webui_plugin/page_decorators.py +++ b/deluge/ui/webui/webui_plugin/page_decorators.py @@ -3,7 +3,7 @@ decorators for html-pages. """ #relative imports from render import render -from webserver_common import ws +from webserver_common import ws, log from utils import * #/relative @@ -30,7 +30,7 @@ def check_session(func): mostly used for POST-pages. """ def deco(self, name = None): - ws.log.debug('%s.%s(name=%s)' % (self.__class__.__name__, func.__name__, + log.debug('%s.%s(name=%s)' % (self.__class__.__name__, func.__name__, name)) vars = web.input(redir_after_login = None) ck = cookies() @@ -95,7 +95,7 @@ def remote(func): "decorator for remote (string) api's" def deco(self, name = None): try: - ws.log.debug('%s.%s(%s)' ,self.__class__.__name__, func.__name__,name ) + log.debug('%s.%s(%s)' ,self.__class__.__name__, func.__name__,name ) print func(self, name) except Exception, e: print 'error:%s' % e.message diff --git a/deluge/ui/webui/webui_plugin/pages.py b/deluge/ui/webui/webui_plugin/pages.py index a80a0c818..750031662 100644 --- a/deluge/ui/webui/webui_plugin/pages.py +++ b/deluge/ui/webui/webui_plugin/pages.py @@ -31,7 +31,7 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. # -from webserver_common import ws +from webserver_common import ws, proxy, log from utils import * from render import render, error_page import page_decorators as deco @@ -179,28 +179,28 @@ class torrent_start: @deco.check_session @deco.torrent_ids def POST(self, torrent_ids): - ws.proxy.resume_torrent(torrent_ids) + proxy.resume_torrent(torrent_ids) do_redirect() class torrent_stop: @deco.check_session @deco.torrent_ids def POST(self, torrent_ids): - ws.proxy.pause_torrent(torrent_ids) + proxy.pause_torrent(torrent_ids) do_redirect() class torrent_reannounce: @deco.check_session @deco.torrent_ids def POST(self, torrent_ids): - ws.proxy.force_reannounce(torrent_ids) + proxy.force_reannounce(torrent_ids) do_redirect() class torrent_recheck: @deco.check_session @deco.torrent_ids def POST(self, torrent_ids): - ws.proxy.force_recheck(torrent_ids) + proxy.force_recheck(torrent_ids) do_redirect() class torrent_delete: @@ -217,7 +217,7 @@ class torrent_delete: vars = web.input(data_also = None, torrent_also = None) data_also = bool(vars.data_also) torrent_also = bool(vars.torrent_also) - ws.proxy.remove_torrent(torrent_ids, torrent_also, data_also) + proxy.remove_torrent(torrent_ids, torrent_also, data_also) do_redirect() class torrent_queue_up: @@ -228,7 +228,7 @@ class torrent_queue_up: torrent_list.sort(lambda x, y : x.queue - y.queue) torrent_ids = [t.id for t in torrent_list] for torrent_id in torrent_ids: - ws.async_proxy.get_core().call("queue_queue_up", None, torrent_id) + async_proxy.get_core().call("queue_queue_up", None, torrent_id) do_redirect() class torrent_queue_down: @@ -239,7 +239,7 @@ class torrent_queue_down: torrent_list.sort(lambda x, y : x.queue - y.queue) torrent_ids = [t.id for t in torrent_list] for torrent_id in reversed(torrent_ids): - ws.async_proxy.get_core().call("queue_queue_down", None, torrent_id) + async_proxy.get_core().call("queue_queue_down", None, torrent_id) do_redirect() class torrent_files: @@ -253,19 +253,19 @@ class torrent_files: for pos in file_priorities: proxy_prio[int(pos)] = 1 - ws.proxy.set_torrent_file_priorities(torrent_id, proxy_prio) + proxy.set_torrent_file_priorities(torrent_id, proxy_prio) do_redirect() class pause_all: @deco.check_session def POST(self, name): - ws.proxy.pause_torrent(ws.proxy.get_session_state()) + proxy.pause_torrent(proxy.get_session_state()) do_redirect() class resume_all: @deco.check_session def POST(self, name): - ws.proxy.resume_torrent(ws.proxy.get_session_state()) + proxy.resume_torrent(proxy.get_session_state()) do_redirect() class refresh: @@ -319,7 +319,7 @@ class logout: class connect: @deco.deluge_page def GET(self, name): - #if ws.proxy.connected(): + #if proxy.connected(): # error = _("Not Connected to a daemon") #else: error = None @@ -361,7 +361,7 @@ class remote_torrent_add: else: #file-post (curl) data_b64 = base64.b64encode(vars.torrent.file.read()) torrent_name = vars.torrent.filename - ws.proxy.add_torrent_filecontent(torrent_name, data_b64) + proxy.add_torrent_filecontent(torrent_name, data_b64) return 'ok' class static(static_handler): @@ -374,7 +374,7 @@ class template_static(static_handler): class downloads(static_handler): def GET(self, name): - self.base_dir = ws.proxy.get_config_value('default_download_path') + self.base_dir = proxy.get_config_value('default_download_path') if not ws.config.get('share_downloads'): raise Exception('Access to downloads is forbidden.') return static_handler.GET(self, name) diff --git a/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py b/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py index 07a7b5066..4781e5d3f 100644 --- a/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py +++ b/deluge/ui/webui/webui_plugin/tests/multicall_notepad.py @@ -3,9 +3,8 @@ test multicall. """ import time -from WebUi.webserver_common import ws +from WebUi.webserver_common import ws, proxy, async_proxy ws.init_06() -async_proxy = ws.async_proxy TORRENT_KEYS = ['name', 'total_size', 'num_files', 'num_pieces', 'piece_length', 'eta', 'ratio', 'file_progress', 'distributed_copies', 'total_done', @@ -17,21 +16,18 @@ TORRENT_KEYS = ['name', 'total_size', 'num_files', 'num_pieces', 'piece_length', 'max_upload_slots', 'max_download_speed', 'prioritize_first_last', 'private' ] - - - if False: # #A: translate this into 1 multicall: start = time.time() stats = { - 'download_rate':ws.proxy.get_download_rate(), - 'upload_rate':ws.proxy.get_upload_rate(), - 'max_download':ws.proxy.get_config_value('max_download_speed'), - 'max_upload':ws.proxy.get_config_value('max_upload_speed'), - 'num_connections':ws.proxy.get_num_connections(), - 'max_num_connections':ws.proxy.get_config_value('max_connections_global') + 'download_rate':proxy.get_download_rate(), + 'upload_rate':proxy.get_upload_rate(), + 'max_download':proxy.get_config_value('max_download_speed'), + 'max_upload':proxy.get_config_value('max_upload_speed'), + 'num_connections':proxy.get_num_connections(), + 'max_num_connections':proxy.get_config_value('max_connections_global') } print "sync-stats:",time.time() - start @@ -66,8 +62,8 @@ if False: #old-sync: start = time.time() - torrent_list = [ws.proxy.get_torrent_status(id, TORRENT_KEYS ) - for id in ws.proxy.get_session_state() + torrent_list = [proxy.get_torrent_status(id, TORRENT_KEYS ) + for id in proxy.get_session_state() ] print "sync-list:",time.time() - start @@ -87,7 +83,7 @@ if False: start = time.time() - torrent_ids = ws.proxy.get_session_state() #Syc-api. + torrent_ids = proxy.get_session_state() #Syc-api. torrent_dict = {} for id in torrent_ids: async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, TORRENT_KEYS ) @@ -98,9 +94,9 @@ if False: print torrent_dict[torrent_ids[0]] if False: - print ws.proxy.get_config_value('download_location') + print proxy.get_config_value('download_location') if True: - torrent_id = ws.proxy.get_session_state()[0] + torrent_id = proxy.get_session_state()[0] print torrent_id - ws.proxy.move_torrent([torrent_id],"/media/sdb1/test") \ No newline at end of file + proxy.move_torrent([torrent_id],"/media/sdb1/test") \ No newline at end of file diff --git a/deluge/ui/webui/webui_plugin/tests/test_all.py b/deluge/ui/webui/webui_plugin/tests/test_all.py index 68b073e79..c9f6127ab 100644 --- a/deluge/ui/webui/webui_plugin/tests/test_all.py +++ b/deluge/ui/webui/webui_plugin/tests/test_all.py @@ -6,7 +6,7 @@ unittest the right way feels so unpythonic :( """ import unittest import cookielib, urllib2 , urllib -from WebUi.webserver_common import ws,TORRENT_KEYS +from WebUi.webserver_common import ws,TORRENT_KEYS, proxy import operator ws.init_06() @@ -17,7 +17,7 @@ BASE_URL = 'http://localhost:8112' PWD = 'deluge' def get_status(id): - return ws.proxy.get_torrent_status(id,TORRENT_KEYS) + return proxy.get_torrent_status(id,TORRENT_KEYS) #BASE: #303 = see other @@ -94,7 +94,7 @@ class TestWebUiBase(unittest.TestCase): else: pass - first_torrent_id = property(lambda self: ws.proxy.get_session_state()[0]) + first_torrent_id = property(lambda self: proxy.get_session_state()[0]) first_torrent = property(lambda self: get_status(self.first_torrent_id)) @@ -200,17 +200,17 @@ class TestIntegration(TestWebUiBase): 'http://torrents.aelitis.com:88/torrents/azautoseeder_0.1.1.jar.torrent' ]) - torrent_ids = ws.proxy.get_session_state() + torrent_ids = proxy.get_session_state() #avoid hammering, investigate current torrent-list and do not re-add. #correct means : 3 torrent's in list (for now) if len(torrent_ids) <> 3: #delete all, nice use case for refactoring delete.. - torrent_ids = ws.proxy.get_session_state() + torrent_ids = proxy.get_session_state() for torrent in torrent_ids: - ws.proxy.remove_torrent([torrent], False, False) + proxy.remove_torrent([torrent], False, False) - torrent_ids = ws.proxy.get_session_state() + torrent_ids = proxy.get_session_state() self.assertEqual(torrent_ids, []) #add 3 using url. @@ -218,7 +218,7 @@ class TestIntegration(TestWebUiBase): self.assert_303('/torrent/add','/index',{'url':url,'torrent':None}) #added? - self.torrent_ids = ws.proxy.get_session_state() + self.torrent_ids = proxy.get_session_state() self.assertEqual(len(self.torrent_ids), 3) else: @@ -231,14 +231,14 @@ class TestIntegration(TestWebUiBase): #pause all self.assert_303('/pause_all','/index', post=1) #pause worked? - pause_status = [get_status(id)["user_paused"] for id in ws.proxy.get_session_state()] + pause_status = [get_status(id)["user_paused"] for id in proxy.get_session_state()] for paused in pause_status: self.assertEqual(paused, True) #resume all self.assert_303('/resume_all','/index', post=1) #resume worked? - pause_status = [get_status(id)["user_paused"] for id in ws.proxy.get_session_state()] + pause_status = [get_status(id)["user_paused"] for id in proxy.get_session_state()] for paused in pause_status: self.assertEqual(paused,False) #pause again. @@ -254,7 +254,7 @@ class TestIntegration(TestWebUiBase): def testQueue(self): #find last: - torrent_id = [id for id in ws.proxy.get_session_state() + torrent_id = [id for id in proxy.get_session_state() if (get_status(id)['queue_pos'] ==3 )][0] #queue @@ -285,7 +285,7 @@ class TestIntegration(TestWebUiBase): def testMeta(self): #info available? - for torrent_id in ws.proxy.get_session_state(): + for torrent_id in proxy.get_session_state(): self.assert_exists('/torrent/info/%s' % torrent_id) self.assert_exists('/torrent/delete/%s' % torrent_id) diff --git a/deluge/ui/webui/webui_plugin/torrent_add.py b/deluge/ui/webui/webui_plugin/torrent_add.py index 09af27726..31da1f7d9 100644 --- a/deluge/ui/webui/webui_plugin/torrent_add.py +++ b/deluge/ui/webui/webui_plugin/torrent_add.py @@ -29,7 +29,7 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. # -from webserver_common import ws +from webserver_common import ws, log, proxy import utils from render import render, error_page import page_decorators as deco @@ -55,8 +55,8 @@ class OptionsForm(forms.Form): default_private = forms.CheckBox(_('Set Private Flag')) def initial_data(self): - data = ws.proxy.get_config() - ws.log.debug("add:Init options with:%s" % data) + data = proxy.get_config() + log.debug("add:Init options with:%s" % data) return data class AddForm(forms.Form): @@ -73,7 +73,7 @@ class torrent_add: def add_page(self,error = None): #form_data = utils.get_newforms_data(AddForm) - ws.log.debug("add-page") + log.debug("add-page") #TODO: CLEANUP!!! vars = web.input(url = None) form_data = {'url':vars.url} @@ -81,7 +81,7 @@ class torrent_add: options_data = None if error: options_data = utils.get_newforms_data(OptionsForm) - ws.log.debug("add:(error-state):Init options with:%s" % options_data) + log.debug("add:(error-state):Init options with:%s" % options_data) return render.torrent_add(AddForm(form_data),OptionsForm(options_data), error) @deco.deluge_page @@ -116,14 +116,14 @@ class torrent_add: print self.add_page(error = _("Choose an url or a torrent, not both.")) return if vars.url: - ws.proxy.add_torrent_url(vars.url,options) - ws.log.debug("add-url:options :%s" % options) + proxy.add_torrent_url(vars.url,options) + log.debug("add-url:options :%s" % options) utils.do_redirect() elif torrent_name: data_b64 = base64.b64encode(torrent_data) #b64 because of strange bug-reports related to binary data - ws.proxy.add_torrent_filecontent(vars.torrent.filename, data_b64, options) - ws.log.debug("add-file:options :%s" % options) + proxy.add_torrent_filecontent(vars.torrent.filename, data_b64, options) + log.debug("add-file:options :%s" % options) utils.do_redirect() else: print self.add_page(error = _("No data")) diff --git a/deluge/ui/webui/webui_plugin/torrent_move.py b/deluge/ui/webui/webui_plugin/torrent_move.py index e6f4174c1..9660c7a9e 100644 --- a/deluge/ui/webui/webui_plugin/torrent_move.py +++ b/deluge/ui/webui/webui_plugin/torrent_move.py @@ -30,7 +30,7 @@ # statement from all source files in the program, then also delete it here. # -from webserver_common import ws +from webserver_common import ws, proxy import utils from render import render import page_decorators as deco @@ -42,7 +42,7 @@ import lib.webpy022 as web class MoveForm(forms.Form): save_path = forms.ServerFolder(_("Move To")) def initial_data(self): - return {'save_path':ws.proxy.get_config_value('download_location')} + return {'save_path':proxy.get_config_value('download_location')} class torrent_move: @@ -70,5 +70,5 @@ class torrent_move: print self.move_page(name, error = _("Error in Path.")) return save_path = form.clean_data["save_path"] - ws.proxy.move_torrent(torrent_ids, save_path) + proxy.move_torrent(torrent_ids, save_path) utils.do_redirect() diff --git a/deluge/ui/webui/webui_plugin/utils.py b/deluge/ui/webui/webui_plugin/utils.py index 4a28ce505..ac2e43866 100644 --- a/deluge/ui/webui/webui_plugin/utils.py +++ b/deluge/ui/webui/webui_plugin/utils.py @@ -47,7 +47,7 @@ import pickle from urlparse import urlparse from webserver_common import REVNO, VERSION, TORRENT_KEYS, STATE_MESSAGES -from webserver_common import ws +from webserver_common import ws, proxy, async_proxy, log debug_unicode = False @@ -64,7 +64,7 @@ def setcookie(key, val): #really simple sessions, to bad i had to implement them myself. def start_session(): - ws.log.debug('start session') + log.debug('start session') session_id = str(random.random()) ws.SESSIONS.append(session_id) #if len(ws.SESSIONS) > 20: #save max 20 sessions? @@ -113,21 +113,21 @@ def getcookie(key, default = None): def get_stats(): 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) + async_proxy.get_download_rate(dict_cb('download_rate',stats)) + async_proxy.get_upload_rate(dict_cb('upload_rate',stats)) + async_proxy.get_config_value(dict_cb('max_download',stats) ,"max_download_speed") - ws.async_proxy.get_config_value(dict_cb('max_upload',stats) + 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) + async_proxy.get_num_connections(dict_cb("num_connections",stats)) + async_proxy.get_config_value(dict_cb('max_num_connections',stats) ,"max_connections_global") - ws.async_proxy.get_dht_nodes(dict_cb('dht_nodes',stats)) + async_proxy.get_dht_nodes(dict_cb('dht_nodes',stats)) - ws.async_proxy.force_call(block=True) + async_proxy.force_call(block=True) - #ws.log.debug(str(stats)) + #log.debug(str(stats)) stats.download_rate = fspeed(stats.download_rate) stats.upload_rate = fspeed(stats.upload_rate) @@ -157,10 +157,10 @@ def enhance_torrent_status(torrent_id,status): for key in TORRENT_KEYS: if not key in status: status[key] = 0 - #ws.log.warning('torrent_status:empty key in status:%s' % key) + #log.warning('torrent_status:empty key in status:%s' % key) elif status[key] == None: status[key] = 0 - #ws.log.warning('torrent_status:None key in status:%s' % key) + #log.warning('torrent_status:None key in status:%s' % key) if status.tracker == 0: @@ -222,9 +222,9 @@ def enhance_torrent_status(torrent_id,status): def get_torrent_status(torrent_id): """ helper method. - enhance ws.proxy.get_torrent_status with some extra data + enhance proxy.get_torrent_status with some extra data """ - status = ws.proxy.get_torrent_status(torrent_id,TORRENT_KEYS) + status = proxy.get_torrent_status(torrent_id,TORRENT_KEYS) return enhance_torrent_status(torrent_id, status) @@ -234,12 +234,12 @@ def get_torrent_list(): """ uses async. """ - torrent_ids = ws.proxy.get_session_state() #Syc-api. + torrent_ids = proxy.get_session_state() #Syc-api. torrent_dict = {} for id in torrent_ids: - ws.async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, + async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, TORRENT_KEYS) - ws.async_proxy.force_call(block=True) + async_proxy.force_call(block=True) return [enhance_torrent_status(id, status) for id, status in torrent_dict.iteritems()] @@ -307,7 +307,7 @@ def get_newforms_data(form_class): vars = web.input() for field in fields: form_data[field] = vars.get(field) - #ws.log.debug("form-field:%s=%s" % (field, form_data[field])) + #log.debug("form-field:%s=%s" % (field, form_data[field])) #DIRTY HACK: (for multiple-select) if isinstance(form_class.base_fields[field], forms.MultipleChoiceField): diff --git a/deluge/ui/webui/webui_plugin/webserver_common.py b/deluge/ui/webui/webui_plugin/webserver_common.py index d8dd12752..235e60a94 100644 --- a/deluge/ui/webui/webui_plugin/webserver_common.py +++ b/deluge/ui/webui/webui_plugin/webserver_common.py @@ -43,6 +43,8 @@ import sys import base64 from md5 import md5 import inspect +from deluge.ui import client +from deluge.log import LOG as log random.seed() @@ -80,12 +82,6 @@ TORRENT_KEYS = ['name', 'total_size', 'num_files', 'num_pieces', 'piece_length', "user_paused" ] -""" -NOT:is_seed,total_download,total_upload,uploaded_memory,queue_pos,user_paused -""" - - - STATE_MESSAGES = [ "Allocating", @@ -111,29 +107,28 @@ CONFIG_DEFAULTS = { #/constants - -class SyncProxyFunction: +#some magic to transform the async-proxy back to sync: +class SyncProxyMethod: """ helper class for SyncProxy """ - def __init__(self,client, func_name): + def __init__(self, func_name): self.func_name = func_name - self.client = client def __call__(self,*args,**kwargs): - func = getattr(self.client,self.func_name) + func = getattr(client,self.func_name) if self.has_callback(func): + #(ab)using list.append as a builtin callback method sync_result = [] func(sync_result.append,*args, **kwargs) - self.client.force_call(block=True) + client.force_call(block=True) if not sync_result: return None return sync_result[0] else: - ws.log.debug('no-cb: %s' % self.func_name) func(*args, **kwargs) - self.client.force_call(block=True) + client.force_call(block=True) return @staticmethod @@ -142,11 +137,14 @@ class SyncProxyFunction: class SyncProxy(object): """acts like the old synchonous proxy""" - def __init__(self, client): - self.client = client + def __getattr__(self, attr): + return SyncProxyMethod(attr) - def __getattr__(self, attr,*args,**kwargs): - return SyncProxyFunction(self.client, attr) +#moving stuff from WS to module +#goal: eliminate WS, because the 05 compatiblilty is not needed anymore +proxy = SyncProxy() +async_proxy = client +#log is already imported. class Ws: @@ -182,37 +180,31 @@ class Ws: self.config = pickle.load(open(self.config_file)) def init_06(self, uri = 'http://localhost:58846'): - import deluge.ui.client as async_proxy - from deluge.log import LOG as log - self.log = log - async_proxy.set_core_uri(uri) - self.async_proxy = async_proxy - - self.proxy = SyncProxy(self.async_proxy) - + client.set_core_uri(uri) + self.async_proxy = client #MONKEY PATCH, TODO->REMOVE!!! def add_torrent_filecontent(name , data_b64, options): - self.log.debug('monkeypatched add_torrent_filecontent:%s,len(data:%s))' % + log.debug('monkeypatched add_torrent_filecontent:%s,len(data:%s))' % (name , len(data_b64))) name = name.replace('\\','/') name = 'deluge06_' + str(random.random()) + '_' + name.split('/')[-1] filename = os.path.join('/tmp', name) - self.log.debug('write: %s' % filename) + log.debug('write: %s' % filename) f = open(filename,"wb") f.write(base64.b64decode(data_b64)) f.close() - self.log.debug("options:%s" % options) + log.debug("options:%s" % options) self.proxy.add_torrent_file([filename] , [options]) - self.proxy.add_torrent_filecontent = add_torrent_filecontent - self.log.debug('cfg-file %s' % self.config_file) + proxy.add_torrent_filecontent = add_torrent_filecontent + log.debug('cfg-file %s' % self.config_file) if not os.path.exists(self.config_file): - self.log.debug('create cfg file %s' % self.config_file) + log.debug('create cfg file %s' % self.config_file) #load&save defaults. f = file(self.config_file,'wb') pickle.dump(CONFIG_DEFAULTS,f) @@ -221,34 +213,6 @@ class Ws: self.init_process() self.env = '0.6' - def init_05(self): - import dbus - self.init_process() - bus = dbus.SessionBus() - self.proxy = bus.get_object("org.deluge_torrent.dbusplugin" - , "/org/deluge_torrent/DelugeDbusPlugin") - - self.env = '0.5_process' - self.init_logger() - - def init_gtk_05(self): - #appy possibly changed config-vars, only called in when runing inside gtk. - #new bug ws.render will not update!!!! - #other bug: must warn if blocklist plugin is active! - from dbus_interface import get_dbus_manager - self.proxy = get_dbus_manager() - self.config = deluge.pref.Preferences(self.config_file, False) - self.env = '0.5_gtk' - self.init_logger() - - def init_logger(self): - #only for 0.5.. - import logging - logging.basicConfig(level=logging.DEBUG, - format="[%(levelname)s] %(message)s") - self.log = logging - - #utils for config: def get_templates(self): template_path = os.path.join(os.path.dirname(__file__), 'templates') @@ -258,7 +222,7 @@ class Ws: and not dirname.startswith('.')] def save_config(self): - self.log.debug('Save Webui Config') + log.debug('Save Webui Config') data = pickle.dumps(self.config) f = open(self.config_file,'wb') f.write(data)