update create_plugin
This commit is contained in:
parent
bb7c5cb4af
commit
8a00b046d5
|
@ -38,16 +38,6 @@ 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:
|
||||||
"""
|
"""
|
||||||
convenience class, you don't have to use this, but it does make things easyer to setup.
|
convenience class, you don't have to use this, but it does make things easyer to setup.
|
||||||
|
@ -69,6 +59,7 @@ class WebUIPluginBase:
|
||||||
resource = clean_plugin_name
|
resource = clean_plugin_name
|
||||||
base_path = "data"
|
base_path = "data"
|
||||||
|
|
||||||
|
#use as : api.render.plugin-name.template-name[excluding.html](parameters)
|
||||||
setattr(api.render, clean_plugin_name, api.egg_render(clean_plugin_name, "template"))
|
setattr(api.render, clean_plugin_name, api.egg_render(clean_plugin_name, "template"))
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Creates an empty plugin and links it from ~/.config/deluge/plugins
|
Creates an empty plugin and links it from ~/.config/deluge/plugins
|
||||||
This plugin includes the framework for using the preferences dialog
|
This plugin includes the framework for using the preferences dialog
|
||||||
|
|
||||||
Example:
|
example:
|
||||||
python create_plugin.py --name MyPlugin2 --basepath . --author-name "Your Name" --author-email "yourname@example.com"
|
python create_plugin.py --name MyPlugin2 --basepath . --author-name "Your Name" --author-email "yourname@example.com"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -41,6 +41,7 @@ def create_plugin():
|
||||||
safe_name = name.lower()
|
safe_name = name.lower()
|
||||||
plugin_base = os.path.realpath(os.path.join(options.path, name))
|
plugin_base = os.path.realpath(os.path.join(options.path, name))
|
||||||
src = os.path.join(plugin_base, safe_name)
|
src = os.path.join(plugin_base, safe_name)
|
||||||
|
template_dir = os.path.join(src,"template")
|
||||||
|
|
||||||
if os.path.exists(plugin_base):
|
if os.path.exists(plugin_base):
|
||||||
print "the directory %s already exists, delete it first" % plugin_base
|
print "the directory %s already exists, delete it first" % plugin_base
|
||||||
|
@ -66,7 +67,7 @@ def create_plugin():
|
||||||
os.mkdir(plugin_base)
|
os.mkdir(plugin_base)
|
||||||
os.mkdir(src)
|
os.mkdir(src)
|
||||||
os.mkdir(os.path.join(src,"data"))
|
os.mkdir(os.path.join(src,"data"))
|
||||||
os.mkdir(os.path.join(src,"template"))
|
os.mkdir(template_dir)
|
||||||
|
|
||||||
print "creating files.."
|
print "creating files.."
|
||||||
write_file(plugin_base,"setup.py", SETUP)
|
write_file(plugin_base,"setup.py", SETUP)
|
||||||
|
@ -75,6 +76,7 @@ def create_plugin():
|
||||||
write_file(src,"webui.py", WEBUI)
|
write_file(src,"webui.py", WEBUI)
|
||||||
write_file(src,"core.py", CORE)
|
write_file(src,"core.py", CORE)
|
||||||
write_file(os.path.join(src,"data"),"config.glade", GLADE)
|
write_file(os.path.join(src,"data"),"config.glade", GLADE)
|
||||||
|
write_file(template_dir,"default.html", DEFAULT_HTML)
|
||||||
|
|
||||||
#add an input parameter for this?
|
#add an input parameter for this?
|
||||||
print "building dev-link.."
|
print "building dev-link.."
|
||||||
|
@ -246,11 +248,27 @@ WEBUI = """
|
||||||
import os
|
import os
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge.ui.client import sclient, aclient
|
from deluge.ui.client import sclient, aclient
|
||||||
|
from deluge.plugins.webuipluginbase import WebUIPluginBase
|
||||||
from deluge import component
|
from deluge import component
|
||||||
|
|
||||||
api = component.get("WebPluginApi")
|
api = component.get("WebPluginApi")
|
||||||
forms = api.forms
|
forms = api.forms
|
||||||
|
|
||||||
|
class %(safe_name)s_page:
|
||||||
|
@api.deco.deluge_page
|
||||||
|
def GET(self, args):
|
||||||
|
return api.render.%(safe_name)s.default("parameter1", "parameter2") #push data to templates/default.html
|
||||||
|
|
||||||
|
class WebUI(WebUIPluginBase):
|
||||||
|
#map url's to classes: [(url,class), ..]
|
||||||
|
urls = [('/%(safe_name)s/example', %(safe_name)s_page)]
|
||||||
|
|
||||||
|
def enable(self):
|
||||||
|
api.config_page_manager.register('plugins', '%(safe_name)s' ,ConfigForm)
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
api.config_page_manager.unregister('%(safe_name)s')
|
||||||
|
|
||||||
class ConfigForm(forms.Form):
|
class ConfigForm(forms.Form):
|
||||||
#meta:
|
#meta:
|
||||||
title = _("%(name)s")
|
title = _("%(name)s")
|
||||||
|
@ -265,18 +283,18 @@ class ConfigForm(forms.Form):
|
||||||
|
|
||||||
#django newforms magic: define config fields:
|
#django newforms magic: define config fields:
|
||||||
test = forms.CharField(label=_("Test config value"))
|
test = forms.CharField(label=_("Test config value"))
|
||||||
|
"""
|
||||||
|
|
||||||
|
DEFAULT_HTML = """$def with (value1, value2)
|
||||||
class WebUI(object):
|
$:render.header(_("Demo1"), '')
|
||||||
def __init__(self, plugin_api, plugin_name):
|
<div class="panel">
|
||||||
log.debug("%(name)s plugin initalized..")
|
<h2>Demo:%(name)s</h2>
|
||||||
self.plugin = plugin_api
|
<pre>
|
||||||
|
$value1
|
||||||
def enable(self):
|
$value2
|
||||||
api.config_page_manager.register('plugins','%(safe_name)s',ConfigForm)
|
</pre>'
|
||||||
|
</div>
|
||||||
def disable(self):
|
$:render.footer()
|
||||||
api.config_page_manager.unregister('%(safe_name)s')
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GPL = """#
|
GPL = """#
|
||||||
|
@ -314,7 +332,6 @@ GPL = """#
|
||||||
# exception, you may extend this exception to your version of the file(s),
|
# 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
|
# 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
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CREATE_DEV_LINK = """#!/bin/bash
|
CREATE_DEV_LINK = """#!/bin/bash
|
||||||
|
|
Loading…
Reference in New Issue