egg_handler for static files in plugin/data (#497)
This commit is contained in:
parent
ffb2de165d
commit
a870101dbe
|
@ -4,6 +4,8 @@ Deluge 1.1.0 - "" (In Development)
|
||||||
* Implement #296 ability to change peer TOS byte
|
* Implement #296 ability to change peer TOS byte
|
||||||
* Add per-torrent move on completed settings
|
* Add per-torrent move on completed settings
|
||||||
* Implement #414 use async save_resume_data method
|
* Implement #414 use async save_resume_data method
|
||||||
|
* FilterManager with torrent filtering in get_torrents_status , for sidebar and plugins.
|
||||||
|
|
||||||
|
|
||||||
GtkUI:
|
GtkUI:
|
||||||
* Add peer progress to the peers tab
|
* Add peer progress to the peers tab
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#
|
||||||
|
# webuipluginbase.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2008 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# Deluge is free software.
|
||||||
|
#
|
||||||
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License, as published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# deluge 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 deluge. 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.
|
||||||
|
|
||||||
|
|
||||||
|
from deluge.log import LOG as log
|
||||||
|
from deluge import component
|
||||||
|
import os
|
||||||
|
api = component.get("WebPluginApi")
|
||||||
|
|
||||||
|
|
||||||
|
class WebUIPluginBase:
|
||||||
|
"""
|
||||||
|
/data is automatically served on http as as /plugin-name/data
|
||||||
|
templates /template are added to api.render
|
||||||
|
"""
|
||||||
|
def __init__(self, plugin_api, plugin_name):
|
||||||
|
log.debug("%s plugin initalized.." % plugin_name)
|
||||||
|
self.plugin = plugin_api
|
||||||
|
self.plugin_name = plugin_name
|
||||||
|
clean_plugin_name = plugin_name.lower().replace(" ","_")
|
||||||
|
|
||||||
|
class egg_data_static(api.egg_handler): #serves files in /data from egg
|
||||||
|
resource = clean_plugin_name
|
||||||
|
base_path = "data"
|
||||||
|
|
||||||
|
template_dir = os.path.join(os.path.dirname(__file__),"template")
|
||||||
|
api.render.register_template_path(template_dir)
|
||||||
|
api.page_manager.register_page("/%s/data/(.*)" % clean_plugin_name , egg_data_static)
|
||||||
|
|
||||||
|
log.debug("%s plugin : end base initalize." % plugin_name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ sclient.set_core_uri()
|
||||||
print "\n\n"
|
print "\n\n"
|
||||||
|
|
||||||
|
|
||||||
if False: #aclient non-core
|
if 0: #aclient non-core
|
||||||
methods = sorted([m for m in dir(aclient) if not m.startswith('_')
|
methods = sorted([m for m in dir(aclient) if not m.startswith('_')
|
||||||
if not m in ['add_torrent_file', 'has_callback', 'get_method',
|
if not m in ['add_torrent_file', 'has_callback', 'get_method',
|
||||||
'methodHelp','methodSignature','list_methods','add_torrent_file_binary']])
|
'methodHelp','methodSignature','list_methods','add_torrent_file_binary']])
|
||||||
|
@ -30,7 +30,7 @@ if False: #aclient non-core
|
||||||
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
||||||
print("%s" % pydoc.getdoc(func))
|
print("%s" % pydoc.getdoc(func))
|
||||||
|
|
||||||
if 0: #baseclient/core
|
if 1: #baseclient/core
|
||||||
methods = sorted([m for m in dir(Core) if m.startswith("export")]
|
methods = sorted([m for m in dir(Core) if m.startswith("export")]
|
||||||
+ ['export_add_torrent_file_binary'] #HACK
|
+ ['export_add_torrent_file_binary'] #HACK
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ if 0: #baseclient/core
|
||||||
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
||||||
print("{{{\n%s\n}}}" % pydoc.getdoc(func))
|
print("{{{\n%s\n}}}" % pydoc.getdoc(func))
|
||||||
|
|
||||||
if False: #plugin-manager
|
if 0: #plugin-manager
|
||||||
import WebUi
|
import WebUi
|
||||||
from WebUi.pluginmanager import PluginManager
|
from WebUi.pluginmanager import PluginManager
|
||||||
|
|
||||||
|
@ -63,13 +63,13 @@ if False: #plugin-manager
|
||||||
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
print("\n'''%s(%s): '''\n" %(method_name, ", ".join(params)))
|
||||||
print("%s" % pydoc.getdoc(func))
|
print("%s" % pydoc.getdoc(func))
|
||||||
|
|
||||||
if 1: #possible config-values
|
if 0: #possible config-values
|
||||||
print "=== config-values ==="
|
print "=== config-values ==="
|
||||||
cfg = sclient.get_config()
|
cfg = sclient.get_config()
|
||||||
for key in sorted(cfg.keys()):
|
for key in sorted(cfg.keys()):
|
||||||
print "%s:%s()" % (key, type(cfg[key]).__name__)
|
print "%s:%s()" % (key, type(cfg[key]).__name__)
|
||||||
|
|
||||||
if False: #keys
|
if 0: #keys
|
||||||
print """== Notes ==
|
print """== Notes ==
|
||||||
* The available keys for get_torrent_status(id, keys)
|
* The available keys for get_torrent_status(id, keys)
|
||||||
{{{
|
{{{
|
||||||
|
|
|
@ -47,6 +47,7 @@ manager = component.get("ClassName")
|
||||||
"""
|
"""
|
||||||
from deluge import component
|
from deluge import component
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
from lib.egg_handler import egg_handler
|
||||||
from deluge.ui.client import aclient
|
from deluge.ui.client import aclient
|
||||||
from deluge import component, pluginmanagerbase
|
from deluge import component, pluginmanagerbase
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
@ -186,6 +187,7 @@ class PluginApi(component.Component):
|
||||||
import utils
|
import utils
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
|
||||||
|
self.egg_handler = egg_handler
|
||||||
self.render = render
|
self.render = render
|
||||||
self.web = web
|
self.web = web
|
||||||
self.deco = deco
|
self.deco = deco
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#(c) Martijn Voncken, mvoncken@gmail.com
|
||||||
|
#Same Licence as python 2.5
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
static fileserving for web.py
|
||||||
|
without the need for wsgi wrapper magic.
|
||||||
|
"""
|
||||||
|
import web
|
||||||
|
from web import url
|
||||||
|
|
||||||
|
import posixpath
|
||||||
|
import urlparse
|
||||||
|
import urllib
|
||||||
|
import mimetypes
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import cgi
|
||||||
|
from StringIO import StringIO
|
||||||
|
mimetypes.init() # try to read system mime.types
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
"""
|
||||||
|
def get_resource(self, filename):
|
||||||
|
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
||||||
|
|
||||||
|
"""
|
||||||
|
class egg_handler:
|
||||||
|
"""
|
||||||
|
serves files directly from an egg
|
||||||
|
"""
|
||||||
|
resource = "label"
|
||||||
|
base_path = "data"
|
||||||
|
extensions_map = mimetypes.types_map
|
||||||
|
|
||||||
|
def GET(self, path):
|
||||||
|
path = os.path.join(self.base_path, path)
|
||||||
|
ctype = self.guess_type(path)
|
||||||
|
|
||||||
|
data = pkg_resources.resource_string(self.resource,path)
|
||||||
|
|
||||||
|
web.header("Content-type", ctype)
|
||||||
|
web.header("Cache-Control" , "public, must-revalidate, max-age=86400")
|
||||||
|
#web.lastmodified(datetime.datetime.fromtimestamp(fs.st_mtime))
|
||||||
|
print data
|
||||||
|
|
||||||
|
def guess_type(self, path):
|
||||||
|
base, ext = posixpath.splitext(path)
|
||||||
|
if ext in self.extensions_map:
|
||||||
|
return self.extensions_map[ext]
|
||||||
|
ext = ext.lower()
|
||||||
|
if ext in self.extensions_map:
|
||||||
|
return self.extensions_map[ext]
|
||||||
|
else:
|
||||||
|
return 'application/octet-stream'
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#example:
|
||||||
|
class usr_static(egg_handler):
|
||||||
|
resource = "label"
|
||||||
|
base_path = "data"
|
||||||
|
|
||||||
|
base_dir = os.path.expanduser('~')
|
||||||
|
urls = ('/relative/(.*)','static_handler',
|
||||||
|
'/(.*)','usr_static')
|
||||||
|
|
||||||
|
web.run(urls,globals())
|
Loading…
Reference in New Issue