mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-14 13:34:21 +00:00
Flake8'd core files
This commit is contained in:
parent
ef7605f9ec
commit
c3477ace9b
@ -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..")
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
@ -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):
|
||||
|
@ -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."""
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user