Add testing plugin.
Plugins should now enable/disable properly and save enabled/disabled state.
This commit is contained in:
parent
5d3275de01
commit
c11e61355b
|
@ -375,9 +375,11 @@ class Core(
|
|||
|
||||
def export_enable_plugin(self, plugin):
|
||||
self.plugins.enable_plugin(plugin)
|
||||
|
||||
return None
|
||||
|
||||
def export_disable_plugin(self, plugin):
|
||||
self.plugins.disable_plugin(plugin)
|
||||
return None
|
||||
|
||||
# Signals
|
||||
def torrent_added(self, torrent_id):
|
||||
|
|
|
@ -90,34 +90,38 @@ class PluginManagerBase:
|
|||
|
||||
self.available_plugins = []
|
||||
for name in self.pkg_env:
|
||||
pkg_name = str(self.pkg_env[name][0]).split()[0]
|
||||
pkg_name = str(self.pkg_env[name][0]).split()[0].replace("-", " ")
|
||||
pkg_version = str(self.pkg_env[name][0]).split()[1]
|
||||
|
||||
log.debug("Found plugin: %s %s", pkg_name, pkg_version)
|
||||
self.available_plugins.append(pkg_name)
|
||||
|
||||
def enable_plugin(self, name):
|
||||
def enable_plugin(self, plugin_name):
|
||||
"""Enables a plugin"""
|
||||
if name not in self.available_plugins:
|
||||
if plugin_name not in self.available_plugins:
|
||||
log.warning("Cannot enable non-existant plugin %s", name)
|
||||
return
|
||||
|
||||
egg = self.pkg_env[name][0]
|
||||
|
||||
plugin_name = plugin_name.replace(" ", "-")
|
||||
egg = self.pkg_env[plugin_name][0]
|
||||
egg.activate()
|
||||
for name in egg.get_entry_map(self.entry_name):
|
||||
entry_point = egg.get_entry_info(self.entry_name, name)
|
||||
cls = entry_point.load()
|
||||
instance = cls(self)
|
||||
self.plugins[name] = instance
|
||||
log.info("Plugin %s enabled..", name)
|
||||
plugin_name = plugin_name.replace("-", " ")
|
||||
self.plugins[plugin_name] = instance
|
||||
if plugin_name not in self.config["enabled_plugins"]:
|
||||
self.config["enabled_plugins"].append(plugin_name)
|
||||
log.info("Plugin %s enabled..", plugin_name)
|
||||
|
||||
def disable_plugin(self, name):
|
||||
"""Disables a plugin"""
|
||||
|
||||
self.plugins[name].disable()
|
||||
|
||||
del self.plugins[name]
|
||||
# except:
|
||||
# log.warning("Unable to disable non-existant plugin %s", name)
|
||||
|
||||
try:
|
||||
del self.plugins[name]
|
||||
self.config["enabled_plugins"].remove(plugin_name)
|
||||
except KeyError:
|
||||
log.warning("Plugin %s is not enabled..", name)
|
||||
|
||||
log.info("Plugin %s disabled..", name)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class PluginBase:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
def disable(self):
|
||||
pass
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
# setup.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
# This program is free software; you can 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, 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.,
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Test plugin
|
||||
"""
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
__author__ = "Andrew Resch"
|
||||
|
||||
setup(
|
||||
name="Test Plugin",
|
||||
version="1.0",
|
||||
description=__doc__,
|
||||
author=__author__,
|
||||
packages=["testp"],
|
||||
package_data = {"testp": ["glade/*.glade"]},
|
||||
entry_points="""
|
||||
[deluge.plugin.core]
|
||||
Testp = testp:CorePlugin
|
||||
[deluge.plugin.gtkui]
|
||||
Testp = testp:GtkUIPlugin
|
||||
"""
|
||||
)
|
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# __init__.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
from deluge.plugins.init import PluginBase
|
||||
|
||||
class CorePlugin(PluginBase):
|
||||
def __init__(self, plugin_manager):
|
||||
# Load the Core portion of the plugin
|
||||
try:
|
||||
from core import Core
|
||||
self.core = Core()
|
||||
except:
|
||||
pass
|
||||
|
||||
class GtkUIPlugin(PluginBase):
|
||||
def __init__(self, plugin_manager):
|
||||
# Load the GtkUI portion of the plugin
|
||||
try:
|
||||
from gtkui import GtkUI
|
||||
self.gtkui = GtkUI()
|
||||
except:
|
||||
pass
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# core.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class Core:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def disable(self):
|
||||
pass
|
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# gtkui.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
from deluge.log import LOG as log
|
||||
import ui
|
||||
|
||||
class GtkUI(ui.UI):
|
||||
def __init__(self):
|
||||
ui.UI.__init__(self)
|
||||
log.debug("gtkui plugin initialized..")
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# ui.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class UI:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def disable(self):
|
||||
pass
|
|
@ -217,6 +217,10 @@ def get_torrent_status(torrent_id, keys):
|
|||
except (AttributeError, socket.error):
|
||||
set_core_uri(None)
|
||||
return {}
|
||||
|
||||
if status == None:
|
||||
return {}
|
||||
|
||||
return pickle.loads(status.data)
|
||||
|
||||
def get_session_state():
|
||||
|
@ -301,17 +305,15 @@ def get_num_connections():
|
|||
|
||||
def enable_plugin(plugin):
|
||||
try:
|
||||
return get_core().enable_plugin(plugin)
|
||||
get_core().enable_plugin(plugin)
|
||||
except (AttributeError, socket.error):
|
||||
set_core_uri(None)
|
||||
return
|
||||
|
||||
def disable_plugin(plugin):
|
||||
try:
|
||||
return get_core().disable_plugin(plugin)
|
||||
get_core().disable_plugin(plugin)
|
||||
except (AttributeError, socket.error):
|
||||
set_core_uri(None)
|
||||
return
|
||||
|
||||
def open_url_in_browser(url):
|
||||
"""Opens link in the desktop's default browser"""
|
||||
|
|
|
@ -121,7 +121,7 @@ class GtkUI:
|
|||
self.signal_receiver = Signals()
|
||||
|
||||
# Initalize the plugins
|
||||
self.plugins = PluginManager(self)
|
||||
self.plugins = PluginManager()
|
||||
|
||||
# Show the connection manager
|
||||
self.connectionmanager = ConnectionManager()
|
||||
|
|
|
@ -37,17 +37,11 @@ import deluge.ui.client as client
|
|||
from deluge.configmanager import ConfigManager
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
|
||||
def __init__(self, gtkui):
|
||||
|
||||
class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||
component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, "PluginManager")
|
||||
self.config = ConfigManager("gtkui.conf")
|
||||
self._gtkui = gtkui
|
||||
|
||||
# Register a callback with the client
|
||||
client.connect_on_new_core(self.start)
|
||||
|
||||
deluge.pluginmanagerbase.PluginManagerBase.__init__(
|
||||
self, "gtkui.conf", "deluge.plugin.gtkui")
|
||||
|
||||
def start(self):
|
||||
"""Start the plugin manager"""
|
||||
|
@ -58,29 +52,24 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
|
|||
self.config["enabled_plugins"] = enabled_plugins
|
||||
|
||||
deluge.pluginmanagerbase.PluginManagerBase.__init__(
|
||||
self, "gtkui.conf", "deluge.plugin.ui.gtk")
|
||||
self, "gtkui.conf", "deluge.plugin.gtkui")
|
||||
|
||||
def get_torrentview(self):
|
||||
"""Returns a reference to the torrentview component"""
|
||||
#return self._gtkui.mainwindow.torrentview
|
||||
return component.get("TorrentView")
|
||||
|
||||
def get_toolbar(self):
|
||||
"""Returns a reference to the toolbar component"""
|
||||
# return self._gtkui.mainwindow.toolbar
|
||||
return component.get("ToolBar")
|
||||
|
||||
def get_menubar(self):
|
||||
"""Returns a reference to the menubar component"""
|
||||
# return self._gtkui.mainwindow.menubar
|
||||
return component.get("MenuBar")
|
||||
|
||||
def get_torrentmenu(self):
|
||||
"""Returns a reference to the torrentmenu component"""
|
||||
# return self._gtkui.mainwindow.menubar.torrentmenu
|
||||
return component.get("MenuBar").torrentmenu
|
||||
|
||||
def get_selected_torrents(self):
|
||||
"""Returns a list of the selected torrent_ids"""
|
||||
# return self._gtkui.mainwindow.torrentview.get_selected_torrents()
|
||||
return component.get("TorrentView").get_selected_torrents()
|
||||
|
|
|
@ -438,8 +438,10 @@ class Preferences(component.Component):
|
|||
self.plugin_liststore.set_value(row, 1, not value)
|
||||
if not value:
|
||||
client.enable_plugin(name)
|
||||
component.get("PluginManager").enable_plugin(name)
|
||||
else:
|
||||
client.disable_plugin(name)
|
||||
component.get("PluginManager").disable_plugin(name)
|
||||
|
||||
def on_plugin_selection_changed(self, treeselection):
|
||||
log.debug("on_plugin_selection_changed")
|
||||
|
|
Loading…
Reference in New Issue