diff --git a/ChangeLog b/ChangeLog index 1ed3af7dd..6391b0803 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ === Deluge 1.3.0 (In Development) === + * Improved Logging * Enforced the use of the "deluge.plugins" namespace to reduce package names clashing beetween regular packages and deluge plugins. ==== Core ==== diff --git a/deluge/common.py b/deluge/common.py index 3acccd780..aba2904f9 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -42,12 +42,15 @@ import subprocess import platform import sys import chardet +import logging try: import json except ImportError: import simplejson as json +log = logging.getLogger(__name__) + # Do a little hack here just in case the user has json-py installed since it # has a different api if not hasattr(json, "dumps"): @@ -77,7 +80,6 @@ try: gettext.textdomain("deluge") gettext.install("deluge", pkg_resources.resource_filename("deluge", "i18n")) except Exception, e: - from deluge.log import LOG as log log.error("Unable to initialize gettext/locale!") log.exception(e) import __builtin__ @@ -527,7 +529,7 @@ def path_join(*parts): path += '/' + part return path -XML_ESCAPES = ( +XML_ESCAPES = ( ('&', '&'), ('<', '<'), ('>', '>'), @@ -536,9 +538,9 @@ XML_ESCAPES = ( ) def xml_decode(string): - """ + """ Unescape a string that was previously encoded for use within xml. - + :param string: The string to escape :type string: string :returns: The unescaped version of the string. @@ -549,9 +551,9 @@ def xml_decode(string): return string def xml_encode(string): - """ + """ Escape a string for use within an xml element or attribute. - + :param string: The string to escape :type string: string :returns: An escaped version of the string. diff --git a/deluge/component.py b/deluge/component.py index a516fd95e..4a6f39622 100644 --- a/deluge/component.py +++ b/deluge/component.py @@ -33,9 +33,11 @@ # # +import logging from twisted.internet.defer import maybeDeferred, succeed, DeferredList, fail from twisted.internet.task import LoopingCall -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class ComponentAlreadyRegistered(Exception): pass diff --git a/deluge/config.py b/deluge/config.py index 74406d213..5dbb68197 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -68,14 +68,16 @@ version as this will be done internally. """ import cPickle as pickle +import logging import shutil import os import deluge.common -from deluge.log import LOG as log json = deluge.common.json +log = logging.getLogger(__name__) + def prop(func): """Function decorator for defining property attributes diff --git a/deluge/configmanager.py b/deluge/configmanager.py index 4638494d5..dc92a534a 100644 --- a/deluge/configmanager.py +++ b/deluge/configmanager.py @@ -34,11 +34,14 @@ # import os +import logging import deluge.common -from deluge.log import LOG as log +import deluge.log from deluge.config import Config +log = logging.getLogger(__name__) + class _ConfigManager: def __init__(self): log.debug("ConfigManager started..") @@ -52,7 +55,6 @@ class _ConfigManager: return self.__config_directory def __del__(self): - log.debug("ConfigManager stopping..") del self.config_files def set_config_dir(self, directory): @@ -86,6 +88,7 @@ class _ConfigManager: # to reload based on the new config directory self.save() self.config_files = {} + deluge.log.tweak_logging_levels() return True diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index b55a99458..e2ff6c865 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -41,12 +41,13 @@ This should typically only be used by the Core. Plugins should utilize the """ +import logging from twisted.internet import reactor import deluge.component as component from deluge._libtorrent import lt -from deluge.log import LOG as log +log = logging.getLogger(__name__) class AlertManager(component.Component): def __init__(self): diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index ef6fbc464..106351b43 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -36,12 +36,13 @@ import os import random import stat +import logging import deluge.component as component import deluge.configmanager as configmanager import deluge.error -from deluge.log import LOG as log +log = logging.getLogger(__name__) AUTH_LEVEL_NONE = 0 AUTH_LEVEL_READONLY = 1 diff --git a/deluge/core/autoadd.py b/deluge/core/autoadd.py index 6d3d7a8bc..911b560ce 100644 --- a/deluge/core/autoadd.py +++ b/deluge/core/autoadd.py @@ -35,15 +35,17 @@ import os +import logging from deluge._libtorrent import lt import deluge.component as component from deluge.configmanager import ConfigManager -from deluge.log import LOG as log MAX_NUM_ATTEMPTS = 10 +log = logging.getLogger(__name__) + class AutoAdd(component.Component): def __init__(self): component.Component.__init__(self, "AutoAdd", depend=["TorrentManager"], interval=5) diff --git a/deluge/core/core.py b/deluge/core/core.py index 82fa4a53e..14eb00833 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -39,6 +39,7 @@ import os import glob import base64 import shutil +import logging import threading import pkg_resources import warnings @@ -50,9 +51,6 @@ from twisted.internet.task import LoopingCall import twisted.web.client from deluge.httpdownloader import download_file -from deluge.log import LOG as log - - import deluge.configmanager import deluge.common @@ -69,6 +67,8 @@ from deluge.core.authmanager import AuthManager from deluge.core.eventmanager import EventManager from deluge.core.rpcserver import export +log = logging.getLogger(__name__) + class Core(component.Component): def __init__(self, listen_interface=None): log.debug("Core init..") diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index 44b7912e5..5cad58af0 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -35,6 +35,7 @@ import os import gettext import locale +import logging import pkg_resources from twisted.internet import reactor import twisted.internet.error @@ -43,9 +44,10 @@ import deluge.component as component import deluge.configmanager import deluge.common from deluge.core.rpcserver import RPCServer, export -from deluge.log import LOG as log import deluge.error +log = logging.getLogger(__name__) + class Daemon(object): def __init__(self, options=None, args=None, classic=False): # Check for another running instance of the daemon diff --git a/deluge/core/eventmanager.py b/deluge/core/eventmanager.py index 7687bfc30..1199813d8 100644 --- a/deluge/core/eventmanager.py +++ b/deluge/core/eventmanager.py @@ -33,8 +33,10 @@ # # +import logging import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class EventManager(component.Component): def __init__(self): diff --git a/deluge/core/filtermanager.py b/deluge/core/filtermanager.py index a91136845..359eb45a5 100644 --- a/deluge/core/filtermanager.py +++ b/deluge/core/filtermanager.py @@ -33,12 +33,13 @@ # # - +import logging import deluge.component as component -from deluge.log import LOG as log STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"] +log = logging.getLogger(__name__) + #special purpose filters: def filter_keywords(torrent_ids, values): #cleanup. diff --git a/deluge/core/oldstateupgrader.py b/deluge/core/oldstateupgrader.py index 9dc722d25..96e84bea4 100644 --- a/deluge/core/oldstateupgrader.py +++ b/deluge/core/oldstateupgrader.py @@ -39,12 +39,14 @@ import os.path import pickle import cPickle import shutil +import logging from deluge._libtorrent import lt from deluge.configmanager import ConfigManager, get_config_dir import deluge.core.torrentmanager -from deluge.log import LOG as log + +log = logging.getLogger(__name__) #start : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286203 def makeFakeClass(module, name): diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index 07f16bcfb..119928979 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -36,13 +36,15 @@ """PluginManager for Core""" +import logging from twisted.internet import reactor from twisted.internet.task import LoopingCall from deluge.event import PluginEnabledEvent, PluginDisabledEvent import deluge.pluginmanagerbase import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Component): diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index adc707e3f..a79659866 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -35,6 +35,7 @@ import os +import logging import threading import pkg_resources from twisted.internet import reactor @@ -46,7 +47,8 @@ from deluge.event import * import deluge.configmanager import deluge.common import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) DEFAULT_PREFS = { "send_info": False, diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index a84ccbf75..2858b3b30 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -39,6 +39,7 @@ import sys import zlib import os import stat +import logging import traceback from twisted.internet.protocol import Factory, Protocol @@ -52,8 +53,6 @@ try: except ImportError: import deluge.rencode as rencode -from deluge.log import LOG as log - import deluge.component as component import deluge.configmanager from deluge.core.authmanager import AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT @@ -62,6 +61,8 @@ RPC_RESPONSE = 1 RPC_ERROR = 2 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 diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 3b613356a..7651b6e5b 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -36,6 +36,7 @@ import os import time +import logging from urllib import unquote from urlparse import urlparse @@ -44,11 +45,12 @@ from deluge._libtorrent import lt import deluge.common import deluge.component as component from deluge.configmanager import ConfigManager, get_config_dir -from deluge.log import LOG as log from deluge.event import * TORRENT_STATE = deluge.common.TORRENT_STATE +log = logging.getLogger(__name__) + class TorrentOptions(dict): def __init__(self): config = ConfigManager("core.conf").config diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 4a2bfafac..b02443cb6 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -41,6 +41,7 @@ import os import time import shutil import operator +import logging from twisted.internet import reactor from twisted.internet.task import LoopingCall @@ -56,7 +57,7 @@ from deluge.core.torrent import TorrentOptions import deluge.core.oldstateupgrader from deluge.common import utf8_encoded -from deluge.log import LOG as log +log = logging.getLogger(__name__) class TorrentState: def __init__(self, diff --git a/deluge/httpdownloader.py b/deluge/httpdownloader.py index b92bd9e06..2af5e59cf 100644 --- a/deluge/httpdownloader.py +++ b/deluge/httpdownloader.py @@ -36,16 +36,19 @@ from twisted.web import client, http from twisted.web.error import PageRedirect from twisted.python.failure import Failure from twisted.internet import reactor -from deluge.log import setupLogger, LOG as log from common import get_version +import logging import os.path import zlib +log = logging.getLogger(__name__) + class HTTPDownloader(client.HTTPDownloader): """ Factory class for downloading files and keeping track of progress. """ - def __init__(self, url, filename, part_callback=None, headers=None, force_filename=False, allow_compression=True): + def __init__(self, url, filename, part_callback=None, headers=None, + force_filename=False, allow_compression=True): """ :param url: the url to download from :type url: string @@ -141,7 +144,7 @@ def sanitise_filename(filename): log.warning("Potentially malicious server: trying to write to file '%s'" % filename) # Only use the basename filename = os.path.basename(filename) - + filename = filename.strip() if filename.startswith(".") or ";" in filename or "|" in filename: # Dodgy server, log it @@ -152,7 +155,8 @@ def sanitise_filename(filename): return filename -def download_file(url, filename, callback=None, headers=None, force_filename=False, allow_compression=True): +def download_file(url, filename, callback=None, headers=None, + force_filename=False, allow_compression=True): """ Downloads a file from a specific URL and returns a Deferred. You can also specify a callback function to be called as parts are received. diff --git a/deluge/log.py b/deluge/log.py index 327375e06..b014fa9c7 100644 --- a/deluge/log.py +++ b/deluge/log.py @@ -2,6 +2,7 @@ # log.py # # Copyright (C) 2007 Andrew Resch +# Copyright (C) 2010 Pedro Algarvio # # Deluge is free software. # @@ -33,18 +34,100 @@ # # - """Logging functions""" +import os +import inspect import logging +from deluge import common +from twisted.internet import defer +from twisted.python.log import PythonLoggingObserver + +__all__ = ["setupLogger", "setLoggerLevel", "getPluginLogger", "LOG"] + +LoggingLoggerClass = logging.getLoggerClass() + +if 'dev' in common.get_version(): + DEFAULT_LOGGING_FORMAT = "%%(asctime)s.%%(msecs)03.0f [%%(name)-%ds:%%(lineno)-4d][%%(levelname)-8s] %%(message)s" +else: + DEFAULT_LOGGING_FORMAT = "%%(asctime)s [%%(name)-%ds][%%(levelname)-8s] %%(message)s" +MAX_LOGGER_NAME_LENGTH = 3 + +class Logging(LoggingLoggerClass): + def __init__(self, logger_name): + LoggingLoggerClass.__init__(self, logger_name) + + # This makes module name padding increase to the biggest module name + # so that logs keep readability. + global MAX_LOGGER_NAME_LENGTH + if len(logger_name) > MAX_LOGGER_NAME_LENGTH: + MAX_LOGGER_NAME_LENGTH = len(logger_name) + for handler in logging.getLogger().handlers: + handler.setFormatter(logging.Formatter( + DEFAULT_LOGGING_FORMAT % MAX_LOGGER_NAME_LENGTH, + datefmt="%H:%M:%S" + )) + + @defer.inlineCallbacks + def garbage(self, msg, *args, **kwargs): + yield LoggingLoggerClass.log(self, 1, msg, *args, **kwargs) + + @defer.inlineCallbacks + def trace(self, msg, *args, **kwargs): + yield LoggingLoggerClass.log(self, 5, msg, *args, **kwargs) + + @defer.inlineCallbacks + def debug(self, msg, *args, **kwargs): + yield LoggingLoggerClass.debug(self, msg, *args, **kwargs) + + @defer.inlineCallbacks + def info(self, msg, *args, **kwargs): + yield LoggingLoggerClass.info(self, msg, *args, **kwargs) + + @defer.inlineCallbacks + def warning(self, msg, *args, **kwargs): + yield LoggingLoggerClass.warning(self, msg, *args, **kwargs) + + warn = warning + + @defer.inlineCallbacks + def error(self, msg, *args, **kwargs): + yield LoggingLoggerClass.error(self, msg, *args, **kwargs) + + @defer.inlineCallbacks + def critical(self, msg, *args, **kwargs): + yield LoggingLoggerClass.critical(self, msg, *args, **kwargs) + + @defer.inlineCallbacks + def exception(self, msg, *args, **kwargs): + yield LoggingLoggerClass.exception(self, msg, *args, **kwargs) + + def findCaller(self): + f = logging.currentframe().f_back + rv = "(unknown file)", 0, "(unknown function)" + while hasattr(f, "f_code"): + co = f.f_code + filename = os.path.normcase(co.co_filename) + if filename in (__file__.replace('.pyc', '.py'), + defer.__file__.replace('.pyc', '.py')): + f = f.f_back + continue + rv = (filename, f.f_lineno, co.co_name) + break + return rv levels = { "info": logging.INFO, + "warn": logging.WARNING, "warning": logging.WARNING, "error": logging.ERROR, "none": logging.CRITICAL, - "debug": logging.DEBUG + "debug": logging.DEBUG, + "trace": 5, + "garbage": 1 } + + def setupLogger(level="error", filename=None, filemode="w"): """ Sets up the basic logger and if `:param:filename` is set, then it will log @@ -53,30 +136,148 @@ def setupLogger(level="error", filename=None, filemode="w"): :param level: str, the level to log :param filename: str, the file to log to """ + import logging - if not level or level not in levels: - level = "error" + if logging.getLoggerClass() is not Logging: + logging.setLoggerClass(Logging) - logging.basicConfig( - level=levels[level], - format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s", - datefmt="%H:%M:%S", - filename=filename, - filemode=filemode + level = levels.get(level, "error") + + rootLogger = logging.getLogger() + + if filename and filemode=='a': + import logging.handlers + handler = logging.handlers.RotatingFileHandler( + filename, filemode, + maxBytes=5*1024*1024, # 5 Mb + backupCount=3, + encoding='utf-8', + delay=0 + ) + elif filename and filemode=='w': + import logging.handlers + handler = getattr( + logging.handlers, 'WatchedFileHandler', logging.FileHandler)( + filename, filemode, 'utf-8', delay=0 + ) + else: + handler = logging.StreamHandler() + handler.setLevel(level) + + formatter = logging.Formatter( + DEFAULT_LOGGING_FORMAT % MAX_LOGGER_NAME_LENGTH, + datefmt="%H:%M:%S" ) -def setLoggerLevel(level): + handler.setFormatter(formatter) + rootLogger.addHandler(handler) + rootLogger.setLevel(level) + + twisted_logging = PythonLoggingObserver('twisted') + twisted_logging.start() + logging.getLogger("twisted").setLevel(level) + +def tweak_logging_levels(): + """This function allows tweaking the logging levels for all or some loggers. + This is mostly usefull for developing purposes hence the contents of the + file are NOT like regular deluge config file's. + + To use is, create a file named "logging.conf" on your Deluge's config dir + with contents like for example: + deluge:warn + deluge.core:debug + deluge.plugin:error + + What the above mean is the logger "deluge" will be set to the WARN level, + the "deluge.core" logger will be set to the DEBUG level and the + "deluge.plugin" will be set to the ERROR level. + + Remember, one rule per line and this WILL override the setting passed from + the command line. + """ + from deluge import configmanager + logging_config_file = os.path.join(configmanager.get_config_dir(), + 'logging.conf') + if not os.path.isfile(logging_config_file): + return + log = logging.getLogger(__name__) + log.warn("logging.conf found! tweaking logging levels from %s", + logging_config_file) + for line in open(logging_config_file, 'r').readlines(): + if line.strip().startswith("#"): + continue + name, level = line.strip().split(':') + if level not in levels: + continue + + log.warn("Setting logger \"%s\" to logging level \"%s\"", name, level) + setLoggerLevel(level, name) + + +def setLoggerLevel(level, logger_name=None): """ Sets the logger level. :param level: str, a string representing the desired level + :param logger_name: str, a string representing desired logger name for which + the level should change. The default is "None" will will + tweak the root logger level. """ - if level not in levels: - return + logging.getLogger(logger_name).setLevel(levels.get(level, "error")) - global LOG - LOG.setLevel(levels[level]) -# Get the logger -LOG = logging.getLogger("deluge") +def getPluginLogger(logger_name): + return logging.getLogger("deluge.plugin.%s" % logger_name) + + +DEPRECATION_WARNING = """You seem to be using old style logging on your code, ie: + from deluge.log import LOG as log + +This has been deprecated in favour of an enhanced logging system and "LOG" will +be removed on the next major version release of Deluge, meaning, code will break, +specially plugins. +If you're seeing this message and you're not the developer of the plugin which +triggered this warning, please report to it's author. +If you're the developer, please stop using the above code and instead use: + + from deluge.log import getPluginLogger + log = getPluginLogger(__name__) + + +The above will result in, regarding the "Label" plugin for example a log message similar to: + 15:33:54 [deluge.plugin.label.core:78 ][INFO ] *** Start Label plugin *** + +If you wish not to have 'deluge.plugin' on the log message you can then instead use: + + import logging + log = logging.getLogger(__name__) + +The above will result in, regarding the "Label" plugin for example a log message similar to: + 15:33:54 [label.core:78 ][INFO ] *** Start Label plugin *** + +Triggering code:""" + +class __BackwardsCompatibleLOG(object): + def __getattribute__(self, name): + import warnings + logger_name = 'deluge' + stack = inspect.stack() + module_stack = stack.pop(1) + caller_module = inspect.getmodule(module_stack[0]) + warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning, + module_stack[1], module_stack[2], + caller_module.__name__) + for member in stack: + module = inspect.getmodule(member[0]) + if not module: + continue + if module.__name__ in ('deluge.plugins.pluginbase', + 'deluge.plugins.init'): + logger_name += '.plugin.%s' % caller_module.__name__ + # Monkey Patch The Plugin Module + caller_module.log = logging.getLogger(logger_name) + break + return getattr(logging.getLogger(logger_name), name) + +LOG = __BackwardsCompatibleLOG() diff --git a/deluge/main.py b/deluge/main.py index 4b32e79e1..dfb489d59 100644 --- a/deluge/main.py +++ b/deluge/main.py @@ -2,6 +2,7 @@ # main.py # # Copyright (C) 2007 Andrew Resch +# Copyright (C) 2010 Pedro Algarvio # # Deluge is free software. # @@ -44,8 +45,7 @@ import sys from optparse import OptionParser import deluge.log -import deluge.common -import deluge.configmanager +#import deluge.common import deluge.error @@ -72,12 +72,25 @@ def start_ui(): help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") parser.add_option("-q", "--quiet", dest="quiet", help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) + parser.add_option("-r", "--rotate-logs", + help="Rotate logfiles.", action="store_true", default=False) parser.add_option("-s", "--set-default-ui", dest="default_ui", help="Sets the default UI to be run when no UI is specified", action="store", type="str") # Get the options and args from the OptionParser (options, args) = parser.parse_args() + if options.quiet: + options.loglevel = "none" + + logfile_mode = 'w' + if options.rotate_logs: + logfile_mode = 'a' + + # Setup the logger + deluge.log.setupLogger(level=options.loglevel, filename=options.logfile, + filemode=logfile_mode) + if options.config: if not os.path.exists(options.config): # Try to create the config folder if it doesn't exist @@ -93,6 +106,7 @@ def start_ui(): os.makedirs(deluge.common.get_default_config_dir()) if options.default_ui: + import deluge.configmanager if options.config: deluge.configmanager.set_config_dir(options.config) @@ -102,15 +116,10 @@ def start_ui(): print "The default UI has been changed to", options.default_ui sys.exit(0) - if options.quiet: - options.loglevel = "none" - - # Setup the logger - deluge.log.setupLogger(level=options.loglevel, filename=options.logfile) - version = deluge.common.get_version() - from deluge.log import LOG as log + import logging + log = logging.getLogger(__name__) log.info("Deluge ui %s", version) log.debug("options: %s", options) log.debug("args: %s", args) @@ -152,6 +161,8 @@ this should be an IP address", metavar="IFACE", help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") parser.add_option("-q", "--quiet", dest="quiet", help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) + parser.add_option("-r", "--rotate-logs", + help="Rotate logfiles.", action="store_true", default=False) parser.add_option("--profile", dest="profile", action="store_true", default=False, help="Profiles the daemon") @@ -161,6 +172,15 @@ this should be an IP address", metavar="IFACE", if options.quiet: options.loglevel = "none" + logfile_mode = 'w' + if options.rotate_logs: + logfile_mode = 'a' + + # Setup the logger + deluge.log.setupLogger(level=options.loglevel, filename=options.logfile, + filemode=logfile_mode) + + import deluge.configmanager if options.config: if not deluge.configmanager.set_config_dir(options.config): print("There was an error setting the config dir! Exiting..") @@ -202,8 +222,9 @@ this should be an IP address", metavar="IFACE", os.makedirs(os.path.abspath(os.path.dirname(options.logfile))) except: pass - deluge.log.setupLogger(level=options.loglevel, filename=options.logfile) - from deluge.log import LOG as log + + import logging + log = logging.getLogger(__name__) if options.profile: import hotshot diff --git a/deluge/metafile.py b/deluge/metafile.py index ced93bca9..8e3549a03 100644 --- a/deluge/metafile.py +++ b/deluge/metafile.py @@ -20,10 +20,12 @@ import os import os.path import sys import time +import logging from hashlib import sha1 as sha from deluge.bencode import bencode -from deluge.log import LOG as log + +log = logging.getLogger(__name__) ignore = ['core', 'CVS', 'Thumbs.db', 'desktop.ini'] @@ -180,7 +182,7 @@ def makeinfo(path, piece_length, progress, name = None, if done > 0: pieces.append(sh.digest()) progress(piece_count, num_pieces) - + if name is not None: assert isinstance(name, unicode) name = to_utf8(name) diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index f4707af7d..d9a01af98 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -37,15 +37,16 @@ """PluginManagerBase""" import os.path - +import logging import pkg_resources import deluge.common import deluge.configmanager -from deluge.log import LOG as log import deluge.component as component +log = logging.getLogger(__name__) + METADATA_KEYS = [ "Name", "License", diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py index ad2da5863..4f48a9799 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py @@ -39,7 +39,7 @@ from deluge._libtorrent import lt import os -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager @@ -48,6 +48,8 @@ from twisted.internet.task import LoopingCall, deferLater from twisted.internet import reactor from deluge.event import DelugeEvent +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "watchdirs":{}, "next_id":1 diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py index 0bda2fac2..9ad27cb9f 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py @@ -39,7 +39,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -48,6 +48,8 @@ import os from common import get_resource +log = getPluginLogger(__name__) + class OptionsDialog(): spin_ids = ["max_download_speed", "max_upload_speed", "stop_ratio"] spin_int_ids = ["max_upload_slots", "max_connections"] diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py index a09a819f3..eab62a355 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/webui.py @@ -37,13 +37,15 @@ # statement from all source files in the program, then also delete it here. # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("autoadd.js")] diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/core.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/core.py index 62edc960b..f6ca3f52c 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/core.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/core.py @@ -45,7 +45,7 @@ from twisted.internet.task import LoopingCall from twisted.internet import threads, defer from twisted.web import error -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager @@ -58,6 +58,8 @@ from readers import ReaderParseError # TODO: check return values for deferred callbacks # TODO: review class attributes for redundancy +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "url": "http://deluge-torrent.org/blocklist/nipfilter.dat.gz", "load_on_start": False, @@ -161,7 +163,7 @@ class Core(CorePluginBase): def get_config(self): """ Returns the config dictionary - + :returns: the config dictionary :rtype: dict """ @@ -182,7 +184,7 @@ class Core(CorePluginBase): def get_status(self): """ Returns the status of the plugin - + :returns: the status dict of the plugin :rtype: dict """ @@ -260,7 +262,7 @@ class Core(CorePluginBase): def on_download_complete(self, blocklist): """ Runs any download clean up functions - + :param blocklist: path of blocklist :type blocklist: string :returns: a Deferred which fires when clean up is done @@ -273,7 +275,7 @@ class Core(CorePluginBase): def on_download_error(self, f): """ Recovers from download error - + :param f: failure that occured :type f: Failure :returns: a Deferred if recovery was possible @@ -309,7 +311,7 @@ class Core(CorePluginBase): def import_list(self, blocklist): """ Imports the downloaded blocklist into the session - + :param blocklist: path of blocklist :type blocklist: string :returns: a Deferred that fires when the blocklist has been imported @@ -333,7 +335,7 @@ class Core(CorePluginBase): self.is_importing = True self.num_blocked = 0 self.blocklist = self.core.session.get_ip_filter() - + if not blocklist: blocklist = self.filename @@ -351,7 +353,7 @@ class Core(CorePluginBase): def on_import_complete(self, blocklist): """ Runs any import clean up functions - + :param blocklist: path of blocklist :type blocklist: string :returns: a Deferred that fires when clean up is done @@ -374,7 +376,7 @@ class Core(CorePluginBase): def on_import_error(self, f): """ Recovers from import error - + :param f: failure that occured :type f: Failure :returns: a Deferred if recovery was possible diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py index 2c2ad0038..98c858dae 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py @@ -36,13 +36,15 @@ from datetime import datetime import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client import deluge.component as component import deluge.common from deluge.plugins.pluginbase import GtkPluginBase import common +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): log.debug("Blocklist GtkUI enable..") diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/peerguardian.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/peerguardian.py index c9f0550c6..2d8a0256d 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/peerguardian.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/peerguardian.py @@ -7,7 +7,9 @@ from exceptions import Exception from struct import unpack import gzip, socket -from deluge.log import LOG as log +from deluge.log import getPluginLogger + +log = getPluginLogger(__name__) class PGException(Exception): pass diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/webui.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/webui.py index 572d2b047..2c4e0de4a 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/webui.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/webui.py @@ -36,11 +36,13 @@ import os -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase +log = getPluginLogger(__name__) + #import deluge.ui.webui.lib.newforms_plus as forms #config_page_manager = component.get("ConfigPageManager") diff --git a/deluge/plugins/Example/deluge/plugins/example/core.py b/deluge/plugins/Example/deluge/plugins/example/core.py index 2d78d1bf9..319580c91 100644 --- a/deluge/plugins/Example/deluge/plugins/example/core.py +++ b/deluge/plugins/Example/deluge/plugins/example/core.py @@ -33,12 +33,14 @@ # # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + class Core(CorePluginBase): def enable(self): log.debug("Example core plugin enabled!") diff --git a/deluge/plugins/Example/deluge/plugins/example/gtkui.py b/deluge/plugins/Example/deluge/plugins/example/gtkui.py index 39f1b77a9..9227cd511 100644 --- a/deluge/plugins/Example/deluge/plugins/example/gtkui.py +++ b/deluge/plugins/Example/deluge/plugins/example/gtkui.py @@ -35,12 +35,14 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component import deluge.common +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): pass diff --git a/deluge/plugins/Example/deluge/plugins/example/webui.py b/deluge/plugins/Example/deluge/plugins/example/webui.py index df2efadd5..961cb49e7 100644 --- a/deluge/plugins/Example/deluge/plugins/example/webui.py +++ b/deluge/plugins/Example/deluge/plugins/example/webui.py @@ -33,17 +33,19 @@ # # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): - + scripts = [get_resource("example.js")] - + # The enable and disable methods are not scrictly required on the WebUI # plugins. They are only here if you need to register images/stylesheets # with the webserver. diff --git a/deluge/plugins/Execute/deluge/plugins/execute/core.py b/deluge/plugins/Execute/deluge/plugins/execute/core.py index 123cc63c9..1dda1c802 100644 --- a/deluge/plugins/Execute/deluge/plugins/execute/core.py +++ b/deluge/plugins/Execute/deluge/plugins/execute/core.py @@ -38,13 +38,15 @@ import time import hashlib from subprocess import Popen, PIPE -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component from deluge.configmanager import ConfigManager from deluge.core.rpcserver import export from deluge.event import DelugeEvent +log = getPluginLogger(__name__) + DEFAULT_CONFIG = { "commands": [] } diff --git a/deluge/plugins/Execute/deluge/plugins/execute/gtkui.py b/deluge/plugins/Execute/deluge/plugins/execute/gtkui.py index 82851814f..c1102a76e 100644 --- a/deluge/plugins/Execute/deluge/plugins/execute/gtkui.py +++ b/deluge/plugins/Execute/deluge/plugins/execute/gtkui.py @@ -37,12 +37,14 @@ import os import gtk import pkg_resources -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component import deluge.common +log = getPluginLogger(__name__) + EXECUTE_ID = 0 EXECUTE_EVENT = 1 EXECUTE_COMMAND = 2 diff --git a/deluge/plugins/Execute/deluge/plugins/execute/webui.py b/deluge/plugins/Execute/deluge/plugins/execute/webui.py index 7bdb6d198..cf529119a 100644 --- a/deluge/plugins/Execute/deluge/plugins/execute/webui.py +++ b/deluge/plugins/Execute/deluge/plugins/execute/webui.py @@ -34,13 +34,15 @@ # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("execute.js")] diff --git a/deluge/plugins/Extractor/deluge/plugins/extractor/core.py b/deluge/plugins/Extractor/deluge/plugins/extractor/core.py index 8221b5bc4..d8d5d8fd7 100644 --- a/deluge/plugins/Extractor/deluge/plugins/extractor/core.py +++ b/deluge/plugins/Extractor/deluge/plugins/extractor/core.py @@ -41,12 +41,14 @@ import os from twisted.internet.utils import getProcessValue -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "extract_path": "", "use_name_folder": True diff --git a/deluge/plugins/Extractor/deluge/plugins/extractor/gtkui.py b/deluge/plugins/Extractor/deluge/plugins/extractor/gtkui.py index 9e3bf617b..d27e253ed 100644 --- a/deluge/plugins/Extractor/deluge/plugins/extractor/gtkui.py +++ b/deluge/plugins/Extractor/deluge/plugins/extractor/gtkui.py @@ -39,7 +39,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -47,6 +47,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): self.glade = gtk.glade.XML(get_resource("extractor_prefs.glade")) @@ -89,7 +91,7 @@ class GtkUI(GtkPluginBase): self.glade.get_widget("folderchooser_path").set_current_folder(config["extract_path"]) else: self.glade.get_widget("entry_path").set_text(config["extract_path"]) - + self.glade.get_widget("chk_use_name").set_active(config["use_name_folder"]) client.extractor.get_config().addCallback(on_get_config) diff --git a/deluge/plugins/Extractor/deluge/plugins/extractor/webui.py b/deluge/plugins/Extractor/deluge/plugins/extractor/webui.py index 3cc135bf7..5f198981d 100644 --- a/deluge/plugins/Extractor/deluge/plugins/extractor/webui.py +++ b/deluge/plugins/Extractor/deluge/plugins/extractor/webui.py @@ -37,11 +37,13 @@ # # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): def enable(self): pass diff --git a/deluge/plugins/Feeder/deluge/plugins/feeder/core.py b/deluge/plugins/Feeder/deluge/plugins/feeder/core.py index 0324556e3..ad74c1c23 100644 --- a/deluge/plugins/Feeder/deluge/plugins/feeder/core.py +++ b/deluge/plugins/Feeder/deluge/plugins/feeder/core.py @@ -42,12 +42,14 @@ import threading # for threaded updates import re # for regular expressions from twisted.internet.task import LoopingCall -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "feeds": {}, "filters": {}, diff --git a/deluge/plugins/Feeder/deluge/plugins/feeder/webui.py b/deluge/plugins/Feeder/deluge/plugins/feeder/webui.py index 4769155f3..662e13c5d 100644 --- a/deluge/plugins/Feeder/deluge/plugins/feeder/webui.py +++ b/deluge/plugins/Feeder/deluge/plugins/feeder/webui.py @@ -36,11 +36,13 @@ import feedparser # for proccessing feed entries import os -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import sclient, aclient from deluge.plugins.webuipluginbase import WebUIPluginBase from deluge import component +log = getPluginLogger(__name__) + api = component.get("WebPluginApi") forms = api.forms @@ -54,7 +56,7 @@ class feed_page: items = """%(old)s
  • %(entry)s
  • -
    """ % { "old":items, "entry":item, "link":entries[item]} + """ % { "old":items, "entry":item, "link":entries[item]} return api.render.feeder.feeds(items, feedname) class filter_page: @@ -63,7 +65,7 @@ class filter_page: def GET(self, args): new_filter = new_filter_form() filters = sclient.feeder_get_filters() - + # List filters txt = "" for filter in filters: @@ -83,7 +85,7 @@ class filter_page: class new_filter_form(forms.Form): "basic form for a new label" name = forms.CharField(label="") - + class filter_settings_page: "Class for showing filter settings" @api.deco.deluge_page @@ -117,7 +119,7 @@ class filter_settings_page: opts['max_upload_slots'] = int(-1) """opts['max_upload_slots'] = long(opts['max_upload_slots']) opts['max_connections'] = long(opts['max_connections'])""" - + # TODO filter settings per feed not implemented. opts['feeds'] = [] @@ -151,7 +153,7 @@ class filter_settings_form(forms.Form): """ % list - regex = forms.CharField(_("regular_expression")) + regex = forms.CharField(_("regular_expression")) all_feeds = forms.CheckBox(_("all_feeds")) active = forms.CheckBox(_("active")) @@ -204,7 +206,7 @@ class remove_filter_page: """ - + class WebUI(WebUIPluginBase): #map url's to classes: [(url,class), ..] diff --git a/deluge/plugins/FreeSpace/deluge/plugins/freespace/__init__.py b/deluge/plugins/FreeSpace/deluge/plugins/freespace/__init__.py index 7f5b5704c..b09dc0f57 100644 --- a/deluge/plugins/FreeSpace/deluge/plugins/freespace/__init__.py +++ b/deluge/plugins/FreeSpace/deluge/plugins/freespace/__init__.py @@ -1,7 +1,7 @@ # # __init__.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken diff --git a/deluge/plugins/FreeSpace/deluge/plugins/freespace/common.py b/deluge/plugins/FreeSpace/deluge/plugins/freespace/common.py index 33820b8f6..647e03519 100644 --- a/deluge/plugins/FreeSpace/deluge/plugins/freespace/common.py +++ b/deluge/plugins/FreeSpace/deluge/plugins/freespace/common.py @@ -1,7 +1,7 @@ # # common.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken diff --git a/deluge/plugins/FreeSpace/deluge/plugins/freespace/core.py b/deluge/plugins/FreeSpace/deluge/plugins/freespace/core.py index 6029cfe7a..0e4846a3d 100644 --- a/deluge/plugins/FreeSpace/deluge/plugins/freespace/core.py +++ b/deluge/plugins/FreeSpace/deluge/plugins/freespace/core.py @@ -1,7 +1,7 @@ # # core.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -41,13 +41,15 @@ import os, statvfs from datetime import datetime, timedelta from twisted.internet import task -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase from deluge.event import DelugeEvent import deluge.component as component import deluge.configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + class LowDiskSpaceEvent(DelugeEvent): """Triggered when the available space for a specific path is getting diff --git a/deluge/plugins/FreeSpace/deluge/plugins/freespace/gtkui.py b/deluge/plugins/FreeSpace/deluge/plugins/freespace/gtkui.py index fb0b5d5d8..83d94b3b2 100644 --- a/deluge/plugins/FreeSpace/deluge/plugins/freespace/gtkui.py +++ b/deluge/plugins/FreeSpace/deluge/plugins/freespace/gtkui.py @@ -1,7 +1,7 @@ # # gtkui.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -39,7 +39,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -47,6 +47,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): diff --git a/deluge/plugins/FreeSpace/deluge/plugins/freespace/webui.py b/deluge/plugins/FreeSpace/deluge/plugins/freespace/webui.py index 9bee15849..a2686597b 100644 --- a/deluge/plugins/FreeSpace/deluge/plugins/freespace/webui.py +++ b/deluge/plugins/FreeSpace/deluge/plugins/freespace/webui.py @@ -1,7 +1,7 @@ # # webui.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -37,13 +37,15 @@ # statement from all source files in the program, then also delete it here. # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("freespace.js")] diff --git a/deluge/plugins/FreeSpace/setup.py b/deluge/plugins/FreeSpace/setup.py index 03c732c3f..74d53d0f2 100755 --- a/deluge/plugins/FreeSpace/setup.py +++ b/deluge/plugins/FreeSpace/setup.py @@ -1,7 +1,7 @@ # # setup.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -41,7 +41,7 @@ from setuptools import setup, find_packages __plugin_name__ = "FreeSpace" __author__ = "Pedro Algarvio" -__author_email__ = "ufs@ufsoft.org" +__author_email__ = "pedro@algarvio.me" __version__ = "0.1" __url__ = "http://deluge.ufsoft.org/hg/Notification/" __license__ = "GPLv3" diff --git a/deluge/plugins/Label/deluge/plugins/label/core.py b/deluge/plugins/Label/deluge/plugins/label/core.py index 3380f2744..cf6c7b970 100644 --- a/deluge/plugins/Label/deluge/plugins/label/core.py +++ b/deluge/plugins/Label/deluge/plugins/label/core.py @@ -37,7 +37,7 @@ torrent-label core plugin. adds a status field for tracker. """ -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase from deluge.core.rpcserver import export from deluge.configmanager import ConfigManager @@ -47,6 +47,8 @@ from urlparse import urlparse import traceback import re +log = getPluginLogger(__name__) + RE_VALID = re.compile("[a-z0-9_\-\.]*\Z") KNOWN_STATES = ['Downloading','Seeding','Paused','Checking','Queued','Error'] diff --git a/deluge/plugins/Label/deluge/plugins/label/gtkui/__init__.py b/deluge/plugins/Label/deluge/plugins/label/gtkui/__init__.py index 62e97eab6..81dbe8e52 100644 --- a/deluge/plugins/Label/deluge/plugins/label/gtkui/__init__.py +++ b/deluge/plugins/Label/deluge/plugins/label/gtkui/__init__.py @@ -36,7 +36,7 @@ import os import pkg_resources # access plugin egg -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge import component # for systray from deluge.plugins.pluginbase import GtkPluginBase import gtk, gobject @@ -46,6 +46,8 @@ import sidebar_menu import label_config import submenu +log = getPluginLogger(__name__) + NO_LABEL = "No Label" def cell_data_label(column, cell, model, row, data): diff --git a/deluge/plugins/Label/deluge/plugins/label/gtkui/label_config.py b/deluge/plugins/Label/deluge/plugins/label/gtkui/label_config.py index a434155bb..1288f7165 100644 --- a/deluge/plugins/Label/deluge/plugins/label/gtkui/label_config.py +++ b/deluge/plugins/Label/deluge/plugins/label/gtkui/label_config.py @@ -39,9 +39,11 @@ import os import pkg_resources # access plugin egg import deluge.component as component import deluge.common -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client +log = getPluginLogger(__name__) + class LabelConfig(object): """ diff --git a/deluge/plugins/Label/deluge/plugins/label/gtkui/sidebar_menu.py b/deluge/plugins/Label/deluge/plugins/label/gtkui/sidebar_menu.py index acbd9b591..0bcfb0835 100644 --- a/deluge/plugins/Label/deluge/plugins/label/gtkui/sidebar_menu.py +++ b/deluge/plugins/Label/deluge/plugins/label/gtkui/sidebar_menu.py @@ -40,9 +40,11 @@ import gtk.glade import deluge.component as component import deluge.common -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client +log = getPluginLogger(__name__) + NO_LABEL = "No Label" #helpers: diff --git a/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py b/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py index 085a34c18..a2e12ea57 100644 --- a/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py +++ b/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py @@ -36,11 +36,13 @@ import os import pkg_resources # access plugin egg -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge import component # for systray import gtk, gobject from deluge.ui.client import client +log = getPluginLogger(__name__) + NO_LABEL = "No Label" class LabelMenu(gtk.MenuItem): diff --git a/deluge/plugins/Label/deluge/plugins/label/webui.py b/deluge/plugins/Label/deluge/plugins/label/webui.py index 59ed7af99..1cf7f4c0c 100644 --- a/deluge/plugins/Label/deluge/plugins/label/webui.py +++ b/deluge/plugins/Label/deluge/plugins/label/webui.py @@ -40,11 +40,13 @@ import os import pkg_resources from deluge.common import fspeed -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import WebPluginBase from deluge import component +log = getPluginLogger(__name__) + def get_resource(filename): return pkg_resources.resource_filename("deluge.plugins.label", os.path.join("data", filename)) diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/__init__.py b/deluge/plugins/Notifications/deluge/plugins/notifications/__init__.py index 7f5b5704c..b09dc0f57 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/__init__.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/__init__.py @@ -1,7 +1,7 @@ # # __init__.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/common.py b/deluge/plugins/Notifications/deluge/plugins/notifications/common.py index 337a9a6aa..1c6cb52b0 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/common.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/common.py @@ -1,7 +1,7 @@ # # common.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -39,7 +39,9 @@ from twisted.internet import defer from deluge import component -from deluge.log import LOG as log +from deluge.log import getPluginLogger + +log = getPluginLogger(__name__) try: from deluge.event import known_events diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/core.py b/deluge/plugins/Notifications/deluge/plugins/notifications/core.py index 7831bc3e8..2377d595e 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/core.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/core.py @@ -1,7 +1,7 @@ # # core.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -41,13 +41,15 @@ import smtplib from twisted.internet import defer, threads from deluge import component from deluge.event import known_events -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.configmanager from deluge.core.rpcserver import export from common import CustomNotifications +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "smtp_enabled": False, "smtp_host": "", diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/gtkui.py b/deluge/plugins/Notifications/deluge/plugins/notifications/gtkui.py index ae8909f45..79b272ac8 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/gtkui.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/gtkui.py @@ -1,7 +1,7 @@ # # gtkui.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -41,7 +41,7 @@ from os.path import basename import gtk from twisted.internet import defer -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -51,6 +51,8 @@ import deluge.configmanager # Relative imports from common import get_resource, CustomNotifications +log = getPluginLogger(__name__) + try: import pygame SOUND_AVAILABLE = True diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/test.py b/deluge/plugins/Notifications/deluge/plugins/notifications/test.py index 1ff385d4e..648d4ad0c 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/test.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/test.py @@ -1,15 +1,17 @@ # -*- coding: utf-8 -*- # vim: sw=4 ts=4 fenc=utf-8 et # ============================================================================== -# Copyright © 2009 UfSoft.org - Pedro Algarvio +# Copyright © 2009-2010 UfSoft.org - Pedro Algarvio # # License: BSD - Please view the LICENSE file for additional information. # ============================================================================== -from twisted.internet import reactor, task +from twisted.internet import task from deluge import component from deluge.event import DelugeEvent -from deluge.log import LOG as log +from deluge.log import getPluginLogger + +log = getPluginLogger(__name__) class FooEvent(DelugeEvent): """foo Event""" diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/webui.py b/deluge/plugins/Notifications/deluge/plugins/notifications/webui.py index 3abf447a9..9ab62bdf9 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/webui.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/webui.py @@ -1,7 +1,7 @@ # # webui.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -38,7 +38,7 @@ # from twisted.internet import defer -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase @@ -47,6 +47,8 @@ import deluge.configmanager # Relative imports from common import get_resource +log = getPluginLogger(__name__) + DEFAULT_PREFS = { # FLASH "flash_enabled": False, diff --git a/deluge/plugins/Notifications/setup.py b/deluge/plugins/Notifications/setup.py index e94589e37..2e4797364 100755 --- a/deluge/plugins/Notifications/setup.py +++ b/deluge/plugins/Notifications/setup.py @@ -1,7 +1,7 @@ # # setup.py # -# Copyright (C) 2009 Pedro Algarvio +# Copyright (C) 2009-2010 Pedro Algarvio # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -41,7 +41,7 @@ from setuptools import setup, find_packages __plugin_name__ = "Notifications" __author__ = "Pedro Algarvio" -__author_email__ = "ufs@ufsoft.org" +__author_email__ = "pedro@algarvio.me" __version__ = "0.1" __url__ = "http://dev.deluge-torrent.org/" __license__ = "GPLv3" diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/core.py b/deluge/plugins/Scheduler/deluge/plugins/scheduler/core.py index c3c5008ea..f810fff71 100644 --- a/deluge/plugins/Scheduler/deluge/plugins/scheduler/core.py +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/core.py @@ -38,7 +38,7 @@ import time -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager @@ -47,6 +47,8 @@ from deluge.event import DelugeEvent from twisted.internet import reactor +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "low_down": -1.0, "low_up": -1.0, diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py b/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py index 73d156285..2bf73cbd3 100644 --- a/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/gtkui.py @@ -38,7 +38,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -46,6 +46,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] class SchedulerSelectWidget(gtk.DrawingArea): diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/webui.py b/deluge/plugins/Scheduler/deluge/plugins/scheduler/webui.py index f7f82d242..fd06cfe8e 100644 --- a/deluge/plugins/Scheduler/deluge/plugins/scheduler/webui.py +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/webui.py @@ -36,13 +36,15 @@ # statement from all source files in the program, then also delete it here. # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("scheduler.js")] diff --git a/deluge/plugins/Stats/deluge/plugins/stats/core.py b/deluge/plugins/Stats/deluge/plugins/stats/core.py index e6af5e2d1..b16aa7c8f 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/core.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/core.py @@ -48,12 +48,14 @@ from twisted.internet.task import LoopingCall import time import deluge -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase from deluge import component from deluge import configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "test": "NiNiNi", "update_interval": 2, #2 seconds. diff --git a/deluge/plugins/Stats/deluge/plugins/stats/graph.py b/deluge/plugins/Stats/deluge/plugins/stats/graph.py index 2fba2d7d2..8432bc2e9 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/graph.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/graph.py @@ -48,7 +48,7 @@ port of old plugin by markybob. """ import time import cairo -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client black = (0, 0, 0) @@ -60,6 +60,8 @@ green = (0, 1.0, 0) blue = (0, 0, 1.0) orange = (1.0, 0.74, 0) +log = getPluginLogger(__name__) + def default_formatter(value): return str(value) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py index 30888ed37..b2ed73730 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py @@ -53,12 +53,14 @@ from twisted.internet import defer import graph from deluge import component -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.common import fspeed from deluge.ui.client import client from deluge.ui.gtkui.torrentdetails import Tab from deluge.plugins.pluginbase import GtkPluginBase +log = getPluginLogger(__name__) + class GraphsTab(Tab): def __init__(self, glade): Tab.__init__(self) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/webui.py b/deluge/plugins/Stats/deluge/plugins/stats/webui.py index b1a235297..d78ff86c9 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/webui.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/webui.py @@ -33,17 +33,19 @@ # # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): - + scripts = [get_resource("stats.js")] - + # The enable and disable methods are not scrictly required on the WebUI # plugins. They are only here if you need to register images/stylesheets # with the webserver. diff --git a/deluge/plugins/Toggle/deluge/plugins/toggle/core.py b/deluge/plugins/Toggle/deluge/plugins/toggle/core.py index ccd0fcc88..1e229c180 100644 --- a/deluge/plugins/Toggle/deluge/plugins/toggle/core.py +++ b/deluge/plugins/Toggle/deluge/plugins/toggle/core.py @@ -37,12 +37,14 @@ # statement from all source files in the program, then also delete it here. # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + DEFAULT_PREFS = { } diff --git a/deluge/plugins/Toggle/deluge/plugins/toggle/gtkui.py b/deluge/plugins/Toggle/deluge/plugins/toggle/gtkui.py index da019692d..eb2941269 100644 --- a/deluge/plugins/Toggle/deluge/plugins/toggle/gtkui.py +++ b/deluge/plugins/Toggle/deluge/plugins/toggle/gtkui.py @@ -39,7 +39,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -47,6 +47,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): self.core = client.toggle diff --git a/deluge/plugins/Toggle/deluge/plugins/toggle/webui.py b/deluge/plugins/Toggle/deluge/plugins/toggle/webui.py index a4ddfc6b7..023085a05 100644 --- a/deluge/plugins/Toggle/deluge/plugins/toggle/webui.py +++ b/deluge/plugins/Toggle/deluge/plugins/toggle/webui.py @@ -37,13 +37,15 @@ # statement from all source files in the program, then also delete it here. # -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("toggle.js")] diff --git a/deluge/plugins/WebUi/deluge/plugins/webui/core.py b/deluge/plugins/WebUi/deluge/plugins/webui/core.py index 9ad4abd4e..3f5fb8686 100644 --- a/deluge/plugins/WebUi/deluge/plugins/webui/core.py +++ b/deluge/plugins/WebUi/deluge/plugins/webui/core.py @@ -39,10 +39,12 @@ import os from deluge import common, component, configmanager -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.plugins.pluginbase import CorePluginBase from deluge.core.rpcserver import export +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "enabled": False, "ssl": False, @@ -50,8 +52,8 @@ DEFAULT_PREFS = { } class Core(CorePluginBase): - - + + def enable(self): self.config = configmanager.ConfigManager("web_plugin.conf", DEFAULT_PREFS) self.server = None @@ -64,13 +66,13 @@ class Core(CorePluginBase): def update(self): pass - + def restart(self): if self.server: self.server.stop().addCallback(self.on_stop) else: self.start() - + def on_stop(self, *args): self.start() @@ -81,7 +83,7 @@ class Core(CorePluginBase): return True except ImportError: return False - + @export def start(self): if not self.server: @@ -96,7 +98,7 @@ class Core(CorePluginBase): self.server.https = self.config["ssl"] self.server.start(False) return True - + @export def stop(self): if self.server: @@ -110,7 +112,7 @@ class Core(CorePluginBase): if "enabled" in config: if config["enabled"] != self.config["enabled"]: action = config["enabled"] and 'start' or 'stop' - + if "ssl" in config: if not action: action = 'restart' @@ -118,7 +120,7 @@ class Core(CorePluginBase): for key in config.keys(): self.config[key] = config[key] self.config.save() - + if action == 'start': return self.start() elif action == 'stop': diff --git a/deluge/plugins/WebUi/deluge/plugins/webui/gtkui.py b/deluge/plugins/WebUi/deluge/plugins/webui/gtkui.py index fc45eee42..47b02e9ab 100644 --- a/deluge/plugins/WebUi/deluge/plugins/webui/gtkui.py +++ b/deluge/plugins/WebUi/deluge/plugins/webui/gtkui.py @@ -38,7 +38,7 @@ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -46,6 +46,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): self.glade = gtk.glade.XML(get_resource("config.glade")) @@ -80,7 +82,7 @@ class GtkUI(GtkPluginBase): self.glade.get_widget("enabled_checkbutton").set_active(config["enabled"]) self.glade.get_widget("ssl_checkbutton").set_active(config["ssl"]) self.glade.get_widget("port_spinbutton").set_value(config["port"]) - + def cb_chk_deluge_web(self, have_web): self.have_web = have_web if have_web: diff --git a/deluge/plugins/init.py b/deluge/plugins/init.py index f445e2303..341ec369a 100644 --- a/deluge/plugins/init.py +++ b/deluge/plugins/init.py @@ -36,7 +36,9 @@ """ This base class is used in plugin's __init__ for the plugin entry points. """ -from deluge.log import LOG as log +import logging + +log = logging.getLogger(__name__) class PluginInitBase(object): _plugin_cls = None diff --git a/deluge/plugins/pluginbase.py b/deluge/plugins/pluginbase.py index 18a406e4a..a59aab754 100644 --- a/deluge/plugins/pluginbase.py +++ b/deluge/plugins/pluginbase.py @@ -33,8 +33,10 @@ # # +import logging import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class PluginBase(component.Component): @@ -42,7 +44,7 @@ class PluginBase(component.Component): def __init__(self, name): super(PluginBase, self).__init__(name, self.update_interval) - + def enable(self): raise NotImplementedError("Need to define an enable method!") @@ -62,20 +64,20 @@ class GtkPluginBase(PluginBase): log.debug("GtkPlugin initialized..") class WebPluginBase(PluginBase): - + scripts = [] debug_scripts = [] - + stylesheets = [] debug_stylesheets = [] - + def __init__(self, plugin_name): super(WebPluginBase, self).__init__("WebPlugin." + plugin_name) - + # Register JSON rpc methods component.get("JSON").register_object(self, plugin_name.lower()) log.debug("WebPlugin initialized..") - + def enable(self): pass diff --git a/deluge/scripts/create_plugin.py b/deluge/scripts/create_plugin.py index c35a5c711..a26b1e6ae 100644 --- a/deluge/scripts/create_plugin.py +++ b/deluge/scripts/create_plugin.py @@ -7,6 +7,7 @@ python create_plugin.py --name MyPlugin2 --basepath . --author-name "Your Name" """ +from datetime import datetime from optparse import OptionParser import os import deluge.common @@ -73,7 +74,8 @@ def create_plugin(): "filename": filename, "plugin_base": plugin_base, "url": options.url, - "configdir": options.configdir + "configdir": options.configdir, + "current_year": datetime.utcnow().year } filename = os.path.join(path, filename) @@ -111,7 +113,6 @@ def create_plugin(): CORE = """ -from deluge.log import LOG as log from deluge.plugins.pluginbase import CorePluginBase import deluge.component as component import deluge.configmanager @@ -206,6 +207,7 @@ setup( """ COMMON = """ + def get_resource(filename): import pkg_resources, os return pkg_resources.resource_filename("deluge.plugins.%(safe_name)s", @@ -215,7 +217,7 @@ def get_resource(filename): GTKUI = """ import gtk -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge.plugins.pluginbase import GtkPluginBase import deluge.component as component @@ -223,6 +225,8 @@ import deluge.common from common import get_resource +log = getPluginLogger(__name__) + class GtkUI(GtkPluginBase): def enable(self): self.glade = gtk.glade.XML(get_resource("config.glade")) @@ -281,13 +285,15 @@ GLADE = """ """ WEBUI = """ -from deluge.log import LOG as log +from deluge.log import getPluginLogger from deluge.ui.client import client from deluge import component from deluge.plugins.pluginbase import WebPluginBase from common import get_resource +log = getPluginLogger(__name__) + class WebUI(WebPluginBase): scripts = [get_resource("%(safe_name)s.js")] @@ -304,7 +310,7 @@ Script: %(filename)s The client-side javascript code for the %(name)s plugin. Copyright: - (C) %(author_name)s 2009 <%(author_email)s> + (C) %(author_name)s %(current_year)s <%(author_email)s> 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 3, or (at your option) @@ -354,7 +360,7 @@ new %(name)sPlugin(); GPL = """# # %(filename)s # -# Copyright (C) 2009 %(author_name)s <%(author_email)s> +# Copyright (C) %(current_year)d %(author_name)s <%(author_email)s> # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken diff --git a/deluge/tests/test_log.py b/deluge/tests/test_log.py new file mode 100644 index 000000000..3ca23f9d3 --- /dev/null +++ b/deluge/tests/test_log.py @@ -0,0 +1,21 @@ +import logging +from twisted.internet import defer +from twisted.trial import unittest +from deluge.log import setupLogger + +class LogTestCase(unittest.TestCase): + def setUp(self): + setupLogger(logging.DEBUG) + + def tearDown(self): + pass + + def test_old_LOG_deprecation_warning(self): + import warnings + from deluge.log import LOG + warnings.filterwarnings("ignore", category=DeprecationWarning, + module="deluge.tests.test_log") + d = defer.Deferred() + d.addCallback(LOG.debug, "foo") + self.assertFailure(d, DeprecationWarning) + warnings.resetwarnings() diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 1a4506691..9852b2998 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -33,6 +33,7 @@ # # +import logging from twisted.internet.protocol import Protocol, ClientFactory from twisted.internet import reactor, ssl, defer try: @@ -44,7 +45,6 @@ import zlib import deluge.common import deluge.component as component -from deluge.log import LOG as log from deluge.event import known_events if deluge.common.windows_check(): @@ -56,6 +56,8 @@ RPC_RESPONSE = 1 RPC_ERROR = 2 RPC_EVENT = 3 +log = logging.getLogger(__name__) + def format_kwargs(kwargs): return ", ".join([key + "=" + str(value) for key, value in kwargs.items()]) diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 5f53db84e..fb9048d01 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -40,6 +40,7 @@ all the interfaces. import os import sys +import logging import urlparse import locale @@ -51,9 +52,10 @@ except ImportError: from deluge import bencode from deluge.common import decode_string, path_join -from deluge.log import LOG as log import deluge.configmanager +log = logging.getLogger(__name__) + class TorrentInfo(object): """ Collects information about a torrent file. diff --git a/deluge/ui/console/commands/config.py b/deluge/ui/console/commands/config.py index 54ef15ee5..e74ad344e 100644 --- a/deluge/ui/console/commands/config.py +++ b/deluge/ui/console/commands/config.py @@ -34,18 +34,20 @@ # # +import re +import logging +import tokenize +import cStringIO +from optparse import make_option + from twisted.internet import defer from deluge.ui.console.main import BaseCommand import deluge.ui.console.colors as colors from deluge.ui.client import client import deluge.component as component -from deluge.log import LOG as log -from optparse import make_option -import re - -import cStringIO, tokenize +log = logging.getLogger(__name__) def atom(next, token): """taken with slight modifications from http://effbot.org/zone/simple-iterator-parser.htm""" diff --git a/deluge/ui/console/eventlog.py b/deluge/ui/console/eventlog.py index c5caddf68..351186dd8 100644 --- a/deluge/ui/console/eventlog.py +++ b/deluge/ui/console/eventlog.py @@ -34,12 +34,13 @@ # +import logging import deluge.component as component import deluge.common import colors from deluge.ui.client import client -from deluge.log import LOG as log +log = logging.getLogger(__name__) class EventLog(component.Component): """ diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index 7d5e1a91a..6ea3adb79 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -34,7 +34,9 @@ # # -import os, sys +import os +import sys +import logging import optparse import shlex import locale @@ -50,9 +52,10 @@ from deluge.ui.console.statusbars import StatusBars from deluge.ui.console.eventlog import EventLog import screen import colors -from deluge.log import LOG as log from deluge.ui.ui import _UI +log = logging.getLogger(__name__) + class Console(_UI): help = """Starts the Deluge console interface""" diff --git a/deluge/ui/console/screen.py b/deluge/ui/console/screen.py index ad0da738f..bf6b53190 100644 --- a/deluge/ui/console/screen.py +++ b/deluge/ui/console/screen.py @@ -34,6 +34,7 @@ # import sys +import logging try: import curses except ImportError: @@ -48,9 +49,10 @@ try: except: pass -from deluge.log import LOG as log from twisted.internet import reactor +log = logging.getLogger(__name__) + class CursesStdIO(object): """fake fd to be registered as a reader with the twisted reactor. Curses classes needing input should extend this""" diff --git a/deluge/ui/coreconfig.py b/deluge/ui/coreconfig.py index 7028936c1..fe002e64a 100644 --- a/deluge/ui/coreconfig.py +++ b/deluge/ui/coreconfig.py @@ -34,9 +34,11 @@ # +import logging import deluge.component as component from deluge.ui.client import client -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class CoreConfig(component.Component): def __init__(self): diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 62e769de8..a4fb421f0 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -36,10 +36,12 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade import gettext import gobject import base64 +import logging import os import pkg_resources @@ -48,12 +50,13 @@ from deluge.ui.client import client import deluge.component as component import listview from deluge.configmanager import ConfigManager -from deluge.log import LOG as log import deluge.common import deluge.ui.common import dialogs import common +log = logging.getLogger(__name__) + class AddTorrentDialog(component.Component): def __init__(self): component.Component.__init__(self, "AddTorrentDialog") diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index 5b25fa537..b584c81b7 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -39,15 +39,17 @@ import os import pygtk pygtk.require('2.0') -import gtk, gtk.glade - +import gtk +import gtk.glade +import logging import pkg_resources from deluge.ui.client import client import deluge.component as component -from deluge.log import LOG as log import deluge.common +log = logging.getLogger(__name__) + def get_logo(size): """Returns a deluge logo pixbuf based on the size parameter.""" if deluge.common.windows_check() or deluge.common.osx_check(): diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 3b9ddf417..96fef9d1d 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -38,6 +38,7 @@ import pkg_resources import urlparse import time import hashlib +import logging from twisted.internet import reactor import deluge.component as component @@ -48,9 +49,10 @@ from deluge.ui.client import client import deluge.ui.client import deluge.ui.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log import dialogs +log = logging.getLogger(__name__) + DEFAULT_HOST = "127.0.0.1" DEFAULT_PORT = 58846 diff --git a/deluge/ui/gtkui/createtorrentdialog.py b/deluge/ui/gtkui/createtorrentdialog.py index 5624a634f..2fb7b689a 100644 --- a/deluge/ui/gtkui/createtorrentdialog.py +++ b/deluge/ui/gtkui/createtorrentdialog.py @@ -40,6 +40,7 @@ import pkg_resources import os.path import gobject import base64 +import logging from twisted.internet.threads import deferToThread @@ -48,7 +49,8 @@ import listview import deluge.component as component import deluge.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class CreateTorrentDialog: def show(self): diff --git a/deluge/ui/gtkui/details_tab.py b/deluge/ui/gtkui/details_tab.py index 411d38423..96f39cfbf 100644 --- a/deluge/ui/gtkui/details_tab.py +++ b/deluge/ui/gtkui/details_tab.py @@ -34,14 +34,16 @@ # -import gtk, gtk.glade +import gtk +import gtk.glade +import logging from deluge.ui.client import client import deluge.component as component from deluge.common import fsize, is_url from deluge.ui.gtkui.torrentdetails import Tab -from deluge.log import LOG as log +log = logging.getLogger(__name__) class DetailsTab(Tab): def __init__(self): diff --git a/deluge/ui/gtkui/edittrackersdialog.py b/deluge/ui/gtkui/edittrackersdialog.py index d710cc6c6..2c9dc73a6 100644 --- a/deluge/ui/gtkui/edittrackersdialog.py +++ b/deluge/ui/gtkui/edittrackersdialog.py @@ -34,14 +34,17 @@ # -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import pkg_resources import deluge.common import common from deluge.ui.client import client import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class EditTrackersDialog: def __init__(self, torrent_id, parent=None): diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py index 9b195a35d..1fc0ccba8 100644 --- a/deluge/ui/gtkui/files_tab.py +++ b/deluge/ui/gtkui/files_tab.py @@ -34,11 +34,14 @@ # -import gtk, gtk.glade, gtk.gdk +import gtk +import gtk.gdk +import gtk.glade import gobject import gettext import os.path import cPickle +import logging from deluge.ui.gtkui.torrentdetails import Tab from deluge.ui.client import client @@ -48,7 +51,7 @@ import deluge.component as component import deluge.common import common -from deluge.log import LOG as log +log = logging.getLogger(__name__) def cell_priority(column, cell, model, row, data): if model.get_value(row, 5) == -1: diff --git a/deluge/ui/gtkui/filtertreeview.py b/deluge/ui/gtkui/filtertreeview.py index 1438c70dc..d7a242840 100644 --- a/deluge/ui/gtkui/filtertreeview.py +++ b/deluge/ui/gtkui/filtertreeview.py @@ -37,14 +37,16 @@ import gtk import gtk.glade +import logging import pkg_resources import deluge.component as component import deluge.common -from deluge.log import LOG as log from deluge.ui.client import client from deluge.configmanager import ConfigManager +log = logging.getLogger(__name__) + STATE_PIX = { "All": "all", "Downloading": "downloading", @@ -126,7 +128,7 @@ class FilterTreeView(component.Component): # Force the theme to use an expander-size of 15 so that we don't cut out # entries due to our indentation hack. gtk.rc_parse_string('style "treeview-style" { GtkTreeView::expander-size = 15 } class "GtkTreeView" style "treeview-style"') - + self.label_view.set_model(self.treestore) self.label_view.get_selection().connect("changed", self.on_selection_changed) self.create_model_filter() diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 3ff092495..1609a2869 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -32,7 +32,6 @@ # statement from all source files in the program, then also delete it here. # # -from deluge.log import LOG as log # Install the twisted reactor from twisted.internet import gtk2reactor @@ -42,8 +41,12 @@ import gobject import gettext import locale import pkg_resources -import gtk, gtk.glade +import gtk +import gtk.glade import sys +import logging + +log = logging.getLogger(__name__) # Initialize gettext try: diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index dc2f917ea..f63a8a45c 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -37,22 +37,24 @@ import sys import os import base64 +import logging try: import rencode except ImportError: import deluge.rencode as rencode - + import deluge.component as component from deluge.ui.client import client import deluge.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log from twisted.internet.protocol import Factory, Protocol, ClientFactory from twisted.internet import reactor import twisted.internet.error +log = logging.getLogger(__name__) + class IPCProtocolServer(Protocol): def dataReceived(self, data): data = rencode.loads(data) @@ -62,11 +64,11 @@ class IPCProtocolClient(Protocol): def connectionMade(self): self.transport.write(rencode.dumps(self.factory.args)) self.transport.loseConnection() - + def connectionLost(self, reason): reactor.stop() self.factory.stop = True - + class IPCClientFactory(ClientFactory): protocol = IPCProtocolClient @@ -74,11 +76,11 @@ class IPCClientFactory(ClientFactory): self.stop = False self.args = args self.connect_failed = connect_failed - + def clientConnectionFailed(self, connector, reason): log.info("Connection to running instance failed. Starting new one..") reactor.stop() - + class IPCInterface(component.Component): def __init__(self, args): component.Component.__init__(self, "IPCInterface") @@ -165,7 +167,7 @@ class IPCInterface(component.Component): os.remove(socket) except Exception, e: log.error("Unable to remove socket file: %s", e) - + lock = socket + ".lock" if os.path.lexists(lock): try: @@ -180,7 +182,7 @@ class IPCInterface(component.Component): log.error("Unable to start IPC listening socket: %s", e) finally: process_args(args) - + def shutdown(self): if deluge.common.windows_check(): import win32api diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index c083fad76..9a2aed9a6 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -37,6 +37,7 @@ import cPickle import os.path +import logging import pygtk pygtk.require('2.0') @@ -46,13 +47,13 @@ import gettext from deluge.configmanager import ConfigManager import deluge.configmanager import deluge.common -from deluge.log import LOG as log from gobject import signal_new, SIGNAL_RUN_LAST, TYPE_NONE from gtk import gdk signal_new('button-press-event', gtk.TreeViewColumn, SIGNAL_RUN_LAST, TYPE_NONE, (gdk.Event,)) +log = logging.getLogger(__name__) # Cell data functions to pass to add_func_column() def cell_data_speed(column, cell, model, row, data): diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 0190976e7..bc582c439 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -36,8 +36,10 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade import gobject +import logging import pkg_resources from urlparse import urlparse import urllib @@ -51,7 +53,7 @@ from twisted.internet import reactor import deluge.common import common -from deluge.log import LOG as log +log = logging.getLogger(__name__) class MainWindow(component.Component): def __init__(self): diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index 8a4cb8c0a..ce80e5463 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -36,7 +36,9 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import pkg_resources import deluge.error @@ -46,7 +48,7 @@ import deluge.common import common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log +log = logging.getLogger(__name__) class MenuBar(component.Component): def __init__(self): diff --git a/deluge/ui/gtkui/notification.py b/deluge/ui/gtkui/notification.py index fe2d1e0e9..7e17fa9d2 100644 --- a/deluge/ui/gtkui/notification.py +++ b/deluge/ui/gtkui/notification.py @@ -34,13 +34,15 @@ # +import logging import deluge.component as component import deluge.common import common -from deluge.log import LOG as log from deluge.configmanager import ConfigManager from deluge.ui.client import client +log = logging.getLogger(__name__) + class Notification: def __init__(self): self.config = ConfigManager("gtkui.conf") @@ -53,7 +55,9 @@ class Notification: self.get_torrent_status(torrent_id) def get_torrent_status(self, torrent_id): - component.get("SessionProxy").get_torrent_status(torrent_id, ["name", "num_files", "total_payload_download"]).addCallback(self._on_get_torrent_status) + component.get("SessionProxy").get_torrent_status(torrent_id, [ + "name", "num_files", "total_payload_download" + ]).addCallback(self._on_get_torrent_status) def _on_get_torrent_status(self, status): if status is None: @@ -77,7 +81,10 @@ class Notification: if not pynotify.init("Deluge"): return title = deluge.common.xml_encode(_("Torrent complete")) - message = deluge.common.xml_encode(status["name"] + "\n" + _("Including %i files" % status["num_files"])) + message = deluge.common.xml_encode( + status["name"] + "\n" + + _("Including %i files" % status["num_files"]) + ) self.note = pynotify.Notification(title, message) self.note.set_icon_from_pixbuf(common.get_logo(48)) if not self.note.show(): @@ -106,9 +113,12 @@ class Notification: headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % ( self.config["ntf_email_add"], self.config["ntf_email_add"], "Finished torrent %s" % (status["name"])) - text = _("This email is to inform you that Deluge has finished downloading %(name)s , \ - which includes %(num_files)i files.\nTo stop receiving these alerts, simply turn off \ - email notification in Deluge's preferences.\n\nThank you,\nDeluge") % {"name": status["name"], "num_files": status["num_files"]} + text = _("This email is to inform you that Deluge has finished " + "downloading %(name)s , which includes %(num_files)i files.\n" + "To stop receiving these alerts, simply turn off email " + "notification in Deluge's preferences.\n\n" + "Thank you,\nDeluge") % {"name": status["name"], + "num_files": status["num_files"]} message = headers + text if self.config["ntf_security"] == 'SSL': port = 465 diff --git a/deluge/ui/gtkui/peers_tab.py b/deluge/ui/gtkui/peers_tab.py index 9e4b92dda..9ac5a6de9 100644 --- a/deluge/ui/gtkui/peers_tab.py +++ b/deluge/ui/gtkui/peers_tab.py @@ -34,7 +34,9 @@ # -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import os.path import cPickle import pkg_resources @@ -48,9 +50,10 @@ import deluge.component as component import deluge.common from deluge.ui.gtkui.listview import cell_data_speed as cell_data_speed from deluge.ui.gtkui.torrentdetails import Tab -from deluge.log import LOG as log from deluge.ui.countries import COUNTRIES +log = logging.getLogger(__name__) + def cell_data_progress(column, cell, model, row, data): value = model.get_value(row, data) cell.set_property("value", value * 100) diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 5bbbef351..8c4ffdc88 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -34,11 +34,13 @@ # +import logging import deluge.component as component import deluge.pluginmanagerbase from deluge.ui.client import client from deluge.configmanager import ConfigManager -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Component): diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 0f9a21915..28aa8762d 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -36,11 +36,12 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import pkg_resources import deluge.component as component -from deluge.log import LOG as log from deluge.ui.client import client import deluge.common import deluge.error @@ -48,13 +49,15 @@ import common from deluge.configmanager import ConfigManager import deluge.configmanager +log = logging.getLogger(__name__) + class Preferences(component.Component): def __init__(self): component.Component.__init__(self, "Preferences") self.window = component.get("MainWindow") - self.glade = gtk.glade.XML( - pkg_resources.resource_filename("deluge.ui.gtkui", - "glade/preferences_dialog.glade")) + self.glade = gtk.glade.XML(pkg_resources.resource_filename( + "deluge.ui.gtkui", "glade/preferences_dialog.glade" + )) self.pref_dialog = self.glade.get_widget("pref_dialog") self.pref_dialog.set_icon(common.get_deluge_icon()) self.treeview = self.glade.get_widget("treeview") diff --git a/deluge/ui/gtkui/queuedtorrents.py b/deluge/ui/gtkui/queuedtorrents.py index fa18a1f87..652473c2c 100644 --- a/deluge/ui/gtkui/queuedtorrents.py +++ b/deluge/ui/gtkui/queuedtorrents.py @@ -36,7 +36,9 @@ import base64 import os.path -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import gobject import pkg_resources @@ -44,9 +46,10 @@ import deluge.component as component from deluge.ui.client import client import deluge.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log import common +log = logging.getLogger(__name__) + class QueuedTorrents(component.Component): def __init__(self): component.Component.__init__(self, "QueuedTorrents", depend=["StatusBar", "AddTorrentDialog"]) @@ -176,7 +179,7 @@ class QueuedTorrents(component.Component): if self.config["interactive_add"]: def on_show(result): component.get("AddTorrentDialog").add_from_url(torrent_path) - + d = component.get("AddTorrentDialog").show(self.config["focus_add_dialog"]) d.addCallback(on_show) else: diff --git a/deluge/ui/gtkui/removetorrentdialog.py b/deluge/ui/gtkui/removetorrentdialog.py index 071992ba5..36257eed0 100644 --- a/deluge/ui/gtkui/removetorrentdialog.py +++ b/deluge/ui/gtkui/removetorrentdialog.py @@ -33,12 +33,15 @@ # # -import gtk, gtk.glade +import gtk +import gtk.glade +import logging import pkg_resources from deluge.ui.client import client import deluge.component as component -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class RemoveTorrentDialog(object): """ diff --git a/deluge/ui/gtkui/sidebar.py b/deluge/ui/gtkui/sidebar.py index 7c1768b37..1b1cca129 100644 --- a/deluge/ui/gtkui/sidebar.py +++ b/deluge/ui/gtkui/sidebar.py @@ -37,11 +37,13 @@ import gtk import gtk.glade +import logging import deluge.component as component import deluge.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class SideBar(component.Component): """ diff --git a/deluge/ui/gtkui/status_tab.py b/deluge/ui/gtkui/status_tab.py index 6feed8ed9..255c303cc 100644 --- a/deluge/ui/gtkui/status_tab.py +++ b/deluge/ui/gtkui/status_tab.py @@ -35,13 +35,16 @@ # -import gtk, gtk.glade +import gtk +import gtk.glade +import logging from deluge.ui.client import client import deluge.component as component import deluge.common from deluge.ui.gtkui.torrentdetails import Tab -from deluge.log import LOG as log + +log = logging.getLogger(__name__) def fpeer_sized(first, second): return "%s (%s)" % (deluge.common.fsize(first), deluge.common.fsize(second)) diff --git a/deluge/ui/gtkui/statusbar.py b/deluge/ui/gtkui/statusbar.py index ff350aeab..52f8c7fb5 100644 --- a/deluge/ui/gtkui/statusbar.py +++ b/deluge/ui/gtkui/statusbar.py @@ -36,13 +36,15 @@ import gtk import gobject +import logging from deluge.ui.client import client import deluge.component as component import deluge.common import common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log + +log = logging.getLogger(__name__) class StatusBarItem: def __init__(self, image=None, stock=None, text=None, callback=None, tooltip=None): diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index a9eaffbeb..5a193358e 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -35,15 +35,17 @@ import gtk +import logging import pkg_resources import deluge.component as component from deluge.ui.client import client import deluge.common from deluge.configmanager import ConfigManager -from deluge.log import LOG as log import common +log = logging.getLogger(__name__) + class SystemTray(component.Component): def __init__(self): component.Component.__init__(self, "SystemTray", interval=4) diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index 81b0c3e8e..5099fd54d 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -36,15 +36,18 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade import gobject +import logging import deluge.component as component from deluge.ui.client import client -from deluge.log import LOG as log from deluge.common import TORRENT_STATE from deluge.configmanager import ConfigManager +log = logging.getLogger(__name__) + class ToolBar(component.Component): def __init__(self): component.Component.__init__(self, "ToolBar") diff --git a/deluge/ui/gtkui/torrentdetails.py b/deluge/ui/gtkui/torrentdetails.py index 035e3ac4f..6241a218f 100644 --- a/deluge/ui/gtkui/torrentdetails.py +++ b/deluge/ui/gtkui/torrentdetails.py @@ -36,17 +36,19 @@ """The torrent details component shows info about the selected torrent.""" -import gtk, gtk.glade +import gtk +import gtk.glade import os import os.path import cPickle +import logging import deluge.component as component from deluge.ui.client import client from deluge.configmanager import ConfigManager import deluge.configmanager -from deluge.log import LOG as log +log = logging.getLogger(__name__) class Tab: def __init__(self): diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index f0573d98a..52590afae 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -38,19 +38,22 @@ import pygtk pygtk.require('2.0') -import gtk, gtk.glade +import gtk +import gtk.glade import gettext import gobject +import logging from urlparse import urlparse import deluge.common import deluge.component as component from deluge.ui.client import client -from deluge.log import LOG as log import listview from deluge.ui.tracker_icons import TrackerIcons from removetorrentdialog import RemoveTorrentDialog +log = logging.getLogger(__name__) + # Status icons.. Create them from file only once to avoid constantly # re-creating them. icon_downloading = gtk.gdk.pixbuf_new_from_file( diff --git a/deluge/ui/sessionproxy.py b/deluge/ui/sessionproxy.py index 9519edfd1..4fc53d85b 100644 --- a/deluge/ui/sessionproxy.py +++ b/deluge/ui/sessionproxy.py @@ -33,13 +33,15 @@ # # +import logging from twisted.internet.defer import maybeDeferred, succeed import deluge.component as component from deluge.ui.client import client -from deluge.log import LOG as log import time +log = logging.getLogger(__name__) + class SessionProxy(component.Component): """ The SessionProxy component is used to cache session information client-side diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index 91a02e46e..008783696 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -34,6 +34,7 @@ # import os +import logging from HTMLParser import HTMLParser, HTMLParseError from urlparse import urljoin, urlparse from tempfile import mkstemp @@ -45,7 +46,7 @@ from deluge.component import Component from deluge.configmanager import get_config_dir from deluge.httpdownloader import download_file from deluge.decorators import proxy -from deluge.log import LOG as log + try: import PIL.Image as Image @@ -55,6 +56,8 @@ except ImportError: else: PIL_INSTALLED = True +log = logging.getLogger(__name__) + class TrackerIcon(object): """ Represents a tracker's icon diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py index b210e2d1d..06fe76c4e 100644 --- a/deluge/ui/ui.py +++ b/deluge/ui/ui.py @@ -33,6 +33,7 @@ # # +import logging from optparse import OptionParser, OptionGroup import deluge.common import deluge.configmanager @@ -65,6 +66,8 @@ class _UI(object): help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") group.add_option("-q", "--quiet", dest="quiet", help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) + group.add_option("-r", "--rotate-logs", + help="Rotate logfiles.", action="store_true", default=False) self.__parser.add_option_group(group) @property @@ -89,9 +92,17 @@ class _UI(object): if self.__options.quiet: self.__options.loglevel = "none" + logfile_mode = 'w' + if self.__options.rotate_logs: + logfile_mode = 'a' + # Setup the logger - deluge.log.setupLogger(level=self.__options.loglevel, filename=self.__options.logfile) - log = deluge.log.LOG + # Setup the logger + deluge.log.setupLogger(level=self.__options.loglevel, + filename=self.__options.logfile, + filemode=logfile_mode) + + log = logging.getLogger(__name__) if self.__options.config: if not deluge.configmanager.set_config_dir(self.__options.config): @@ -105,7 +116,8 @@ class _UI(object): class UI: def __init__(self, options, args, ui_args): - from deluge.log import LOG as log + import logging + log = logging.getLogger(__name__) log.debug("UI init..") # Set the config directory diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index fa0000809..bb7b12da8 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -53,13 +53,13 @@ from twisted.web import http, resource, server, static from deluge import common, component, configmanager from deluge.core.rpcserver import check_ssl_keys -from deluge.log import setupLogger, LOG as _log from deluge.ui import common as uicommon from deluge.ui.tracker_icons import TrackerIcons from deluge.ui.web.auth import Auth from deluge.ui.web.common import Template, compress from deluge.ui.web.json_api import JSON, WebApi from deluge.ui.web.pluginmanager import PluginManager + log = logging.getLogger(__name__) # Initialize gettext @@ -248,7 +248,7 @@ class LookupResource(resource.Resource, component.Component): self.__paths = {} for directory in directories: self.addDirectory(directory) - + def addDirectory(self, directory, path=""): log.debug("Adding directory `%s` with path `%s`", directory, path) paths = self.__paths.setdefault(path, []) @@ -342,10 +342,10 @@ class ScriptResource(resource.Resource, component.Component): self.__scripts[type]["order"].append(path) def remove_script(self, path, type=None): - """ - Removes a script or folder of scripts from the script resource. + """ + Removes a script or folder of scripts from the script resource. - :param path: The path of the folder + :param path: The path of the folder :type path: string :keyword type: The type of script to add (normal, debug, dev) :param type: string @@ -667,13 +667,13 @@ class DelugeWeb(component.Component): def start_normal(self): self.socket = reactor.listenTCP(self.port, self.site) log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0", - self.port, self.port) + self.port, self.port) def start_ssl(self): check_ssl_keys() self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory()) log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0", - self.port, self.port) + self.port, self.port) def stop(self): log.info("Shutting down webserver")