diff --git a/deluge/core/core.py b/deluge/core/core.py index faf24f07a..c9db26f69 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -50,10 +50,12 @@ else: dbus_imported = True import gobject import deluge.libtorrent as lt +import pkg_resources from deluge.config import Config import deluge.common from deluge.core.torrentmanager import TorrentManager +from deluge.core.pluginmanager import PluginManager # Get the logger log = logging.getLogger("deluge") @@ -87,7 +89,10 @@ class Core(dbus.service.Object): # Start the TorrentManager self.torrents = TorrentManager(self.session) - + + # Load plugins + self.plugins = PluginManager() + log.debug("Starting main loop..") self.loop = gobject.MainLoop() self.loop.run() diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py new file mode 100644 index 000000000..3fb9eef4e --- /dev/null +++ b/deluge/core/pluginmanager.py @@ -0,0 +1,63 @@ +# +# pluginmanager.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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 logging +import os.path + +import pkg_resources + +# Get the logger +log = logging.getLogger("deluge") + +class PluginManager: + def __init__(self): + # This will load any .eggs in the plugins folder inside the main + # deluge egg.. Need to scan the local plugin folder too. + + plugin_dir = os.path.join(os.path.dirname(__file__), "..", "plugins") + + pkg_resources.working_set.add_entry(plugin_dir) + pkg_env = pkg_resources.Environment([plugin_dir]) + + self.plugins = {} + for name in pkg_env: + egg = pkg_env[name][0] + egg.activate() + modules = [] + for name in egg.get_entry_map("deluge.plugin"): + entry_point = egg.get_entry_info("deluge.plugin", name) + cls = entry_point.load() + instance = cls() + self.plugins[name] = instance + + log.info("Plugins loaded: %s", self.plugins) diff --git a/deluge/plugins/queue/queue/__init__.py b/deluge/plugins/queue/queue/__init__.py new file mode 100644 index 000000000..dea9791ae --- /dev/null +++ b/deluge/plugins/queue/queue/__init__.py @@ -0,0 +1,39 @@ +# +# __init__.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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. + +class QueuePlugin: + def __init__(self): + print "queue plugin init!" + + def test(self): + print "queue plugin test!" diff --git a/deluge/plugins/queue/setup.py b/deluge/plugins/queue/setup.py new file mode 100644 index 000000000..681dc02b4 --- /dev/null +++ b/deluge/plugins/queue/setup.py @@ -0,0 +1,49 @@ +# setup.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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. + +""" +Allow torrents to be queued in a specific order +""" + +from setuptools import setup + +__author__ = "Andrew Resch" + +setup( + name="Queue", + version="1.0", + description=__doc__, + author=__author__, + packages=["queue"], + entry_points=""" + [deluge.plugin] + Queue = queue:QueuePlugin + """ +) diff --git a/setup.py b/setup.py index 4f14bfcba..bb19020dd 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,7 @@ ez_setup.use_setuptools() from setuptools import setup, find_packages, Extension import platform import glob +import os python_version = platform.python_version()[0:3] @@ -83,6 +84,11 @@ libtorrent = Extension( sources = _sources ) +# Build the plugin eggs +for path in glob.glob('deluge/plugins/*'): + print path + "/setup.py" + os.system("cd " + path + "&& python setup.py bdist_egg -d ..") + # Main setup setup( @@ -100,11 +106,12 @@ setup( include_package_data = True, package_data = {"deluge": ["ui/gtkui/glade/*.glade", "data/pixmaps/*.png", - "ui/gtkui/po/*.po?" + "ui/gtkui/po/*.po?", + "plugins/*.egg", ]}, ext_package = "deluge", ext_modules = [libtorrent], - packages = find_packages(), + packages = find_packages(exclude=["plugins"]), entry_points = """ [console_scripts] deluge = deluge.main:main