diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index ed19a9995..794ffb492 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -50,6 +50,7 @@ from deluge.common import decode_string log = logging.getLogger(__name__) + class AlertManager(component.Component): def __init__(self): log.debug("AlertManager initialized..") diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index 12f06dacb..3bc7fc643 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -35,8 +35,6 @@ # import os -import random -import stat import shutil import logging @@ -62,8 +60,10 @@ AUTH_LEVELS_MAPPING_REVERSE = {} for key, value in AUTH_LEVELS_MAPPING.iteritems(): AUTH_LEVELS_MAPPING_REVERSE[value] = key + class Account(object): __slots__ = ('username', 'password', 'authlevel') + def __init__(self, username, password, authlevel): self.username = username self.password = password @@ -297,9 +297,7 @@ class AuthManager(component.Component): create_localclient_account(True) return self.__load_auth_file() - if save_and_reload: log.info("Re-writing auth file (upgrade)") self.write_auth_file() self.__auth_modification_time = auth_file_modification_time - diff --git a/deluge/core/core.py b/deluge/core/core.py index 0296dc559..b1aa5e423 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -54,8 +54,8 @@ from deluge import path_chooser_common from deluge.configmanager import ConfigManager, get_config_dir import deluge.common import deluge.component as component -from deluge.event import * -from deluge.error import * +from deluge.event import NewVersionAvailableEvent, SessionResumedEvent, TorrentQueueChangedEvent +from deluge.error import DelugeError, InvalidTorrentError, InvalidPathError from deluge.core.authmanager import AUTH_LEVEL_ADMIN, AUTH_LEVEL_NONE from deluge.core.authmanager import AUTH_LEVELS_MAPPING, AUTH_LEVELS_MAPPING_REVERSE from deluge.core.torrentmanager import TorrentManager diff --git a/deluge/core/eventmanager.py b/deluge/core/eventmanager.py index 755451c40..a53a10e86 100644 --- a/deluge/core/eventmanager.py +++ b/deluge/core/eventmanager.py @@ -38,6 +38,7 @@ import deluge.component as component log = logging.getLogger(__name__) + class EventManager(component.Component): def __init__(self): component.Component.__init__(self, "EventManager") diff --git a/deluge/core/filtermanager.py b/deluge/core/filtermanager.py index d4af33a4a..e64db2b86 100644 --- a/deluge/core/filtermanager.py +++ b/deluge/core/filtermanager.py @@ -41,17 +41,18 @@ STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"] log = logging.getLogger(__name__) + # Special purpose filters: def filter_keywords(torrent_ids, values): # Cleanup keywords = ",".join([v.lower() for v in values]) keywords = keywords.split(",") - for keyword in keywords: torrent_ids = filter_one_keyword(torrent_ids, keyword) return torrent_ids + def filter_one_keyword(torrent_ids, keyword): """ search torrent on keyword. @@ -59,7 +60,6 @@ def filter_one_keyword(torrent_ids, keyword): """ all_torrents = component.get("TorrentManager").torrents - found = False for torrent_id in torrent_ids: torrent = all_torrents[torrent_id] if keyword in torrent.filename.lower(): @@ -79,6 +79,7 @@ def filter_one_keyword(torrent_ids, keyword): yield torrent_id break + def filter_by_name(torrent_ids, search_string): all_torrents = component.get("TorrentManager").torrents try: @@ -100,6 +101,7 @@ def filter_by_name(torrent_ids, search_string): if search_string in torrent_name: yield torrent_id + def tracker_error_filter(torrent_ids, values): filtered_torrent_ids = [] tm = component.get("TorrentManager") @@ -117,6 +119,7 @@ def tracker_error_filter(torrent_ids, values): filtered_torrent_ids.append(torrent_id) return filtered_torrent_ids + class FilterManager(component.Component): """FilterManager @@ -134,6 +137,7 @@ class FilterManager(component.Component): self.filter_tree_items = None self.register_tree_field("state", self._init_state_tree) + def _init_tracker_tree(): return {"Error": 0} self.register_tree_field("tracker_host", _init_tracker_tree) @@ -220,7 +224,7 @@ class FilterManager(component.Component): items = copy.deepcopy(self.filter_tree_items) for torrent_id in list(torrent_ids): - status = self.core.create_torrent_status(torrent_id, torrent_keys, plugin_keys) #status={key:value} + status = self.core.create_torrent_status(torrent_id, torrent_keys, plugin_keys) # status={key:value} for field in tree_keys: value = status[field] items[field][value] = items[field].get(value, 0) + 1 @@ -229,7 +233,7 @@ class FilterManager(component.Component): items["tracker_host"]["All"] = len(torrent_ids) items["tracker_host"]["Error"] = len(tracker_error_filter(torrent_ids, ("Error",))) - if not show_zero_hits: + if not show_zero_hits: for cat in ["state", "owner", "tracker_host"]: if cat in tree_keys: self._hide_state_items(items[cat]) @@ -245,23 +249,23 @@ class FilterManager(component.Component): return sorted_items def _init_state_tree(self): - return {"All":len(self.torrents.get_torrent_list()), - "Downloading":0, - "Seeding":0, - "Paused":0, - "Checking":0, - "Queued":0, - "Error":0, - "Active":len(self.filter_state_active(self.torrents.get_torrent_list())) - } + return {"All": len(self.torrents.get_torrent_list()), + "Downloading": 0, + "Seeding": 0, + "Paused": 0, + "Checking": 0, + "Queued": 0, + "Error": 0, + "Active": len(self.filter_state_active(self.torrents.get_torrent_list())) + } - def register_filter(self, id, filter_func, filter_value = None): + def register_filter(self, id, filter_func, filter_value=None): self.registered_filters[id] = filter_func def deregister_filter(self, id): del self.registered_filters[id] - def register_tree_field(self, field, init_func = lambda : {}): + def register_tree_field(self, field, init_func=lambda: {}): self.tree_fields[field] = init_func def deregister_tree_field(self, field): @@ -279,7 +283,7 @@ class FilterManager(component.Component): def _hide_state_items(self, state_items): "for hide(show)-zero hits" - for (value, count) in state_items.items(): + for (value, count) in state_items.items(): if value != "All" and count == 0: del state_items[value] diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index 5ef5ef55f..e94ae84ca 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -44,8 +44,8 @@ import deluge.component as component log = logging.getLogger(__name__) -class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, - component.Component): + +class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Component): """PluginManager handles the loading of plugins and provides plugins with functions to access parts of the core.""" diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index 3678265a0..648fd1581 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -41,7 +41,7 @@ from twisted.internet.task import LoopingCall from deluge._libtorrent import lt -from deluge.event import * +from deluge.event import ConfigValueChangedEvent import deluge.configmanager import deluge.common import deluge.component as component diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index 4b734da84..45fc95299 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -36,23 +36,17 @@ """RPCServer Module""" import sys -import zlib import os import stat import logging import traceback -from twisted.internet.protocol import Factory, Protocol +from twisted.internet.protocol import Factory from twisted.internet import reactor, defer from OpenSSL import crypto, SSL from types import FunctionType -try: - import rencode -except ImportError: - import deluge.rencode as rencode - import deluge.component as component import deluge.configmanager from deluge.core.authmanager import (AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT, @@ -68,6 +62,7 @@ RPC_EVENT = 3 log = logging.getLogger(__name__) + def export(auth_level=AUTH_LEVEL_DEFAULT): """ Decorator function to register an object's method as an RPC. The object @@ -122,6 +117,7 @@ def format_request(call): else: return s + class ServerContextFactory(object): def getContext(self): """ @@ -136,6 +132,7 @@ class ServerContextFactory(object): ctx.use_privatekey_file(os.path.join(ssl_dir, "daemon.pkey")) return ctx + class DelugeRPCProtocol(DelugeTransferProtocol): def message_received(self, request): @@ -323,7 +320,7 @@ class DelugeRPCProtocol(DelugeTransferProtocol): def on_fail(failure): try: failure.raiseException() - except Exception, e: + except Exception: sendError() return failure @@ -331,6 +328,7 @@ class DelugeRPCProtocol(DelugeTransferProtocol): else: self.sendData((RPC_RESPONSE, request_id, ret)) + class RPCServer(component.Component): """ This class is used to handle rpc requests from the client. Objects are @@ -531,7 +529,8 @@ class RPCServer(component.Component): log.debug("Session ID %s is not valid. Not sending event \"%s\".", session_id, event.name) return if session_id not in self.factory.interested_events: - log.debug("Session ID %s is not interested in any events. Not sending event \"%s\".", session_id, event.name) + log.debug("Session ID %s is not interested in any events. Not sending event \"%s\".", + session_id, event.name) return if event.name not in self.factory.interested_events[session_id]: log.debug("Session ID %s is not interested in event \"%s\". Not sending it.", session_id, event.name) @@ -556,6 +555,7 @@ def check_ssl_keys(): generate_ssl_keys() break + def generate_ssl_keys(): """ This method generates a new SSL key/cert. @@ -576,7 +576,7 @@ def generate_ssl_keys(): cert = crypto.X509() cert.set_serial_number(0) cert.gmtime_adj_notBefore(0) - cert.gmtime_adj_notAfter(60*60*24*365*5) # Five Years + cert.gmtime_adj_notAfter(60*60*24*365*5) # Five Years cert.set_issuer(req.get_subject()) cert.set_subject(req.get_subject()) cert.set_pubkey(req.get_pubkey())