Get blocklist plugin working
This commit is contained in:
parent
fa77f8403a
commit
9b05ec8b5f
|
@ -1,9 +1,8 @@
|
|||
#
|
||||
# blocklist/__init__.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2008 Mark Stahler ('kramed') <markstahler@gmail.com>
|
||||
|
||||
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
|
@ -24,36 +23,13 @@
|
|||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
from deluge.plugins.init import PluginInitBase
|
||||
|
||||
class CorePlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
# Load the Core portion of the plugin
|
||||
try:
|
||||
from core import Core
|
||||
self.plugin = Core(plugin_name)
|
||||
except Exception, e:
|
||||
log.error("Failed to load core plugin %s!", plugin_name)
|
||||
log.exception(e)
|
||||
from core import Core as _plugin_cls
|
||||
|
||||
class GtkUIPlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
# Load the GtkUI portion of the plugin
|
||||
try:
|
||||
from gtkui import GtkUI
|
||||
self.plugin = GtkUI(plugin_name)
|
||||
except Exception, e:
|
||||
log.error("Failed to load gtkui plugin %s!", plugin_name)
|
||||
log.exception(e)
|
||||
from gtkui import GtkUI as _plugin_cls
|
||||
|
||||
class WebUIPlugin(PluginInitBase):
|
||||
def __init__(self, plugin_name):
|
||||
# Load the WebUI portion of the plugin
|
||||
try:
|
||||
from webui import WebUI
|
||||
self.plugin = WebUI(plugin_name)
|
||||
except Exception, e:
|
||||
log.error("Failed to load webui plugin %s!", plugin_name)
|
||||
log.exception(e)
|
||||
from webui import WebUI as _plugin_cls
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# ui.py
|
||||
# common.py
|
||||
#
|
||||
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
|
@ -26,15 +26,5 @@
|
|||
import pkg_resources
|
||||
import os.path
|
||||
|
||||
class UI:
|
||||
def __init__(self, plugin_api, plugin_name):
|
||||
self.plugin = plugin_api
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def disable(self):
|
||||
pass
|
||||
|
||||
def get_resource(self, filename):
|
||||
def get_resource(filename):
|
||||
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
|
@ -32,7 +32,7 @@ import time
|
|||
import shutil
|
||||
|
||||
from deluge.log import LOG as log
|
||||
from deluge.plugins.corepluginbase import CorePluginBase
|
||||
from deluge.plugins.pluginbase import CorePluginBase
|
||||
import deluge.component as component
|
||||
import deluge.configmanager
|
||||
from deluge.core.rpcserver import export
|
||||
|
@ -94,29 +94,29 @@ class Core(CorePluginBase):
|
|||
pass
|
||||
|
||||
## Exported RPC methods ###
|
||||
@export
|
||||
@export()
|
||||
def download_list(self, _import=False):
|
||||
"""Download the blocklist specified in the config as url"""
|
||||
self.download_blocklist(_import)
|
||||
|
||||
@export
|
||||
@export()
|
||||
def import_list(self, force=False):
|
||||
"""Import the blocklist from the blocklist.cache, if load is True, then
|
||||
it will download the blocklist file if needed."""
|
||||
threading.Thread(target=self.import_blocklist, kwargs={"force": force}).start()
|
||||
|
||||
@export
|
||||
@export()
|
||||
def get_config(self):
|
||||
"""Returns the config dictionary"""
|
||||
return self.config.config
|
||||
|
||||
@export
|
||||
@export()
|
||||
def set_config(self, config):
|
||||
"""Sets the config based on values in 'config'"""
|
||||
for key in config.keys():
|
||||
self.config[key] = config[key]
|
||||
|
||||
@export
|
||||
@export()
|
||||
def get_status(self):
|
||||
"""Returns the status of the plugin."""
|
||||
status = {}
|
||||
|
|
|
@ -25,21 +25,23 @@
|
|||
import gtk
|
||||
|
||||
from deluge.log import LOG as log
|
||||
from deluge.ui.client import aclient as client
|
||||
from deluge.ui.client import client
|
||||
import deluge.component as component
|
||||
import deluge.common
|
||||
from deluge.plugins.pluginbase import GtkPluginBase
|
||||
import common
|
||||
|
||||
import ui
|
||||
from core import FORMATS
|
||||
|
||||
class GtkUI(ui.UI):
|
||||
class GtkUI(GtkPluginBase):
|
||||
def enable(self):
|
||||
log.debug("Blocklist GtkUI enable..")
|
||||
self.plugin = component.get("PluginManager")
|
||||
|
||||
self.load_preferences_page()
|
||||
|
||||
self.status_item = component.get("StatusBar").add_item(
|
||||
image=self.get_resource("blocklist16.png"),
|
||||
image=common.get_resource("blocklist16.png"),
|
||||
text="",
|
||||
callback=self._on_status_item_clicked,
|
||||
tooltip="Blocked IP Ranges")
|
||||
|
@ -114,7 +116,7 @@ class GtkUI(ui.UI):
|
|||
self.glade.get_widget("label_url").set_text(
|
||||
status["file_url"])
|
||||
|
||||
client.blocklist.get_status(_on_get_status)
|
||||
client.blocklist.get_status().addCallback(_on_get_status)
|
||||
|
||||
def _on_show_prefs(self):
|
||||
def _on_get_config(config):
|
||||
|
@ -132,7 +134,7 @@ class GtkUI(ui.UI):
|
|||
self.glade.get_widget("chk_import_on_start").set_active(
|
||||
config["load_on_start"])
|
||||
|
||||
client.blocklist.get_config(_on_get_config)
|
||||
client.blocklist.get_config().addCallback(_on_get_config)
|
||||
|
||||
def _on_apply_prefs(self):
|
||||
config = {}
|
||||
|
@ -141,15 +143,15 @@ class GtkUI(ui.UI):
|
|||
config["url"] = self.glade.get_widget("entry_url").get_text()
|
||||
config["check_after_days"] = self.glade.get_widget("spin_check_days").get_value_as_int()
|
||||
config["load_on_start"] = self.glade.get_widget("chk_import_on_start").get_active()
|
||||
client.blocklist.set_config(None, config)
|
||||
client.blocklist.set_config(config)
|
||||
|
||||
def _on_button_check_download_clicked(self, widget):
|
||||
self._on_apply_prefs()
|
||||
client.blocklist.import_list(None, False)
|
||||
client.blocklist.import_list(False)
|
||||
|
||||
def _on_button_force_download_clicked(self, widget):
|
||||
self._on_apply_prefs()
|
||||
client.blocklist.import_list(None, True)
|
||||
client.blocklist.import_list(True)
|
||||
|
||||
def _on_status_item_clicked(self, widget, event):
|
||||
component.get("Preferences").show("Blocklist")
|
||||
|
@ -157,7 +159,7 @@ class GtkUI(ui.UI):
|
|||
def load_preferences_page(self):
|
||||
"""Initializes the preferences page and adds it to the preferences dialog"""
|
||||
# Load the preferences page
|
||||
self.glade = gtk.glade.XML(self.get_resource("blocklist_pref.glade"))
|
||||
self.glade = gtk.glade.XML(common.get_resource("blocklist_pref.glade"))
|
||||
|
||||
self.progress_bar = self.glade.get_widget("progressbar")
|
||||
self.table_info = self.glade.get_widget("table_info")
|
||||
|
@ -187,10 +189,10 @@ class GtkUI(ui.UI):
|
|||
|
||||
# Set button icons
|
||||
self.glade.get_widget("image_download").set_from_file(
|
||||
self.get_resource("blocklist_download24.png"))
|
||||
common.get_resource("blocklist_download24.png"))
|
||||
|
||||
self.glade.get_widget("image_import").set_from_file(
|
||||
self.get_resource("blocklist_import24.png"))
|
||||
common.get_resource("blocklist_import24.png"))
|
||||
|
||||
# Update the preferences page with config values from the core
|
||||
self._on_show_prefs()
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
|
||||
import os
|
||||
from deluge.log import LOG as log
|
||||
from deluge.ui.client import sclient, aclient
|
||||
from deluge.ui.client import client
|
||||
from deluge import component
|
||||
import ui
|
||||
from deluge.plugins.pluginbase import WebPluginBase
|
||||
|
||||
import deluge.ui.webui.lib.newforms_plus as forms
|
||||
#import deluge.ui.webui.lib.newforms_plus as forms
|
||||
|
||||
config_page_manager = component.get("ConfigPageManager")
|
||||
#config_page_manager = component.get("ConfigPageManager")
|
||||
|
||||
FORMAT_LIST = [
|
||||
('gzmule',_("Emule IP list (GZip)")),
|
||||
|
@ -41,68 +41,11 @@ FORMAT_LIST = [
|
|||
('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):
|
||||
data = sclient.blocklist.get_config()
|
||||
return data
|
||||
|
||||
def save(self, data):
|
||||
cfg = dict(data)
|
||||
del cfg["btn_import_now"]
|
||||
del cfg["btn_force_download"]
|
||||
sclient.blocklist.set_config(cfg)
|
||||
if data.btn_import_now:
|
||||
sclient.blocklist.import_list(data.btn_force_download)
|
||||
|
||||
#input fields :
|
||||
listtype = forms.ChoiceField(FORMAT_LIST)
|
||||
url = forms.CharField(label=_("Url"))
|
||||
check_after_days = forms.IntegerField(label=_("Check for 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 attempt download"), min_value=1, max_value=5)
|
||||
load_on_start = forms.CheckBox(_('Import on daemon startup'))
|
||||
|
||||
btn_import_now = forms.CheckBox(_('Import Now'))
|
||||
btn_force_download = forms.CheckBox(_('Force Download'))
|
||||
|
||||
def post_html(self):
|
||||
"show blocklist status"
|
||||
status = sclient.blocklist.get_status()
|
||||
|
||||
if status["state"] == "Downloading":
|
||||
txt = _("Downloading %.2f%%") % (status["file_progress"] * 100)
|
||||
elif status["state"] == "Importing":
|
||||
txt = _("Importing %s") % str(status["num_blocked"])
|
||||
elif status["state"] == "Idle":
|
||||
txt = _("Blocked Ranges: %s") % str(status["num_blocked"])
|
||||
else:
|
||||
txt = _("Inactive")
|
||||
|
||||
return """
|
||||
<h3>Status</h3>
|
||||
<div class="info">
|
||||
%s<br><form method="GET"><input type="submit" value="%s"></form>
|
||||
</div>
|
||||
""" % (txt, _("Refresh status"))
|
||||
|
||||
|
||||
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..")
|
||||
|
||||
class WebUI(WebPluginBase):
|
||||
def enable(self):
|
||||
config_page_manager.register('plugins','blocklist',BlockListCfgForm)
|
||||
#config_page_manager.register('plugins','blocklist',BlockListCfgForm)
|
||||
pass
|
||||
|
||||
def disable(self):
|
||||
config_page_manager.deregister('blocklist')
|
||||
#config_page_manager.deregister('blocklist')
|
||||
pass
|
||||
|
|
|
@ -38,13 +38,16 @@ class CorePluginBase(PluginBase):
|
|||
# Register RPC methods
|
||||
component.get("RPCServer").register_object(self, plugin_name.lower())
|
||||
log.debug("CorePlugin initialized..")
|
||||
component.start("CorePlugin." + plugin_name)
|
||||
|
||||
class GtkPluginBase(PluginBase):
|
||||
def __init__(self, plugin_name):
|
||||
component.Component.__init__(self, "GtkPlugin." + plugin_name)
|
||||
log.debug("GtkPlugin initialized..")
|
||||
component.start("GtkPlugin." + plugin_name)
|
||||
|
||||
class WebPluginBase(PluginBase):
|
||||
def __init__(self, plugin_name):
|
||||
component.Component.__init__(self, "WebPlugin." + plugin_name)
|
||||
log.debug("WebPlugin initialized..")
|
||||
component.start("WebPlugin." + plugin_name)
|
||||
|
|
Loading…
Reference in New Issue