sync-wrapper for new async client

This commit is contained in:
Martijn Voncken 2008-01-21 17:57:38 +00:00
parent 762f8a52af
commit 217d7eaa90
7 changed files with 129 additions and 12 deletions

View File

@ -134,3 +134,23 @@ class Plugins(config.Form):
raise forms.ValidationError("SAVE:TODO")
config.register_block('deluge','plugins', Plugins)
class Queue(config.Form):
title = _("Queue")
info = _("queue-cfg not finished")
queue_top = config.CheckBox(_("Queue new torrents to top"))
total_active = config.DelugeInt(_("Total active torrents"))
total_seeding = config.DelugeInt(_("Total active seeding"))
total_downloading = config.DelugeInt(_("Total active downloading"))
queue_bottom = config.CheckBox(_("Queue completed torrents to bottom"))
stop_on_ratio = config.CheckBox(_("Stop seeding when ratio reaches"))
stop_ratio = config.DelugeInt(_("TODO:float-edit-box"))
remove_after_stop = config.CheckBox(_("Remve torrent when ratio reached"))
def save(self, value):
raise forms.ValidationError("SAVE:TODO")
config.register_block('plugins','queue', Queue)

View File

@ -55,9 +55,16 @@ class Template(config.WebCfgForm):
class Server(config.WebCfgForm):
title = _("Server")
try:
import OpenSSL
except ImportError:
info = _("pyopenssl not installed, install this for https.")
port = forms.IntegerField(label = _("Port"),min_value=80)
use_https = config.CheckBox(_("Use https"))
def post_save(self):
pass
#raise forms.ValidationError(

View File

@ -1,15 +1,42 @@
"""
pretty debug errors
(part of web.py)
adapted for deluge-webui:
-edit-box with traceback for cut+paste.
-pretty errors for well known exceptions.
web.py :
adapted from Django <djangoproject.com>
Copyright (c) 2005, the Lawrence Journal-World
Used under the modified BSD license:
http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
"""
__all__ = ["debugerror", "djangoerror"]
import utils
print utils
print dir(utils)
pretty_errors_str = {
"org.freedesktop.DBus.Error.ServiceUnknown":
""" Webui Lost the connection to deluge <br \>
Unable to reconnect, please restart deluge.
<!--<a href="/kill">click here to stop the webui</a>-->""",
"InvalidUniqueIDError:":
"""
this torrent was removed,
<a href="/home">click here to go to the torrent-list</a>
"""
}
pretty_errors_cls = {
type(utils.UnknownTorrentError):"""
this torrent was removed,
<a href="/home">click here to go to the torrent-list</a>
"""
}
import sys, urlparse, pprint
from lib.webpy022.net import websafe
from lib.webpy022.template import Template
@ -299,6 +326,16 @@ def djangoerror():
exception_message = 'no message'
exception_type = exception_type.__name__
"""
for err_str in pretty_errors:
if err_str in exception_message:
#from render import render
return render.error(pretty_errors[err_str])
"""
if exception_type in pretty_errors_cls:
from render import render
return render.error(pretty_errors_cls[exception_type])
version_info = (
"WebUi : rev." + ws.REVNO
+ "Python : " + str(sys.version)

View File

@ -39,6 +39,10 @@ import config_tabs_webui #auto registers
import config_tabs_deluge #auto registers
from config import config_page
#import forms
#
from debugerror import deluge_debugerror
web.webapi.internalerror = deluge_debugerror
#
import lib.webpy022 as web
from lib.webpy022.http import seeother, url

View File

@ -1,6 +1,15 @@
$def with (torrent_list, all_torrents)
$:render.header(_('Torrent list'))
<script language="javascript">
/*for select_all shortcut/button*/
var all_torrents = [
$for t in torrent_list:
"$t.id",
]
</script>
<div class="panel" id="toolbar">
<a class='toolbar_btn' href="#"
@ -45,7 +54,6 @@ $:render.header(_('Torrent list'))
</div>
<div id="tableContainer" class="tableContainer">
<table class="torrent_list" border=0 cellspacing=0 cellpadding=2 id="torrent_list">
<thead class="fixedHeader">
@ -142,6 +150,6 @@ $:part_stats()
</form>
$:render.footer()

View File

@ -48,10 +48,7 @@ from urlparse import urlparse
from webserver_common import REVNO, VERSION, TORRENT_KEYS, STATE_MESSAGES
from webserver_common import ws
from debugerror import deluge_debugerror
#init:
web.webapi.internalerror = deluge_debugerror
debug_unicode = False
#methods:
@ -146,6 +143,10 @@ def get_torrent_status(torrent_id):
ws.log.warning('torrent_status:None key in status:%s' % key)
if status.tracker == 0:
#0.6 does not raise a decent error on non-existing torrent.
raise UnknownTorrentError(torrent_id)
status["id"] = torrent_id
url = urlparse(status.tracker)
@ -253,3 +254,10 @@ def get_category_choosers(torrent_list):
#/utils
class WebUiError(Exception):
"""the message of these exceptions will be rendered in
render.error(e.message) in debugerror.py"""
pass
class UnknownTorrentError(WebUiError):
pass

View File

@ -108,6 +108,36 @@ CONFIG_DEFAULTS = {
#/constants
class SyncProxyFunction():
"""
helper class for SyncProxy
"""
def __init__(self,client, func_name):
self.func_name = func_name
self.client = client
def __call__(self,*args,**kwargs):
sync_result = []
def callback( result):
sync_result.append(result)
func = getattr(self.client,self.func_name)
func(callback,*args)
self.client.force_call(block=True)
return sync_result[0]
class SyncProxy(object):
"""acts like the old synchonous proxy"""
def __init__(self, client):
self.client = client
def __getattr__(self, attr,*args,**kwargs):
return SyncProxyFunction(self.client, attr)
class Ws:
"""
singleton
@ -141,11 +171,15 @@ class Ws:
self.config = pickle.load(open(self.config_file))
def init_06(self, uri = 'http://localhost:58846'):
import deluge.ui.client as proxy
import deluge.ui.client as async_proxy
from deluge.log import LOG as log
self.log = log
proxy.set_core_uri(uri)
self.proxy = proxy
async_proxy.set_core_uri(uri)
self.async_proxy = async_proxy
self.proxy = SyncProxy(self.async_proxy)
#MONKEY PATCH, TODO->REMOVE!!!
def add_torrent_filecontent(name , data_b64):
@ -174,7 +208,6 @@ class Ws:
f.close()
self.init_process()
self.proxy = proxy
self.env = '0.6'
def init_05(self):