Update create_plugin.py script

This commit is contained in:
Andrew Resch 2009-02-24 00:00:35 +00:00
parent 703e9def05
commit 4a6ecde07b
3 changed files with 33 additions and 76 deletions

View File

@ -22,7 +22,6 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
from deluge.log import LOG as log
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase
class CorePlugin(PluginInitBase): class CorePlugin(PluginInitBase):

View File

@ -26,6 +26,7 @@
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.ui.client import client from deluge.ui.client import client
from deluge import component from deluge import component
from deluge.plugins.pluginbase import WebPluginBase
class WebUI(WebPluginBase): class WebUI(WebPluginBase):
def enable(self): def enable(self):

View File

@ -92,66 +92,50 @@ def create_plugin():
CORE = """ CORE = """
import deluge
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.plugins.corepluginbase import CorePluginBase from deluge.plugins.pluginbase import CorePluginBase
from deluge import component import deluge.component as component
#from deluge.plugins.coreclient import client #1.1 and later only import deluge.configmanager
#client: see http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi from deluge.core.rpcserver import export
DEFAULT_PREFS = { DEFAULT_PREFS = {
"test":"NiNiNi" "test":"NiNiNi"
} }
class Core(CorePluginBase): class Core(CorePluginBase):
def enable(self): def enable(self):
self.config = deluge.configmanager.ConfigManager("%(safe_name)s.conf", DEFAULT_PREFS) self.config = deluge.configmanager.ConfigManager("%(safe_name)s.conf", DEFAULT_PREFS)
def disable(self): def disable(self):
pass pass
def export_set_config(self, config): def update(self):
pass
@export()
def set_config(self, config):
"sets the config dictionary" "sets the config dictionary"
for key in config.keys(): for key in config.keys():
self.config[key] = config[key] self.config[key] = config[key]
self.config.save() self.config.save()
def export_get_config(self): @export()
def get_config(self):
"returns the config dictionary" "returns the config dictionary"
return self.config.config return self.config.config
""" """
INIT = """ INIT = """
from deluge.log import LOG as log from deluge.plugins.init import PluginInitBase
from deluge.plugins.init import PluginBase class CorePlugin(PluginInitBase):
from core import Core as _plugin_cls
class CorePlugin(PluginBase): class GtkUIPlugin(PluginInitBase):
def __init__(self, plugin_api, plugin_name): from gtkui import GtkUI as _plugin_cls
# Load the Core portion of the plugin
try:
from core import Core
self.plugin = Core(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a Core plugin: %%s", e)
class WebUIPlugin(PluginBase): class WebUIPlugin(PluginInitBase):
def __init__(self, plugin_api, plugin_name): from webui import WebUI as _plugin_cls
try:
from webui import WebUI
self.plugin = WebUI(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a WebUI plugin: %%s", e)
class GtkUIPlugin(PluginBase):
def __init__(self, plugin_api, plugin_name):
# Load the GtkUI portion of the plugin
try:
from gtkui import GtkUI
self.plugin = GtkUI(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a GtkUI plugin: %%s", e)
""" """
@ -193,15 +177,15 @@ setup(
""" """
GTKUI = """ GTKUI = """
from deluge.log import LOG as log
from deluge.ui.client import aclient
import gtk import gtk
class GtkUI(object): from deluge.log import LOG as log
def __init__(self, plugin_api, plugin_name): from deluge.ui.client import client
log.debug("Calling %(name)s UI init") from deluge.plugins.pluginbase import GtkPluginBase
self.plugin = plugin_api import deluge.component as component
import deluge.common
class GtkUI(GtkPluginBase):
def enable(self): def enable(self):
self.glade = gtk.glade.XML(self.get_resource("config.glade")) self.glade = gtk.glade.XML(self.get_resource("config.glade"))
@ -220,10 +204,10 @@ class GtkUI(object):
config = { config = {
"test":self.glade.get_widget("txt_test").get_text() "test":self.glade.get_widget("txt_test").get_text()
} }
aclient.%(safe_name)s_set_config(None, config) client.%(safe_name)s.set_config(config)
def on_show_prefs(self): def on_show_prefs(self):
aclient.%(safe_name)s_get_config(self.cb_get_config) client.%(safe_name)s.get_config().addCallback(self.cb_get_config)
def cb_get_config(self, config): def cb_get_config(self, config):
"callback for on show_prefs" "callback for on show_prefs"
@ -264,44 +248,17 @@ GLADE = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
""" """
WEBUI = """ WEBUI = """
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 client
from deluge.plugins.webuipluginbase import WebUIPluginBase
from deluge import component from deluge import component
from deluge.plugins.pluginbase import WebPluginBase
api = component.get("WebPluginApi") class WebUI(WebPluginBase):
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): def enable(self):
api.config_page_manager.register('plugins', '%(safe_name)s' ,ConfigForm) pass
def disable(self): def disable(self):
api.config_page_manager.deregister('%(safe_name)s') pass
class ConfigForm(forms.Form):
#meta:
title = _("%(name)s")
#load/save:
def initial_data(self):
return sclient.%(safe_name)s_get_config()
def save(self, data):
cfg = dict(data)
sclient.%(safe_name)s_set_config(cfg)
#django newforms magic: define config fields:
test = forms.CharField(label=_("Test config value"))
""" """
DEFAULT_HTML = """$def with (value1, value2) DEFAULT_HTML = """$def with (value1, value2)
@ -323,7 +280,7 @@ GPL = """#
# #
# Basic plugin template created by: # Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com> # Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # Deluge is free software.
# #