mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-09 01:48:40 +00:00
url-routing using PageManager
This commit is contained in:
parent
ace62ef0b7
commit
1f3932e13f
6 changed files with 58 additions and 82 deletions
|
@ -41,9 +41,9 @@ import sys
|
||||||
import os
|
import os
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
from deluge import component
|
from deluge import component
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
config = ConfigManager("webui.conf")
|
config = ConfigManager("webui.conf")
|
||||||
config_page_manager = component.get("ConfigPageManager")
|
config_page_manager = component.get("ConfigPageManager")
|
||||||
|
|
||||||
|
@ -114,3 +114,7 @@ class config_page:
|
||||||
|
|
||||||
def render(self, f , name , message = '' , error=''):
|
def render(self, f , name , message = '' , error=''):
|
||||||
return render.config(config_page_manager.groups, config_page_manager.blocks, f, name , message , error)
|
return render.config(config_page_manager.groups, config_page_manager.blocks, f, name , message , error)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
component.get("PageManager").register_page("/config/(.*)", config_page)
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,11 @@ import register_menu
|
||||||
import torrent_add
|
import torrent_add
|
||||||
import torrent_options
|
import torrent_options
|
||||||
import torrent_move
|
import torrent_move
|
||||||
|
import config_forms
|
||||||
|
torrent_add.register()
|
||||||
|
torrent_options.register()
|
||||||
|
torrent_move.register()
|
||||||
|
config_forms.register()
|
||||||
#/self registering pages.
|
#/self registering pages.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,7 @@
|
||||||
from utils import *
|
from utils import *
|
||||||
import utils #todo remove the line above.
|
import utils #todo remove the line above.
|
||||||
from render import render, error_page
|
from render import render, error_page
|
||||||
import time
|
|
||||||
import page_decorators as deco
|
import page_decorators as deco
|
||||||
from config_forms import config_page
|
|
||||||
|
|
||||||
from deluge.common import get_pixmap
|
from deluge.common import get_pixmap
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
@ -54,48 +52,12 @@ from deluge import component
|
||||||
from deluge.ui.client import sclient as proxy
|
from deluge.ui.client import sclient as proxy
|
||||||
|
|
||||||
page_manager = component.get("PageManager")
|
page_manager = component.get("PageManager")
|
||||||
|
def route(url, klass):
|
||||||
#from json_api import json_api #secuity leak, todo:fix
|
"""
|
||||||
|
url-mapping is using page_manager
|
||||||
#routing:
|
not the default web.py way ; I want class decorators!
|
||||||
urls = [
|
"""
|
||||||
"/login", "login",
|
page_manager.register_page(url, klass)
|
||||||
"/index", "index",
|
|
||||||
"/torrent/info/(.*)", "torrent_info",
|
|
||||||
"/torrent/info_inner/(.*)", "torrent_info_inner",
|
|
||||||
"/torrent/stop/(.*)", "torrent_stop",
|
|
||||||
"/torrent/start/(.*)", "torrent_start",
|
|
||||||
"/torrent/reannounce/(.*)", "torrent_reannounce",
|
|
||||||
"/torrent/recheck/(.*)", "torrent_recheck",
|
|
||||||
"/torrent/delete/(.*)", "torrent_delete",
|
|
||||||
"/torrent/queue/up/(.*)", "torrent_queue_up",
|
|
||||||
"/torrent/queue/down/(.*)", "torrent_queue_down",
|
|
||||||
"/torrent/files/(.*)","torrent_files",
|
|
||||||
"/pause_all", "pause_all",
|
|
||||||
"/resume_all", "resume_all",
|
|
||||||
"/refresh/set", "refresh_set",
|
|
||||||
"/refresh/(.*)", "refresh",
|
|
||||||
"/config/(.*)", "config_page",
|
|
||||||
"/home", "home",
|
|
||||||
"/about", "about",
|
|
||||||
"/logout", "logout",
|
|
||||||
"/connect","connect",
|
|
||||||
"/daemon/control/(.*)","daemon_control",
|
|
||||||
#remote-api:
|
|
||||||
"/remote/torrent/add(.*)", "remote_torrent_add",
|
|
||||||
#"/json/(.*)","json_api",
|
|
||||||
#static:
|
|
||||||
"/static/(.*)", "static",
|
|
||||||
"/template/static/(.*)", "template_static",
|
|
||||||
#"/downloads/(.*)","downloads" disabled until it can handle large downloads
|
|
||||||
#default-pages
|
|
||||||
"/", "home",
|
|
||||||
"", "home",
|
|
||||||
"/robots.txt","robots",
|
|
||||||
"/template_style.css","template_style",
|
|
||||||
"/pixmaps/(.*)","pixmaps"
|
|
||||||
]
|
|
||||||
#/routing
|
|
||||||
|
|
||||||
#pages:
|
#pages:
|
||||||
class login:
|
class login:
|
||||||
|
@ -115,6 +77,7 @@ class login:
|
||||||
seeother(url('/login', error=1, redir=vars.redir))
|
seeother(url('/login', error=1, redir=vars.redir))
|
||||||
else:
|
else:
|
||||||
seeother('/login?error=1')
|
seeother('/login?error=1')
|
||||||
|
route('/login',login)
|
||||||
|
|
||||||
class index:
|
class index:
|
||||||
"page containing the torrent list."
|
"page containing the torrent list."
|
||||||
|
@ -157,24 +120,25 @@ class index:
|
||||||
setcookie("order", vars.order)
|
setcookie("order", vars.order)
|
||||||
setcookie("sort", vars.sort)
|
setcookie("sort", vars.sort)
|
||||||
return render.index(torrent_list, organize_filters)
|
return render.index(torrent_list, organize_filters)
|
||||||
|
route('/index',index)
|
||||||
|
|
||||||
#simple proxy's to deluge.ui.client
|
#simple proxy's to deluge.ui.client
|
||||||
#execute a command on torrent(s) and redirect to index page.
|
#execute a command on torrent(s) and redirect to index page.
|
||||||
def torrents_command(command):
|
def reg_torrents_POST(url_name, proxy_command):
|
||||||
class torrents_command_inner:
|
class _page_class:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
@deco.torrent_ids
|
@deco.torrent_ids
|
||||||
def POST(self, torrent_ids):
|
def POST(self, torrent_ids):
|
||||||
getattr(proxy, command)(torrent_ids)
|
getattr(proxy, proxy_command)(torrent_ids)
|
||||||
do_redirect()
|
do_redirect()
|
||||||
return torrents_command_inner
|
route("/torrent/%s/(.*)" % url_name, _page_class)
|
||||||
|
|
||||||
torrent_start = torrents_command("resume_torrent")
|
reg_torrents_POST("start", "resume_torrent")
|
||||||
torrent_stop = torrents_command("pause_torrent")
|
reg_torrents_POST("stop", "pause_torrent")
|
||||||
torrent_reannounce = torrents_command("force_reannounce")
|
reg_torrents_POST("recheck", "force_recheck")
|
||||||
torrent_recheck = torrents_command("force_recheck")
|
reg_torrents_POST("reannounce", "force_reannounce")
|
||||||
torrent_queue_down = torrents_command("queue_down")
|
reg_torrents_POST("queue/up", "queue_up")
|
||||||
torrent_queue_up = torrents_command("queue_up")
|
reg_torrents_POST("queue/down", "queue_down")
|
||||||
|
|
||||||
class torrent_info:
|
class torrent_info:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
|
@ -182,6 +146,7 @@ class torrent_info:
|
||||||
@deco.torrent
|
@deco.torrent
|
||||||
def GET(self, torrent):
|
def GET(self, torrent):
|
||||||
return render.torrent_info(torrent)
|
return render.torrent_info(torrent)
|
||||||
|
route("/torrent/info/(.*)", torrent_info)
|
||||||
|
|
||||||
class torrent_info_inner:
|
class torrent_info_inner:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
|
@ -194,6 +159,7 @@ class torrent_info_inner:
|
||||||
active_tab = getcookie("torrent_info_tab") or "details"
|
active_tab = getcookie("torrent_info_tab") or "details"
|
||||||
setcookie("torrent_info_tab", active_tab)
|
setcookie("torrent_info_tab", active_tab)
|
||||||
return render.torrent_info_inner(torrent, active_tab)
|
return render.torrent_info_inner(torrent, active_tab)
|
||||||
|
route("/torrent/info_inner/(.*)", torrent_info_inner)
|
||||||
|
|
||||||
class torrent_delete:
|
class torrent_delete:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
|
@ -211,6 +177,7 @@ class torrent_delete:
|
||||||
torrent_also = bool(vars.torrent_also)
|
torrent_also = bool(vars.torrent_also)
|
||||||
proxy.remove_torrent(torrent_ids, torrent_also, data_also)
|
proxy.remove_torrent(torrent_ids, torrent_also, data_also)
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route("/torrent/delete/(.*)",torrent_delete)
|
||||||
|
|
||||||
class torrent_files:
|
class torrent_files:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
|
@ -222,21 +189,23 @@ class torrent_files:
|
||||||
proxy_prio = [0 for x in xrange(len(torrent.file_priorities))]
|
proxy_prio = [0 for x in xrange(len(torrent.file_priorities))]
|
||||||
for pos in file_priorities:
|
for pos in file_priorities:
|
||||||
proxy_prio[int(pos)] = 1
|
proxy_prio[int(pos)] = 1
|
||||||
|
|
||||||
proxy.set_torrent_file_priorities(torrent_id, proxy_prio)
|
proxy.set_torrent_file_priorities(torrent_id, proxy_prio)
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route("/torrent/files/(.*)", torrent_files)
|
||||||
|
|
||||||
class pause_all:
|
class pause_all:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
def POST(self, name):
|
def POST(self, name):
|
||||||
proxy.pause_torrent(proxy.get_session_state())
|
proxy.pause_torrent(proxy.get_session_state())
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route("/pause_all", pause_all)
|
||||||
|
|
||||||
class resume_all:
|
class resume_all:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
def POST(self, name):
|
def POST(self, name):
|
||||||
proxy.resume_torrent(proxy.get_session_state())
|
proxy.resume_torrent(proxy.get_session_state())
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route("/resume_all", resume_all)
|
||||||
|
|
||||||
class refresh:
|
class refresh:
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
|
@ -250,6 +219,7 @@ class refresh:
|
||||||
if not getcookie('auto_refresh_secs'):
|
if not getcookie('auto_refresh_secs'):
|
||||||
setcookie('auto_refresh_secs', 10)
|
setcookie('auto_refresh_secs', 10)
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route("/refresh/(.*)", refresh)
|
||||||
|
|
||||||
class refresh_set:
|
class refresh_set:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
|
@ -266,16 +236,20 @@ class refresh_set:
|
||||||
do_redirect()
|
do_redirect()
|
||||||
else:
|
else:
|
||||||
error_page(_('refresh must be > 0'))
|
error_page(_('refresh must be > 0'))
|
||||||
|
route("/refresh/set", refresh_set)
|
||||||
|
|
||||||
class home:
|
class home:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route('/home', home)
|
||||||
|
route('/', home)
|
||||||
|
|
||||||
class about:
|
class about:
|
||||||
@deco.deluge_page_noauth
|
@deco.deluge_page_noauth
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
return render.about()
|
return render.about()
|
||||||
|
route('/about', about)
|
||||||
|
|
||||||
class logout:
|
class logout:
|
||||||
def GET(self):
|
def GET(self):
|
||||||
|
@ -285,6 +259,7 @@ class logout:
|
||||||
def POST(self, name):
|
def POST(self, name):
|
||||||
end_session()
|
end_session()
|
||||||
seeother('/login')
|
seeother('/login')
|
||||||
|
route('/logout', logout)
|
||||||
|
|
||||||
class connect:
|
class connect:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
|
@ -311,6 +286,7 @@ class connect:
|
||||||
#TODO: more error-handling
|
#TODO: more error-handling
|
||||||
utils.daemon_connect(uri)
|
utils.daemon_connect(uri)
|
||||||
do_redirect()
|
do_redirect()
|
||||||
|
route('/connect', connect)
|
||||||
|
|
||||||
class daemon_control:
|
class daemon_control:
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
|
@ -330,16 +306,15 @@ class daemon_control:
|
||||||
seeother('/connect')
|
seeother('/connect')
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
import time
|
||||||
uri = web.input(uri = None).uri
|
uri = web.input(uri = None).uri
|
||||||
if not uri:
|
if not uri:
|
||||||
uri = 'http://localhost:58846'
|
uri = 'http://localhost:58846'
|
||||||
|
|
||||||
port = int(uri.split(':')[2])
|
port = int(uri.split(':')[2])
|
||||||
utils.daemon_start_localhost(port)
|
utils.daemon_start_localhost(port)
|
||||||
time.sleep(1) #pause a while to let it start?
|
time.sleep(1) #pause a while to let it start?
|
||||||
|
|
||||||
utils.daemon_connect( uri )
|
utils.daemon_connect( uri )
|
||||||
|
route("/daemon/control/(.*)", daemon_control)
|
||||||
|
|
||||||
#other stuff:
|
#other stuff:
|
||||||
class remote_torrent_add:
|
class remote_torrent_add:
|
||||||
|
@ -364,33 +339,31 @@ class remote_torrent_add:
|
||||||
torrent_name = vars.torrent.filename
|
torrent_name = vars.torrent.filename
|
||||||
proxy.add_torrent_filecontent(torrent_name, data_b64)
|
proxy.add_torrent_filecontent(torrent_name, data_b64)
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
route("/remote/torrent/add(.*)", remote_torrent_add)
|
||||||
|
|
||||||
class static(static_handler):
|
class static(static_handler):
|
||||||
base_dir = os.path.join(os.path.dirname(__file__), 'static')
|
base_dir = os.path.join(os.path.dirname(__file__), 'static')
|
||||||
|
route("/static/(.*)", static)
|
||||||
|
|
||||||
class template_static(static_handler):
|
class template_static(static_handler):
|
||||||
def get_base_dir(self):
|
def get_base_dir(self):
|
||||||
return os.path.join(os.path.dirname(__file__),
|
return os.path.join(os.path.dirname(__file__),
|
||||||
'templates/%s/static' % ws.config.get('template'))
|
'templates/%s/static' % ws.config.get('template'))
|
||||||
|
route("/template/static/(.*)", template_static)
|
||||||
class downloads(static_handler):
|
|
||||||
def GET(self, name):
|
|
||||||
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)
|
|
||||||
|
|
||||||
class robots:
|
class robots:
|
||||||
def GET(self):
|
def GET(self):
|
||||||
"no robots/prevent searchengines from indexing"
|
"no robots/prevent searchengines from indexing"
|
||||||
web.header("Content-Type", "text/plain")
|
web.header("Content-Type", "text/plain")
|
||||||
print "User-agent: *\nDisallow:/\n"
|
print "User-agent: *\nDisallow:/\n"
|
||||||
|
route("/robots.txt", robots)
|
||||||
|
|
||||||
class template_style:
|
class template_style:
|
||||||
def GET(self):
|
def GET(self):
|
||||||
web.header("Content-Type", "text/css")
|
web.header("Content-Type", "text/css")
|
||||||
style = Storage()
|
style = Storage()
|
||||||
print render.template_style(style)
|
print render.template_style(style)
|
||||||
|
route("/template_style.css", template_style)
|
||||||
|
|
||||||
class pixmaps:
|
class pixmaps:
|
||||||
"use the deluge-images. located in data/pixmaps"
|
"use the deluge-images. located in data/pixmaps"
|
||||||
|
@ -413,6 +386,4 @@ class pixmaps:
|
||||||
web.header("Content-Length", str(fs[6]))
|
web.header("Content-Length", str(fs[6]))
|
||||||
web.header("Cache-Control" , "public, must-revalidate, max-age=86400")
|
web.header("Cache-Control" , "public, must-revalidate, max-age=86400")
|
||||||
print content
|
print content
|
||||||
#/pages
|
route("/pixmaps/(.*)", pixmaps)
|
||||||
|
|
||||||
page_manager.register_pages(urls,globals())
|
|
||||||
|
|
|
@ -39,8 +39,6 @@ import page_decorators as deco
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
import web
|
import web
|
||||||
|
|
||||||
page_manager = component.get("PageManager")
|
|
||||||
|
|
||||||
class OptionsForm(forms.Form):
|
class OptionsForm(forms.Form):
|
||||||
download_location = forms.ServerFolder(_("Download Location"))
|
download_location = forms.ServerFolder(_("Download Location"))
|
||||||
compact_allocation = forms.CheckBox(_("Compact Allocation"))
|
compact_allocation = forms.CheckBox(_("Compact Allocation"))
|
||||||
|
@ -131,4 +129,5 @@ class torrent_add:
|
||||||
print self.add_page(error = _("No data"))
|
print self.add_page(error = _("No data"))
|
||||||
return
|
return
|
||||||
|
|
||||||
page_manager.register_page("/torrent/add/(.*)",torrent_add)
|
def register():
|
||||||
|
component.get("PageManager").register_page("/torrent/add/(.*)",torrent_add)
|
|
@ -39,8 +39,6 @@ from render import render
|
||||||
import page_decorators as deco
|
import page_decorators as deco
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
|
||||||
page_manager = component.get("PageManager")
|
|
||||||
|
|
||||||
#Too much boilerplate code here, todo : fix it.
|
#Too much boilerplate code here, todo : fix it.
|
||||||
|
|
||||||
class MoveForm(forms.Form):
|
class MoveForm(forms.Form):
|
||||||
|
@ -77,4 +75,5 @@ class torrent_move:
|
||||||
proxy.move_torrent(torrent_ids, save_path)
|
proxy.move_torrent(torrent_ids, save_path)
|
||||||
utils.do_redirect()
|
utils.do_redirect()
|
||||||
|
|
||||||
page_manager.register_page("/torrent/move/(.*)",torrent_move)
|
def register():
|
||||||
|
component.get("PageManager").register_page("/torrent/move/(.*)",torrent_move)
|
||||||
|
|
|
@ -29,16 +29,13 @@
|
||||||
# this exception statement from your version. If you delete this exception
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
#
|
#
|
||||||
from deluge.ui.client import sclient as proxy
|
from deluge.ui.client import sclient
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge import component
|
from deluge import component
|
||||||
|
|
||||||
from render import template
|
|
||||||
import page_decorators as deco
|
import page_decorators as deco
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
|
||||||
page_manager = component.get("PageManager")
|
|
||||||
|
|
||||||
class TorrentOptionsForm(forms.Form):
|
class TorrentOptionsForm(forms.Form):
|
||||||
#download
|
#download
|
||||||
max_download_speed = forms.DelugeFloat(
|
max_download_speed = forms.DelugeFloat(
|
||||||
|
@ -58,6 +55,7 @@ class torrent_options:
|
||||||
def POST(self, torrent):
|
def POST(self, torrent):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
template.Template.globals["forms"].torrent_options = lambda torrent : TorrentOptionsForm(torrent)
|
def register():
|
||||||
|
from render import template
|
||||||
page_manager.register_page("/torrent/options/(.*)",torrent_options)
|
template.Template.globals["forms"].torrent_options = lambda torrent : TorrentOptionsForm(torrent)
|
||||||
|
component.get("PageManager").register_page("/torrent/options/(.*)", torrent_options)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue