mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
egg_render for templates files in plugin/templates (#497)
This commit is contained in:
parent
a870101dbe
commit
bb7c5cb4af
@ -38,35 +38,39 @@ import os
|
|||||||
api = component.get("WebPluginApi")
|
api = component.get("WebPluginApi")
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
def plugin_render_template(*args , **kwargs):
|
||||||
|
return "plugin-render"
|
||||||
|
|
||||||
|
class plugin_render():
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return plugin_render_template
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class WebUIPluginBase:
|
class WebUIPluginBase:
|
||||||
"""
|
"""
|
||||||
/data is automatically served on http as as /plugin-name/data
|
convenience class, you don't have to use this, but it does make things easyer to setup.
|
||||||
templates /template are added to api.render
|
* static files: /data is automatically served on http as as /safe-plugin-name/data
|
||||||
|
* templates: /template are added to api.render.plugin-name.
|
||||||
|
* pages: urls attribute registers pages : urls = [(url, class), ..]
|
||||||
"""
|
"""
|
||||||
|
urls= []
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_api, plugin_name):
|
||||||
log.debug("%s plugin initalized.." % plugin_name)
|
log.debug("%s plugin : start initalize.." % plugin_name)
|
||||||
self.plugin = plugin_api
|
self.plugin = plugin_api
|
||||||
self.plugin_name = plugin_name
|
self.plugin_name = plugin_name
|
||||||
clean_plugin_name = plugin_name.lower().replace(" ","_")
|
clean_plugin_name = plugin_name.lower().replace(" ","_")
|
||||||
|
|
||||||
|
for url , klass in self.urls:
|
||||||
|
api.page_manager.register_page(url, klass)
|
||||||
|
|
||||||
class egg_data_static(api.egg_handler): #serves files in /data from egg
|
class egg_data_static(api.egg_handler): #serves files in /data from egg
|
||||||
resource = clean_plugin_name
|
resource = clean_plugin_name
|
||||||
base_path = "data"
|
base_path = "data"
|
||||||
|
|
||||||
template_dir = os.path.join(os.path.dirname(__file__),"template")
|
setattr(api.render, clean_plugin_name, api.egg_render(clean_plugin_name, "template"))
|
||||||
api.render.register_template_path(template_dir)
|
|
||||||
api.page_manager.register_page("/%s/data/(.*)" % clean_plugin_name , egg_data_static)
|
api.page_manager.register_page("/%s/data/(.*)" % clean_plugin_name , egg_data_static)
|
||||||
|
|
||||||
log.debug("%s plugin : end base initalize." % plugin_name)
|
log.debug("%s plugin : end initalize.." % plugin_name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,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 lib.egg_handler import egg_handler
|
||||||
|
from lib.egg_render import egg_render
|
||||||
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
|
||||||
@ -188,6 +189,7 @@ class PluginApi(component.Component):
|
|||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
|
||||||
self.egg_handler = egg_handler
|
self.egg_handler = egg_handler
|
||||||
|
self.egg_render = egg_render
|
||||||
self.render = render
|
self.render = render
|
||||||
self.web = web
|
self.web = web
|
||||||
self.deco = deco
|
self.deco = deco
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
"""
|
"""
|
||||||
static fileserving for web.py
|
static fileserving for web.py
|
||||||
without the need for wsgi wrapper magic.
|
serves 1 directory from a packed egg, using pkg_resourses
|
||||||
"""
|
"""
|
||||||
import web
|
import web
|
||||||
from web import url
|
from web import url
|
||||||
@ -20,11 +20,6 @@ from StringIO import StringIO
|
|||||||
mimetypes.init() # try to read system mime.types
|
mimetypes.init() # try to read system mime.types
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
"""
|
|
||||||
def get_resource(self, filename):
|
|
||||||
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
|
||||||
|
|
||||||
"""
|
|
||||||
class egg_handler:
|
class egg_handler:
|
||||||
"""
|
"""
|
||||||
serves files directly from an egg
|
serves files directly from an egg
|
||||||
@ -60,7 +55,6 @@ if __name__ == '__main__':
|
|||||||
resource = "label"
|
resource = "label"
|
||||||
base_path = "data"
|
base_path = "data"
|
||||||
|
|
||||||
base_dir = os.path.expanduser('~')
|
|
||||||
urls = ('/relative/(.*)','static_handler',
|
urls = ('/relative/(.*)','static_handler',
|
||||||
'/(.*)','usr_static')
|
'/(.*)','usr_static')
|
||||||
|
|
||||||
|
34
deluge/ui/webui/lib/egg_render.py
Normal file
34
deluge/ui/webui/lib/egg_render.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#(c) Martijn Voncken, mvoncken@gmail.com
|
||||||
|
#Same Licence as python 2.5
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
render object for web.py
|
||||||
|
renders from egg instead of directory.
|
||||||
|
"""
|
||||||
|
from web import template
|
||||||
|
import pkg_resources
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class egg_render:
|
||||||
|
"""
|
||||||
|
templates directly from an egg
|
||||||
|
"""
|
||||||
|
def __init__(self, resource, base_path , cache=False):
|
||||||
|
self.resource = resource
|
||||||
|
self.base_path = base_path
|
||||||
|
self.cache = cache
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
filename = attr + ".html" #<--bug, not consistent with the web.py renderer, that renderer ignores extensions.
|
||||||
|
template_data = pkg_resources.resource_string(self.resource, os.path.join(self.base_path, filename))
|
||||||
|
c = template.Template(template_data, filename = filename)
|
||||||
|
if self.cache:
|
||||||
|
setattr(self, attr, c)
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#example:
|
||||||
|
pass
|
Loading…
x
Reference in New Issue
Block a user