diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/__init__.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/__init__.py index 813e7e3c8..4effcf535 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/__init__.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/__init__.py @@ -1,5 +1,4 @@ -# -# __init__.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -8,49 +7,28 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # from deluge.plugins.init import PluginInitBase + class CorePlugin(PluginInitBase): def __init__(self, plugin_name): from core import Core as _plugin_cls self._plugin_cls = _plugin_cls super(CorePlugin, self).__init__(plugin_name) + class GtkUIPlugin(PluginInitBase): def __init__(self, plugin_name): from gtkui import GtkUI as _plugin_cls self._plugin_cls = _plugin_cls super(GtkUIPlugin, self).__init__(plugin_name) + class WebUIPlugin(PluginInitBase): def __init__(self, plugin_name): from webui import WebUI as _plugin_cls diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py index cc1b6a01e..c87920a27 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py @@ -1,5 +1,4 @@ -# -# common.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -8,36 +7,14 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # +import os +import pkg_resources + + def get_resource(filename): - import pkg_resources, os - return pkg_resources.resource_filename("deluge.plugins.autoadd", - os.path.join("data", filename)) + return pkg_resources.resource_filename("deluge.plugins.autoadd", os.path.join("data", filename)) diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py index d9ed97aed..7d69cc533 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py @@ -1,5 +1,4 @@ -# -# core.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # Copyright (C) 2011 Pedro Algarvio @@ -9,33 +8,9 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # from deluge._libtorrent import lt @@ -55,47 +30,52 @@ from deluge.event import DelugeEvent log = logging.getLogger(__name__) + DEFAULT_PREFS = { - "watchdirs":{}, - "next_id":1 + "watchdirs": {}, + "next_id": 1 } -OPTIONS_AVAILABLE = { #option: builtin - "enabled":False, - "path":False, - "append_extension":False, + +OPTIONS_AVAILABLE = { # option: builtin + "enabled": False, + "path": False, + "append_extension": False, "copy_torrent": False, "delete_copy_torrent_toggle": False, - "abspath":False, - "download_location":True, - "max_download_speed":True, - "max_upload_speed":True, - "max_connections":True, - "max_upload_slots":True, - "prioritize_first_last":True, - "auto_managed":True, - "stop_at_ratio":True, - "stop_ratio":True, - "remove_at_ratio":True, - "move_completed":True, - "move_completed_path":True, - "label":False, - "add_paused":True, - "queue_to_top":False, + "abspath": False, + "download_location": True, + "max_download_speed": True, + "max_upload_speed": True, + "max_connections": True, + "max_upload_slots": True, + "prioritize_first_last": True, + "auto_managed": True, + "stop_at_ratio": True, + "stop_ratio": True, + "remove_at_ratio": True, + "move_completed": True, + "move_completed_path": True, + "label": False, + "add_paused": True, + "queue_to_top": False, "owner": "localclient" } MAX_NUM_ATTEMPTS = 10 + class AutoaddOptionsChangedEvent(DelugeEvent): """Emitted when the options for the plugin are changed.""" def __init__(self): pass -def CheckInput(cond, message): + +def check_input(cond, message): if not cond: raise Exception(message) + class Core(CorePluginBase): def enable(self): @@ -138,12 +118,12 @@ class Core(CorePluginBase): """Update the options for a watch folder.""" watchdir_id = str(watchdir_id) options = self._make_unicode(options) - CheckInput( + check_input( watchdir_id in self.watchdirs, _("Watch folder does not exist.") ) - if options.has_key('path'): + if "path" in options: options['abspath'] = os.path.abspath(options['path']) - CheckInput( + check_input( os.path.isdir(options['abspath']), _("Path does not exist.") ) for w_id, w in self.watchdirs.iteritems(): @@ -174,14 +154,14 @@ class Core(CorePluginBase): filedump = _file.read() if not filedump: - raise RuntimeError, "Torrent is 0 bytes!" + raise RuntimeError("Torrent is 0 bytes!") _file.close() except IOError, e: log.warning("Unable to open %s: %s", filename, e) raise e # Get the info to see if any exceptions are raised - if magnet == False: + if not magnet: lt.torrent_info(lt.bdecode(filedump)) return base64.encodestring(filedump) @@ -421,9 +401,9 @@ class Core(CorePluginBase): """Add a watch folder.""" options = self._make_unicode(options) abswatchdir = os.path.abspath(options['path']) - CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist.")) - CheckInput( - os.access(abswatchdir, os.R_OK|os.W_OK), + check_input(os.path.isdir(abswatchdir), _("Path does not exist.")) + check_input( + os.access(abswatchdir, os.R_OK | os.W_OK), "You must have read and write access to watch folder." ) if abswatchdir in [wd['abspath'] for wd in self.watchdirs.itervalues()]: @@ -443,8 +423,7 @@ class Core(CorePluginBase): def remove(self, watchdir_id): """Remove a watch folder.""" watchdir_id = str(watchdir_id) - CheckInput(watchdir_id in self.watchdirs, - "Unknown Watchdir: %s" % self.watchdirs) + check_input(watchdir_id in self.watchdirs, "Unknown Watchdir: %s" % self.watchdirs) if self.watchdirs[watchdir_id]['enabled']: self.disable_watchdir(watchdir_id) del self.watchdirs[watchdir_id] diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py index b369fc124..4891a3841 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py @@ -1,5 +1,4 @@ -# -# gtkui.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -8,33 +7,9 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # import gtk @@ -51,9 +26,11 @@ from common import get_resource log = logging.getLogger(__name__) + class IncompatibleOption(Exception): pass + class OptionsDialog(): spin_ids = ["max_download_speed", "max_upload_speed", "stop_ratio"] spin_int_ids = ["max_upload_slots", "max_connections"] @@ -68,11 +45,11 @@ class OptionsDialog(): def show(self, options={}, watchdir_id=None): self.glade = gtk.glade.XML(get_resource("autoadd_options.glade")) self.glade.signal_autoconnect({ - "on_opts_add":self.on_add, - "on_opts_apply":self.on_apply, - "on_opts_cancel":self.on_cancel, - "on_options_dialog_close":self.on_cancel, - "on_toggle_toggled":self.on_toggle_toggled + "on_opts_add": self.on_add, + "on_opts_apply": self.on_apply, + "on_opts_cancel": self.on_cancel, + "on_options_dialog_close": self.on_cancel, + "on_toggle_toggled": self.on_toggle_toggled }) self.dialog = self.glade.get_widget("options_dialog") self.dialog.set_transient_for(component.get("Preferences").pref_dialog) @@ -287,7 +264,7 @@ class OptionsDialog(): self.glade.get_widget('stop_ratio').set_sensitive(isactive) self.glade.get_widget('remove_at_ratio').set_sensitive(isactive) - def on_apply(self, Event=None): + def on_apply(self, event=None): try: options = self.generate_opts() client.autoadd.set_options( @@ -296,7 +273,6 @@ class OptionsDialog(): except IncompatibleOption, err: dialogs.ErrorDialog(_("Incompatible Option"), str(err), self.dialog).run() - def on_error_show(self, result): d = dialogs.ErrorDialog(_("Error"), result.value.exception_msg, self.dialog) result.cleanFailure() @@ -305,14 +281,14 @@ class OptionsDialog(): def on_added(self, result): self.dialog.destroy() - def on_add(self, Event=None): + def on_add(self, event=None): try: options = self.generate_opts() client.autoadd.add(options).addCallbacks(self.on_added, self.on_error_show) except IncompatibleOption, err: dialogs.ErrorDialog(_("Incompatible Option"), str(err), self.dialog).run() - def on_cancel(self, Event=None): + def on_cancel(self, event=None): self.dialog.destroy() def generate_opts(self): @@ -424,32 +400,32 @@ class GtkUI(GtkPluginBase): ]) return store - def create_columns(self, treeView): - rendererToggle = gtk.CellRendererToggle() + def create_columns(self, treeview): + renderer_toggle = gtk.CellRendererToggle() column = gtk.TreeViewColumn( - _("Active"), rendererToggle, activatable=1, active=1 + _("Active"), renderer_toggle, activatable=1, active=1 ) column.set_sort_column_id(1) - treeView.append_column(column) + treeview.append_column(column) tt = gtk.Tooltip() tt.set_text(_('Double-click to toggle')) - treeView.set_tooltip_cell(tt, None, None, rendererToggle) + treeview.set_tooltip_cell(tt, None, None, renderer_toggle) - rendererText = gtk.CellRendererText() - column = gtk.TreeViewColumn(_("Owner"), rendererText, text=2) + renderertext = gtk.CellRendererText() + column = gtk.TreeViewColumn(_("Owner"), renderertext, text=2) column.set_sort_column_id(2) - treeView.append_column(column) + treeview.append_column(column) tt2 = gtk.Tooltip() tt2.set_text(_('Double-click to edit')) - treeView.set_has_tooltip(True) + treeview.set_has_tooltip(True) - rendererText = gtk.CellRendererText() - column = gtk.TreeViewColumn(_("Path"), rendererText, text=3) + renderertext = gtk.CellRendererText() + column = gtk.TreeViewColumn(_("Path"), renderertext, text=3) column.set_sort_column_id(3) - treeView.append_column(column) + treeview.append_column(column) tt2 = gtk.Tooltip() tt2.set_text(_('Double-click to edit')) - treeView.set_has_tooltip(True) + treeview.set_has_tooltip(True) def load_watchdir_list(self): pass @@ -457,17 +433,17 @@ class GtkUI(GtkPluginBase): def add_watchdir_entry(self): pass - def on_add_button_clicked(self, Event=None): + def on_add_button_clicked(self, event=None): #display options_window self.opts_dialog.show() - def on_remove_button_clicked(self, Event=None): + def on_remove_button_clicked(self, event=None): tree, tree_id = self.treeView.get_selection().get_selected() watchdir_id = str(self.store.get_value(tree_id, 0)) if watchdir_id: client.autoadd.remove(watchdir_id) - def on_edit_button_clicked(self, Event=None, a=None, col=None): + def on_edit_button_clicked(self, event=None, a=None, col=None): tree, tree_id = self.treeView.get_selection().get_selected() watchdir_id = str(self.store.get_value(tree_id, 0)) if watchdir_id: diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py index a2d56f549..2133a05e3 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py @@ -1,5 +1,4 @@ -# -# webui.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -8,44 +7,19 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # import logging -from deluge.ui.client import client -from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource log = logging.getLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("autoadd.js")] diff --git a/deluge/plugins/AutoAdd/setup.py b/deluge/plugins/AutoAdd/setup.py index 62ff199f4..beb407391 100644 --- a/deluge/plugins/AutoAdd/setup.py +++ b/deluge/plugins/AutoAdd/setup.py @@ -1,5 +1,4 @@ -# -# setup.py +# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # Copyright (C) 2011 Pedro Algarvio @@ -9,33 +8,9 @@ # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill # -# 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 3 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. +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. # from setuptools import setup, find_packages @@ -60,8 +35,8 @@ setup( license=__license__, long_description=__long_description__ if __long_description__ else __description__, packages=find_packages(), - namespace_packages = ["deluge", "deluge.plugins"], - package_data = __pkg_data__, + namespace_packages=["deluge", "deluge.plugins"], + package_data=__pkg_data__, entry_points=""" [deluge.plugin.core]