diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index f2a56fd08..92f007191 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -2,19 +2,19 @@ # pluginmanagerbase.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., @@ -43,18 +43,18 @@ from deluge.log import LOG as log class PluginManagerBase: """PluginManagerBase is a base class for PluginManagers to inherit""" - + def __init__(self, config_file, entry_name): log.debug("Plugin manager init..") - + self.config = deluge.configmanager.ConfigManager(config_file) - + # This is the entry we want to load.. self.entry_name = entry_name - + # Loaded plugins self.plugins = {} - + # Scan the plugin folders for plugins self.scan_for_plugins() @@ -67,27 +67,27 @@ class PluginManagerBase: # Disable all plugins that are enabled for key in self.plugins.keys(): self.plugins[key].disable() - + def __getitem__(self, key): return self.plugins[key] - + def get_available_plugins(self): """Returns a list of the available plugins name""" return self.available_plugins - + def get_enabled_plugins(self): """Returns a list of enabled plugins""" return self.plugins.keys() - + def scan_for_plugins(self): """Scans for available plugins""" plugin_dir = os.path.join(os.path.dirname(__file__), "plugins") user_plugin_dir = os.path.join(deluge.configmanager.get_config_dir(), "plugins") - + pkg_resources.working_set.add_entry(plugin_dir) pkg_resources.working_set.add_entry(user_plugin_dir) self.pkg_env = pkg_resources.Environment([plugin_dir, user_plugin_dir]) - + self.available_plugins = [] for name in self.pkg_env: pkg_name = str(self.pkg_env[name][0]).split()[0].replace("-", " ") @@ -98,10 +98,10 @@ class PluginManagerBase: def enable_plugin(self, plugin_name): """Enables a plugin""" if plugin_name not in self.available_plugins: - log.warning("Cannot enable non-existant plugin %s", name) + log.warning("Cannot enable non-existant plugin %s", plugin_name) return - plugin_name = plugin_name.replace(" ", "-") + plugin_name = plugin_name.replace(" ", "-") egg = self.pkg_env[plugin_name][0] egg.activate() for name in egg.get_entry_map(self.entry_name): @@ -112,11 +112,11 @@ class PluginManagerBase: plugin_name = plugin_name.replace("-", " ") self.plugins[plugin_name] = instance if plugin_name not in self.config["enabled_plugins"]: - log.debug("Adding %s to enabled_plugins list in config", + log.debug("Adding %s to enabled_plugins list in config", plugin_name) self.config["enabled_plugins"].append(plugin_name) log.info("Plugin %s enabled..", plugin_name) - + def disable_plugin(self, name): """Disables a plugin""" try: diff --git a/deluge/plugins/organize/organize/__init__.py b/deluge/plugins/organize/organize/__init__.py deleted file mode 100644 index 140cfc73f..000000000 --- a/deluge/plugins/organize/organize/__init__.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# __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. - -from deluge.log import LOG as log - -from deluge.plugins.init import PluginBase - -class CorePlugin(PluginBase): - def __init__(self, plugin_api, plugin_name): - # 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 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) -""" - diff --git a/deluge/plugins/organize/organize/core.py b/deluge/plugins/organize/organize/core.py deleted file mode 100644 index 0b7078c86..000000000 --- a/deluge/plugins/organize/organize/core.py +++ /dev/null @@ -1,135 +0,0 @@ -""" -torrent-organize core plugin. - -adds a status field for tracker. -""" - -from deluge.log import LOG as log -from deluge.plugins.corepluginbase import CorePluginBase - -from urlparse import urlparse - -STATE_FILTERS = { - 'Allocating': lambda t: (t.state == 'Allocating'), - 'Checking': lambda t: (t.state == 'Checking'), - 'Downloading': lambda t: (t.state == 'Downloadig'), - 'Seeding':lambda t: (t.state == 'Seeding'), - 'Paused':lambda t: (t.state == 'Paused'), - 'Error':lambda t: (t.state == 'Error'), - 'Queued':lambda t: (t.state == 'Queued') - #'Traffic':lambda t: (t.download_payload_rate > 0 or t.upload_payload_rate > 0) -} - -class Core(CorePluginBase): - def enable(self): - log.info("*** START Organize plugin***") - - self.plugin.register_status_field("tracker_name", self._status_get_tracker) - log.debug("Organize plugin enabled..") - - #__init__.... - core = self.plugin.get_core() - self.torrents = core.torrents.torrents - - def disable(self): - # De-register the label field - - self.plugin.deregister_status_field("tracker_name") - - def update(self): - pass - - - ## Utils ## - def get_tracker(self, torrent): - "returns 1st tracker." - log.debug(torrent) - log.debug(torrent.trackers) - if not torrent.trackers: - return 'tracker-less' - url = urlparse(torrent.trackers[0]['url']) - if hasattr(url,'hostname'): - return (url.hostname or 'unknown?') - return 'No-tracker?' - - ## Filters ## - def filter_state(self, torrents, state): - "in/out: a list of torrent objects." - filter_func = STATE_FILTERS[state] - return [t for t in torrents if filter_func(t)] - - def filter_tracker(self, torrents, tracker): - "in/out: a list of torrent objects." - return [t for t in torrents if self.get_tracker(t) == tracker] - - def filter_keyword(self, torrents, keyword): - "in/out: a list of torrent objects." - return [t for t in torrents if keyword in t.filename.lower()] - - ## Public ## - def export_state_filter_items(self): - """ - returns a sorted list of tuples: - [(state, count), ...] - """ - #maybe I should explain this.. .. - #or just fix it to be less generic, and more readable. - return [("All", len(self.torrents))] + [ - (state, len(self.filter_state(self.torrents.values(), state))) - for state in STATE_FILTERS] - - def export_tracker_filter_items(self): - """ - returns a sorted list of tuples: - [(tracker_name, count), ...] - """ - trackers = [self.get_tracker(t) for t in self.torrents.values()] - tcounter = {} - for tracker in trackers: - tcounter[tracker] = tcounter.get(tracker,0) + 1 - #tcounter= {'tracker-name':count, ...} - return sorted([x for x in tcounter.iteritems()]) - - def export_all_filter_items(self): - """ - for sclient, returns:{ - 'tracker':, - 'state':} - """ - return { - 'tracker':self.export_tracker_filter_items(), - 'state':self.export_state_filter_items() - } - - def export_get_session_state(self,filter_dict): - """ - in: a dict of filters: - { - 'keyword':'a keyword', - 'state':'Seeding', - 'tracker':'tracker.aelitis.com' - } - returns a list of torrent_id's - """ - torrents = self.torrents.values() - - if 'keyword' in filter_dict: - filter_dict['keyword'] = filter_dict['keyword'].lower() - torrents = self.filter_keyword(torrents, filter_dict['keyword']) - - if 'state' in filter_dict and filter_dict['state'] <> "All": - torrents = self.filter_state(torrents, filter_dict['state']) - - if 'tracker' in filter_dict: - torrents = self.filter_tracker(torrents, filter_dict['tracker']) - - return [t.torrent_id for t in torrents] - - - ## Status fields ## - def _status_get_tracker(self, torrent_id): - return self.get_tracker(self.torrents[torrent_id]) - -if __name__ == "__main__": - import test - diff --git a/deluge/plugins/organize/organize/test.py b/deluge/plugins/organize/organize/test.py deleted file mode 100644 index fbc575e45..000000000 --- a/deluge/plugins/organize/organize/test.py +++ /dev/null @@ -1,41 +0,0 @@ -from deluge.ui.client import sclient - -sclient.set_core_uri() - -ids = sclient.get_session_state() - -for t in sclient.get_torrents_status(ids, ['name','tracker_name','tracker']).itervalues(): - print t - -for tracker,count in sclient.organize_tracker_filter_items(): - print tracker, count - -for state,count in sclient.organize_state_filter_items(): - print state, count - -print sclient.organize_all_filter_items() - - -print 'tracker.aelitis.com:' -print sclient.organize_get_session_state({'tracker':'tracker.aelitis.com'} ) - -print 'no results' -print sclient.organize_get_session_state({'tracker':'no results'} ) - - -print 'seeding' -print sclient.organize_get_session_state({'state':'Seeding'} ) - -print 'paused' -print sclient.organize_get_session_state({'state':'Paused'} ) - -print 'seeding+tracker.aelitis.com' -print sclient.organize_get_session_state({ - 'tracker':'tracker.aelitis.com', - 'state':'Seeding'}) - -print 'on keyword:' -print sclient.organize_get_session_state({'keyword':'client'}) - -print 'on keyword:no results' -print sclient.organize_get_session_state({'keyword':'lasjhdinewhjdeg'}) diff --git a/deluge/plugins/organize/setup.py b/deluge/plugins/organize/setup.py deleted file mode 100644 index 486b83947..000000000 --- a/deluge/plugins/organize/setup.py +++ /dev/null @@ -1,55 +0,0 @@ -# setup.py -# -# Copyright (C) 2008 Martijn Voncken -# -# 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. - -""" -Organize plugin. - -Offers filters on state,tracker and keyword. -Core only for now, moving builtin webui stuff to a plugin. - -Future: Labels/Tags -""" - -from setuptools import setup - -__author__ = "Martijn Voncken" - -setup( - name="Organize", - version="0.1", - description=__doc__, - author=__author__, - packages=["organize"], - #package_data = {"testp": ["glade/*.glade"]}, - entry_points=""" - [deluge.plugin.core] - Organize = organize:CorePlugin - """ -)