From b803d39d6374a74b1de3162d7c8bfdb04e75d7eb Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sat, 22 Dec 2007 08:15:51 +0000 Subject: [PATCH] webui sync r168 --- plugins/WebUi/__init__.py | 4 +- plugins/WebUi/debugerror.py | 6 +- plugins/WebUi/deluge_webserver.py | 7 +- plugins/WebUi/json_api.py | 132 ++++++++++++++++++ plugins/WebUi/lib/__init__.py | 0 .../{ => lib}/gtk_cherrypy_wsgiserver.py | 0 .../{dbus_pythonize.py => lib/pythonize.py} | 0 plugins/WebUi/lib/readme.txt | 8 ++ plugins/WebUi/{ => lib}/static_handler.py | 0 .../Dependency-not-really part of webui.txt | 0 plugins/WebUi/{ => lib}/webpy022/__init__.py | 0 plugins/WebUi/{ => lib}/webpy022/changes.txt | 0 plugins/WebUi/{ => lib}/webpy022/cheetah.py | 0 plugins/WebUi/{ => lib}/webpy022/db.py | 0 .../WebUi/{ => lib}/webpy022/debugerror.py | 0 plugins/WebUi/{ => lib}/webpy022/form.py | 0 plugins/WebUi/{ => lib}/webpy022/http.py | 0 .../WebUi/{ => lib}/webpy022/httpserver.py | 0 plugins/WebUi/{ => lib}/webpy022/net.py | 0 plugins/WebUi/{ => lib}/webpy022/request.py | 0 plugins/WebUi/{ => lib}/webpy022/template.py | 0 plugins/WebUi/{ => lib}/webpy022/utils.py | 0 plugins/WebUi/{ => lib}/webpy022/webapi.py | 0 plugins/WebUi/{ => lib}/webpy022/wsgi.py | 0 .../{ => lib}/webpy022/wsgiserver/__init__.py | 0 plugins/WebUi/revno | 1 - plugins/WebUi/templates/advanced/index.html | 5 +- .../templates/advanced/static/advanced.css | 16 +++ .../WebUi/templates/advanced/static/deluge.js | 5 +- .../WebUi/templates/deluge/part_refresh.html | 13 -- plugins/WebUi/version | 5 - plugins/WebUi/webserver_common.py | 9 +- plugins/WebUi/webserver_framework.py | 37 +++-- 33 files changed, 204 insertions(+), 44 deletions(-) create mode 100644 plugins/WebUi/json_api.py create mode 100644 plugins/WebUi/lib/__init__.py rename plugins/WebUi/{ => lib}/gtk_cherrypy_wsgiserver.py (100%) rename plugins/WebUi/{dbus_pythonize.py => lib/pythonize.py} (100%) create mode 100644 plugins/WebUi/lib/readme.txt rename plugins/WebUi/{ => lib}/static_handler.py (100%) rename plugins/WebUi/{ => lib}/webpy022/Dependency-not-really part of webui.txt (100%) rename plugins/WebUi/{ => lib}/webpy022/__init__.py (100%) rename plugins/WebUi/{ => lib}/webpy022/changes.txt (100%) rename plugins/WebUi/{ => lib}/webpy022/cheetah.py (100%) rename plugins/WebUi/{ => lib}/webpy022/db.py (100%) rename plugins/WebUi/{ => lib}/webpy022/debugerror.py (100%) rename plugins/WebUi/{ => lib}/webpy022/form.py (100%) rename plugins/WebUi/{ => lib}/webpy022/http.py (100%) rename plugins/WebUi/{ => lib}/webpy022/httpserver.py (100%) rename plugins/WebUi/{ => lib}/webpy022/net.py (100%) rename plugins/WebUi/{ => lib}/webpy022/request.py (100%) rename plugins/WebUi/{ => lib}/webpy022/template.py (100%) rename plugins/WebUi/{ => lib}/webpy022/utils.py (100%) rename plugins/WebUi/{ => lib}/webpy022/webapi.py (100%) rename plugins/WebUi/{ => lib}/webpy022/wsgi.py (100%) rename plugins/WebUi/{ => lib}/webpy022/wsgiserver/__init__.py (100%) delete mode 100644 plugins/WebUi/revno delete mode 100644 plugins/WebUi/templates/deluge/part_refresh.html delete mode 100644 plugins/WebUi/version diff --git a/plugins/WebUi/__init__.py b/plugins/WebUi/__init__.py index d33df9a4a..85f372757 100644 --- a/plugins/WebUi/__init__.py +++ b/plugins/WebUi/__init__.py @@ -97,7 +97,7 @@ class plugin_WebUi(object): if status[0] == 0: os.kill(int(status[1].split()[0]), 9) time.sleep(1) #safe time to wait for kill to finish. - self.config_file = os.path.join(deluge.common.CONFIG_DIR, "webui.conf") + self.config_file = deluge.common.CONFIG_DIR + "/webui.conf" self.config = deluge.pref.Preferences(self.config_file, False) try: self.config.load() @@ -162,7 +162,7 @@ class plugin_WebUi(object): else: print 'Start Webui(in process)..' - server_bin = os.path.join(os.path.dirname(__file__), 'run_webserver') + server_bin = os.path.dirname(__file__) + '/run_webserver' self.proc = Popen((server_bin,'env=0.5')) def kill_server(self): diff --git a/plugins/WebUi/debugerror.py b/plugins/WebUi/debugerror.py index f1ef73001..259dcac72 100644 --- a/plugins/WebUi/debugerror.py +++ b/plugins/WebUi/debugerror.py @@ -11,9 +11,9 @@ http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 __all__ = ["debugerror", "djangoerror"] import sys, urlparse, pprint -from webpy022.net import websafe -from webpy022.template import Template -import webpy022.webapi as web +from lib.webpy022.net import websafe +from lib.webpy022.template import Template +import lib.webpy022.webapi as web import webserver_common as ws from traceback import format_tb diff --git a/plugins/WebUi/deluge_webserver.py b/plugins/WebUi/deluge_webserver.py index 6f70f02db..e8fd839b9 100644 --- a/plugins/WebUi/deluge_webserver.py +++ b/plugins/WebUi/deluge_webserver.py @@ -34,13 +34,15 @@ import webserver_common as ws from webserver_framework import * -import webpy022 as web -from webpy022.http import seeother, url +import lib.webpy022 as web +from lib.webpy022.http import seeother, url import base64 from operator import attrgetter import os +from json_api import json_api + #routing: urls = ( "/login", "login", @@ -64,6 +66,7 @@ urls = ( "/logout", "logout", #remote-api: "/remote/torrent/add(.*)", "remote_torrent_add", + "/json/(.*)","json_api", #static: "/static/(.*)", "static", "/template/static/(.*)", "template_static", diff --git a/plugins/WebUi/json_api.py b/plugins/WebUi/json_api.py new file mode 100644 index 000000000..7dc01e380 --- /dev/null +++ b/plugins/WebUi/json_api.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# webserver_framework.py +# +# Copyright (C) Martijn Voncken 2007 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, write to: +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. +""" +json api. +only used for XUL and/or external scripts +it would be possible not to incluse the python-json dependency. +""" + +import deluge.ui.client as proxy +from new import instancemethod +from inspect import getargspec +from webserver_framework import remote,ws,get_torrent_status,log +proxy = ws.proxy + +def to_json(obj): + from lib.pythonize import pythonize + obj = pythonize(obj) + try: + import json + return json.write(obj) + except ImportError: + raise ImportError("""Install python-json using your package-manager + http://sourceforge.net/projects/json-py/""") + +class json_api: + """ + eperimental json api + generic proxy for all methods onm self. + """ + illegal_methods = ['shutdown', 'socket', 'xmlrpclib','pickle','os', + 'is_localhost','CoreProxy','connect_on_new_core', 'connect_on_no_core', + 'connected','deluge','GET','POST'] + def __init__(self): + self._add_proxy_methods() + + @remote + def GET(self,name): + if name.startswith('_'): + raise AttributeError('_ methods are illegal!') + if name in self.illegal_methods: + raise AttributeError('Illegal method , I smell a rat!') + if not(hasattr(self,name)): + raise AttributeError('No such Method') + + method = getattr(self,name) + kwargs = {} + + result = method(**kwargs) + + return to_json(result) + + POST = GET + + def list_methods(self): + """ + list all json methods + returns a dict of {methodname:{args:[list of kwargs],doc:'string'},..} + """ + methods = [getattr(self,m) for m in dir(self) + if not m.startswith('_') + and (not m in self.illegal_methods) + and callable(getattr(self,m)) + ] + + return dict([(f.__name__, + {'args':getargspec(f)[0],'doc':(f.__doc__ or '').strip()}) + for f in methods]) + + def _add_proxy_methods(self): + methods = [getattr(proxy,m) for m in dir(proxy) + if not m.startswith('_') + and (not m in self.illegal_methods) + and callable(getattr(proxy,m)) + ] + for m in methods: + setattr(self,m.__name__,m) + + #extra's: + def list_torrents(self): + return [get_torrent_status(torrent_id) + for torrent_id in ws.proxy.get_session_state()] + + get_torrent_status = get_torrent_status + + + +if __name__ == '__main__': + from pprint import pprint + #proxy.set_core_uri('http://localhost:58846') #How to configure this? + j = json_api() + if True: + print 'list-methods:' + methods = j.list_methods() + names = methods.keys() + names.sort() + for name in names: + m = methods[name] + print "%s(%s)\n %s\n" % (name , m['args'] , m['doc']) + + #j.GET('list_torrents') + j.POST('list_torrents') + diff --git a/plugins/WebUi/lib/__init__.py b/plugins/WebUi/lib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/WebUi/gtk_cherrypy_wsgiserver.py b/plugins/WebUi/lib/gtk_cherrypy_wsgiserver.py similarity index 100% rename from plugins/WebUi/gtk_cherrypy_wsgiserver.py rename to plugins/WebUi/lib/gtk_cherrypy_wsgiserver.py diff --git a/plugins/WebUi/dbus_pythonize.py b/plugins/WebUi/lib/pythonize.py similarity index 100% rename from plugins/WebUi/dbus_pythonize.py rename to plugins/WebUi/lib/pythonize.py diff --git a/plugins/WebUi/lib/readme.txt b/plugins/WebUi/lib/readme.txt new file mode 100644 index 000000000..1b68f9447 --- /dev/null +++ b/plugins/WebUi/lib/readme.txt @@ -0,0 +1,8 @@ +This folder may only contain general purpose utilities/files/tools. +They should be usable outside of deluge. + +Disclaimer: + +Some may have been adapted to work better with deluge. +But they will not other import parts of deluge or Webui. + diff --git a/plugins/WebUi/static_handler.py b/plugins/WebUi/lib/static_handler.py similarity index 100% rename from plugins/WebUi/static_handler.py rename to plugins/WebUi/lib/static_handler.py diff --git a/plugins/WebUi/webpy022/Dependency-not-really part of webui.txt b/plugins/WebUi/lib/webpy022/Dependency-not-really part of webui.txt similarity index 100% rename from plugins/WebUi/webpy022/Dependency-not-really part of webui.txt rename to plugins/WebUi/lib/webpy022/Dependency-not-really part of webui.txt diff --git a/plugins/WebUi/webpy022/__init__.py b/plugins/WebUi/lib/webpy022/__init__.py similarity index 100% rename from plugins/WebUi/webpy022/__init__.py rename to plugins/WebUi/lib/webpy022/__init__.py diff --git a/plugins/WebUi/webpy022/changes.txt b/plugins/WebUi/lib/webpy022/changes.txt similarity index 100% rename from plugins/WebUi/webpy022/changes.txt rename to plugins/WebUi/lib/webpy022/changes.txt diff --git a/plugins/WebUi/webpy022/cheetah.py b/plugins/WebUi/lib/webpy022/cheetah.py similarity index 100% rename from plugins/WebUi/webpy022/cheetah.py rename to plugins/WebUi/lib/webpy022/cheetah.py diff --git a/plugins/WebUi/webpy022/db.py b/plugins/WebUi/lib/webpy022/db.py similarity index 100% rename from plugins/WebUi/webpy022/db.py rename to plugins/WebUi/lib/webpy022/db.py diff --git a/plugins/WebUi/webpy022/debugerror.py b/plugins/WebUi/lib/webpy022/debugerror.py similarity index 100% rename from plugins/WebUi/webpy022/debugerror.py rename to plugins/WebUi/lib/webpy022/debugerror.py diff --git a/plugins/WebUi/webpy022/form.py b/plugins/WebUi/lib/webpy022/form.py similarity index 100% rename from plugins/WebUi/webpy022/form.py rename to plugins/WebUi/lib/webpy022/form.py diff --git a/plugins/WebUi/webpy022/http.py b/plugins/WebUi/lib/webpy022/http.py similarity index 100% rename from plugins/WebUi/webpy022/http.py rename to plugins/WebUi/lib/webpy022/http.py diff --git a/plugins/WebUi/webpy022/httpserver.py b/plugins/WebUi/lib/webpy022/httpserver.py similarity index 100% rename from plugins/WebUi/webpy022/httpserver.py rename to plugins/WebUi/lib/webpy022/httpserver.py diff --git a/plugins/WebUi/webpy022/net.py b/plugins/WebUi/lib/webpy022/net.py similarity index 100% rename from plugins/WebUi/webpy022/net.py rename to plugins/WebUi/lib/webpy022/net.py diff --git a/plugins/WebUi/webpy022/request.py b/plugins/WebUi/lib/webpy022/request.py similarity index 100% rename from plugins/WebUi/webpy022/request.py rename to plugins/WebUi/lib/webpy022/request.py diff --git a/plugins/WebUi/webpy022/template.py b/plugins/WebUi/lib/webpy022/template.py similarity index 100% rename from plugins/WebUi/webpy022/template.py rename to plugins/WebUi/lib/webpy022/template.py diff --git a/plugins/WebUi/webpy022/utils.py b/plugins/WebUi/lib/webpy022/utils.py similarity index 100% rename from plugins/WebUi/webpy022/utils.py rename to plugins/WebUi/lib/webpy022/utils.py diff --git a/plugins/WebUi/webpy022/webapi.py b/plugins/WebUi/lib/webpy022/webapi.py similarity index 100% rename from plugins/WebUi/webpy022/webapi.py rename to plugins/WebUi/lib/webpy022/webapi.py diff --git a/plugins/WebUi/webpy022/wsgi.py b/plugins/WebUi/lib/webpy022/wsgi.py similarity index 100% rename from plugins/WebUi/webpy022/wsgi.py rename to plugins/WebUi/lib/webpy022/wsgi.py diff --git a/plugins/WebUi/webpy022/wsgiserver/__init__.py b/plugins/WebUi/lib/webpy022/wsgiserver/__init__.py similarity index 100% rename from plugins/WebUi/webpy022/wsgiserver/__init__.py rename to plugins/WebUi/lib/webpy022/wsgiserver/__init__.py diff --git a/plugins/WebUi/revno b/plugins/WebUi/revno deleted file mode 100644 index 9e42f3ef0..000000000 --- a/plugins/WebUi/revno +++ /dev/null @@ -1 +0,0 @@ -165 diff --git a/plugins/WebUi/templates/advanced/index.html b/plugins/WebUi/templates/advanced/index.html index 703ec5520..23525a02d 100644 --- a/plugins/WebUi/templates/advanced/index.html +++ b/plugins/WebUi/templates/advanced/index.html @@ -47,7 +47,7 @@ $:render.header(_('Torrent list'))
- +
$:(sort_head('calc_state_str', 'S')) @@ -67,9 +67,10 @@ $:render.header(_('Torrent list')) +$altrow(True) $#4-space indentation is mandatory for for-loops in templetor! $for torrent in torrent_list: - +
diff --git a/plugins/WebUi/templates/advanced/static/advanced.css b/plugins/WebUi/templates/advanced/static/advanced.css index 3a03f0056..b4fa9db10 100644 --- a/plugins/WebUi/templates/advanced/static/advanced.css +++ b/plugins/WebUi/templates/advanced/static/advanced.css @@ -78,6 +78,19 @@ tr.torrent_table:hover { background-color:#68a; } +tr.altrow0:hover { + background-color:#68a; +} +tr.altrow1:hover { + background-color:#68a; +} + +tr.altrow1{ + background-color: #37506f; +} + + + tr.torrent_table_selected { background-color:#900; } @@ -85,6 +98,9 @@ tr.torrent_table_selected { th.torrent_table:hover { background-color:#68a; } +th.torrent_table { + background-color: #37506f; +} img.button { margin-bottom:0px; diff --git a/plugins/WebUi/templates/advanced/static/deluge.js b/plugins/WebUi/templates/advanced/static/deluge.js index 4cb557ffd..da6be06e1 100644 --- a/plugins/WebUi/templates/advanced/static/deluge.js +++ b/plugins/WebUi/templates/advanced/static/deluge.js @@ -45,6 +45,9 @@ function on_click_row_js(e, id) { function select_row(id){ var row = get_row(id); if (row) { + if (!(row.default_class_name)) { + row.default_class_name = row.className; + } row.className = 'torrent_table_selected'; state.selected_rows[state.selected_rows.length] = id; setCookie('selected_rows',state.selected_rows); @@ -54,7 +57,7 @@ function select_row(id){ function deselect_row(id){ var row = get_row(id); if (row) { - row.className = 'torrent_table' + row.className = row.default_class_name /*remove from state.selected_rows*/ var idx = state.selected_rows.indexOf(id); state.selected_rows.splice(idx,1); diff --git a/plugins/WebUi/templates/deluge/part_refresh.html b/plugins/WebUi/templates/deluge/part_refresh.html deleted file mode 100644 index 29a33755b..000000000 --- a/plugins/WebUi/templates/deluge/part_refresh.html +++ /dev/null @@ -1,13 +0,0 @@ -
-
-$_('Auto refresh:') -$if getcookie('auto_refresh') == '1': - ($getcookie('auto_refresh_secs')) $_('seconds'))   - $:render.part_button('GET', '/refresh/set', _('Set'), 'tango/preferences-system.png') - $:render.part_button('POST', '/refresh/off', _('Disable'), 'tango/process-stop.png') -$else: - $_('Off')   - $:render.part_button('POST', '/refresh/on', _('Enable'), 'tango/view-refresh.png') -$#end -
-
diff --git a/plugins/WebUi/version b/plugins/WebUi/version deleted file mode 100644 index a5afaff28..000000000 --- a/plugins/WebUi/version +++ /dev/null @@ -1,5 +0,0 @@ -revision-id: mvoncken@gmail.com-20070930083408-sv8mo0mi1rbjnfvk -date: 2007-12-05 15:10:08 +0200 -build-date: 2007-12-05 15:34:50 +0200 -revno: 165 -branch-nick: WebUi diff --git a/plugins/WebUi/webserver_common.py b/plugins/WebUi/webserver_common.py index e55fadcaa..61e65e4c0 100644 --- a/plugins/WebUi/webserver_common.py +++ b/plugins/WebUi/webserver_common.py @@ -31,8 +31,8 @@ """ initializes config,render and proxy. -contains all hacks to support running in process0.5 ,run inside-gtk0.5 and - run in process0.6 +All hacks go here, so this is a really ugly source-file.. +Support running in process0.5 ,run inside-gtk0.5 and run in process0.6 """ import os @@ -41,7 +41,7 @@ import random import pickle import sys import base64 -from webpy022 import template +from lib.webpy022 import template random.seed() webui_path = os.path.dirname(__file__) @@ -163,7 +163,8 @@ def init_gtk_05(): def init_logger(): #only for 0.5.. import logging - logging.basicConfig(level=logging.DEBUG,format="[%(levelname)-8s] %(module)s:%(lineno)d %(message)s") + logging.basicConfig(level=logging.DEBUG, + format="[%(levelname)s] %(message)s") globals()['log'] = logging diff --git a/plugins/WebUi/webserver_framework.py b/plugins/WebUi/webserver_framework.py index e285c1a3a..e4c23858c 100644 --- a/plugins/WebUi/webserver_framework.py +++ b/plugins/WebUi/webserver_framework.py @@ -40,13 +40,13 @@ Todo's before stable: -clear finished? -torrent files. """ -import webpy022 as web +import lib.webpy022 as web -from webpy022.webapi import cookies, setcookie as w_setcookie -from webpy022.http import seeother, url -from webpy022 import template,changequery as self_url -from webpy022.utils import Storage -from static_handler import static_handler +from lib.webpy022.webapi import cookies, setcookie as w_setcookie +from lib.webpy022.http import seeother, url +from lib.webpy022 import template,changequery as self_url +from lib.webpy022.utils import Storage +from lib.static_handler import static_handler from deluge.common import fsize,fspeed @@ -144,7 +144,8 @@ def check_session(func): return func if session is valid, else redirect to login page. """ def deco(self, name = None): - log.debug('%s.%s(name=%s)' % (self.__class__.__name__,func.__name__,name)) + log.debug('%s.%s(name=%s)' % (self.__class__.__name__, func.__name__, + name)) vars = web.input(redir_after_login = None) ck = cookies() if ck.has_key("session_id") and ck["session_id"] in ws.SESSIONS: @@ -282,6 +283,7 @@ def filter_torrent_state(torrent_list,filter_name): ,'queued':lambda t: (t.paused and not t.user_paused) ,'paused':lambda t: (t.user_paused) ,'seeding':lambda t:(t.is_seed and not t.paused ) + ,'active':lambda t: (t.download_rate > 0 or t.upload_rate > 0) } filter_func = filters[filter_name] return [t for t in torrent_list if filter_func(t)] @@ -300,7 +302,8 @@ def category_tabs(torrent_list): (_('Downloading'),'downloading') , (_('Queued'),'queued') , (_('Paused'),'paused') , - (_('Seeding'),'seeding') + (_('Seeding'),'seeding'), + (_('Active'),'active') ]: title += ' (%s)' % ( len(filter_torrent_state(torrent_list, filter_name)), ) @@ -349,6 +352,17 @@ def template_part_stats(): def get_config(var): return ws.config.get(var) +irow = 0 +def altrow(reset = False): + global irow + if reset: + irow = 1 + return + irow +=1 + irow = irow % 2 + return "altrow%s" % irow + + template.Template.globals.update({ 'sort_head': template_sort_head, 'part_stats':template_part_stats, @@ -357,6 +371,7 @@ template.Template.globals.update({ '_': _ , #gettext/translations 'str': str, #because % in templetor is broken. 'sorted': sorted, + 'altrow':altrow, 'get_config': get_config, 'self_url': self_url, 'fspeed': common.fspeed, @@ -370,9 +385,9 @@ template.Template.globals.update({ #/template-defs def create_webserver(urls, methods): - from webpy022.request import webpyfunc - from webpy022 import webapi - from gtk_cherrypy_wsgiserver import CherryPyWSGIServer + from lib.webpy022.request import webpyfunc + from lib.webpy022 import webapi + from lib.gtk_cherrypy_wsgiserver import CherryPyWSGIServer import os func = webapi.wsgifunc(webpyfunc(urls, methods, False))