From f55fdcf1188da287422b6ef92b468b8a24359439 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Tue, 18 Mar 2008 20:33:04 +0000 Subject: [PATCH] blocklist-plugin config pt1 --- .../plugins/blocklist/blocklist/__init__.py | 20 +++- deluge/plugins/blocklist/blocklist/webui.py | 91 +++++++++++++++++++ deluge/plugins/blocklist/setup.py | 6 +- 3 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 deluge/plugins/blocklist/blocklist/webui.py diff --git a/deluge/plugins/blocklist/blocklist/__init__.py b/deluge/plugins/blocklist/blocklist/__init__.py index db3e19d50..3baa6ea7e 100644 --- a/deluge/plugins/blocklist/blocklist/__init__.py +++ b/deluge/plugins/blocklist/blocklist/__init__.py @@ -4,19 +4,19 @@ # Copyright (C) 2007 Andrew Resch ('andar') # Copyright (C) 2008 Mark Stahler ('kramed') -# +# # 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 2 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., @@ -48,9 +48,19 @@ class CorePlugin(PluginBase): class GtkUIPlugin(PluginBase): def __init__(self, plugin_api, plugin_name): - # Load the GtkUI portion of the plugin + # 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) + +class WebUIPlugin(PluginBase): + def __init__(self, plugin_api, plugin_name): + # Load the GtkUI portion of the plugin + 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) + diff --git a/deluge/plugins/blocklist/blocklist/webui.py b/deluge/plugins/blocklist/blocklist/webui.py new file mode 100644 index 000000000..09c98779c --- /dev/null +++ b/deluge/plugins/blocklist/blocklist/webui.py @@ -0,0 +1,91 @@ +# +# blocklist/webui.py +# +# Copyright (C) 2008 Martijn Voncken + +# +# 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 2 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. + +import os +from deluge.log import LOG as log +from deluge.ui.client import sclient +from deluge import component +import ui + +import deluge.ui.webui.lib.newforms_plus as forms + +config_page_manager = component.get("ConfigPageManager") + +FORMAT_LIST = [ + ('gzmule',_("Emule IP list (GZip)")), + ('spzip',_("SafePeer Text (Zipped)")), + ('pgtext',_("PeerGuardian Text (Uncompressed)")), + ('p2bgz',_("PeerGuardian P2B (GZip)")) +] + +class BlockListCfgForm(forms.Form): + """ + a config form based on django forms. + see webui.lib.newforms_plus, config_forms, etc. + """ + #meta: + title = _("BlockList") + + #load/save: + def initial_data(self): + return sclient.block_list_get_options() + + def save(self, data): + sclient.block_list_set_options(dict(data)) + + #input fields : + listtype = forms.ChoiceField(FORMAT_LIST) + url = forms.URLField(label=_("Url")) + check_after_days = forms.IntegerField(label=_("Check for a blocklist every (days)"), min_value=-1, max_value=14) + timeout = forms.IntegerField(label=_("Timeout (seconds)"), min_value=15, max_value=360) + try_times = forms.IntegerField(label=_("Times to attemptdownload of new list"), min_value=1, max_value=5) + load_on_start = forms.CheckBox(_('Import blocklist on daemon startup')) + +class WebUI(ui.UI): + def __init__(self, plugin_api, plugin_name): + log.debug("Calling UI init") + # Call UI constructor + ui.UI.__init__(self, plugin_api, plugin_name) + log.debug("Blocklist WebUI plugin initalized..") + + def enable(self): + config_page_manager.register('plugins','blocklist',BlockListCfgForm) + + def disable(self): + config_page_manager.unregister('blocklist') + + + + + diff --git a/deluge/plugins/blocklist/setup.py b/deluge/plugins/blocklist/setup.py index bebce4d0f..c17541615 100644 --- a/deluge/plugins/blocklist/setup.py +++ b/deluge/plugins/blocklist/setup.py @@ -8,12 +8,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. -# +# # This program 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 this program. If not, write to: # The Free Software Foundation, Inc., @@ -50,5 +50,7 @@ setup( Blocklist = blocklist:CorePlugin [deluge.plugin.gtkui] Blocklist = blocklist:GtkUIPlugin + [deluge.plugin.webui] + Blocklist = blocklist:WebUIPlugin """ )