From 3b00a7de59b2f6ed889d4c0816051af50725fa12 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Mon, 6 Dec 2010 11:20:22 +0000 Subject: [PATCH] Swhiched the old style logging, ie, a single logger for all logging output to several loggers. This brings the ability to tweak the logging levels for each of the loggers, ie, we can have the "deluge" logger be at the ERROR level while having "deluge.core" at the DEBUG level, meaning we will only see log message for all of the deluge loggers above the ERROR level while still having all messages above the DEBUG level for the "deluge.core" logger and it's children. This kind of tweak can be achieved by adding a file named "logging.conf" to deluge's config dir and this is explained on the `deluge.log.tweak_logging_levels` function. Passing `-r` to the cli's while also passing `-l` will make the logfile rotate when reaching 5Mb in size. Three backups will be kept at all times. All deluge's code is now using this new style logging along with the git hosted plugins. For other plugins not hosted by deluge, which still imports `LOG` as the logger, a deprecation warning will be shown explaining the required changes needed to use the new style logging. New plugins created by the `create_plugin` script will use the new logging facilities. --- ChangeLog | 2 + deluge/common.py | 14 +- deluge/component.py | 4 +- deluge/config.py | 4 +- deluge/configmanager.py | 6 +- deluge/core/alertmanager.py | 3 +- deluge/core/authmanager.py | 3 +- deluge/core/autoadd.py | 4 +- deluge/core/core.py | 6 +- deluge/core/daemon.py | 4 +- deluge/core/eventmanager.py | 4 +- deluge/core/filtermanager.py | 5 +- deluge/core/oldstateupgrader.py | 4 +- deluge/core/pluginmanager.py | 4 +- deluge/core/preferencesmanager.py | 4 +- deluge/core/rpcserver.py | 5 +- deluge/core/torrent.py | 4 +- deluge/core/torrentmanager.py | 7 +- deluge/httpdownloader.py | 12 +- deluge/log.py | 228 ++++++++++++++++-- deluge/main.py | 43 +++- deluge/metafile.py | 6 +- deluge/pluginmanagerbase.py | 5 +- deluge/plugins/autoadd/autoadd/core.py | 26 +- deluge/plugins/autoadd/autoadd/gtkui.py | 68 +++--- deluge/plugins/autoadd/autoadd/webui.py | 4 +- deluge/plugins/blocklist/blocklist/core.py | 20 +- deluge/plugins/blocklist/blocklist/gtkui.py | 4 +- .../blocklist/blocklist/peerguardian.py | 4 +- deluge/plugins/blocklist/blocklist/webui.py | 4 +- deluge/plugins/example/example/core.py | 4 +- deluge/plugins/example/example/gtkui.py | 4 +- deluge/plugins/example/example/webui.py | 8 +- deluge/plugins/execute/execute/core.py | 4 +- deluge/plugins/execute/execute/gtkui.py | 4 +- deluge/plugins/execute/execute/webui.py | 6 +- deluge/plugins/extractor/extractor/core.py | 12 +- deluge/plugins/extractor/extractor/gtkui.py | 6 +- deluge/plugins/extractor/extractor/webui.py | 4 +- deluge/plugins/feeder/feeder/core.py | 4 +- deluge/plugins/feeder/feeder/webui.py | 16 +- .../plugins/freespace/freespace/__init__.py | 2 +- deluge/plugins/freespace/freespace/common.py | 2 +- deluge/plugins/freespace/freespace/core.py | 6 +- deluge/plugins/freespace/freespace/gtkui.py | 6 +- deluge/plugins/freespace/freespace/webui.py | 6 +- deluge/plugins/freespace/setup.py | 4 +- deluge/plugins/init.py | 4 +- deluge/plugins/label/label/core.py | 4 +- deluge/plugins/label/label/gtkui/__init__.py | 4 +- .../plugins/label/label/gtkui/label_config.py | 4 +- .../plugins/label/label/gtkui/sidebar_menu.py | 4 +- deluge/plugins/label/label/gtkui/submenu.py | 4 +- deluge/plugins/label/label/webui.py | 4 +- .../notifications/notifications/__init__.py | 2 +- .../notifications/notifications/common.py | 6 +- .../notifications/notifications/core.py | 6 +- .../notifications/notifications/gtkui.py | 6 +- .../notifications/notifications/test.py | 8 +- .../notifications/notifications/webui.py | 6 +- deluge/plugins/notifications/setup.py | 4 +- deluge/plugins/pluginbase.py | 16 +- deluge/plugins/scheduler/scheduler/core.py | 4 +- deluge/plugins/scheduler/scheduler/gtkui.py | 4 +- deluge/plugins/scheduler/scheduler/webui.py | 8 +- deluge/plugins/stats/stats/core.py | 4 +- deluge/plugins/stats/stats/graph.py | 4 +- deluge/plugins/stats/stats/gtkui.py | 4 +- deluge/plugins/stats/stats/webui.py | 8 +- deluge/plugins/toggle/toggle/core.py | 4 +- deluge/plugins/toggle/toggle/gtkui.py | 4 +- deluge/plugins/toggle/toggle/webui.py | 4 +- deluge/plugins/webui/webui/core.py | 20 +- deluge/plugins/webui/webui/gtkui.py | 6 +- deluge/scripts/create_plugin.py | 39 +-- deluge/tests/test_log.py | 21 ++ deluge/ui/client.py | 26 +- deluge/ui/common.py | 4 +- deluge/ui/console/commands/config.py | 12 +- deluge/ui/console/eventlog.py | 3 +- deluge/ui/console/main.py | 7 +- deluge/ui/console/screen.py | 4 +- deluge/ui/coreconfig.py | 4 +- deluge/ui/gtkui/addtorrentdialog.py | 7 +- deluge/ui/gtkui/common.py | 8 +- deluge/ui/gtkui/connectionmanager.py | 4 +- deluge/ui/gtkui/createtorrentdialog.py | 4 +- deluge/ui/gtkui/details_tab.py | 6 +- deluge/ui/gtkui/edittrackersdialog.py | 7 +- deluge/ui/gtkui/files_tab.py | 7 +- deluge/ui/gtkui/filtertreeview.py | 6 +- deluge/ui/gtkui/gtkui.py | 7 +- deluge/ui/gtkui/ipcinterface.py | 18 +- deluge/ui/gtkui/listview.py | 3 +- deluge/ui/gtkui/mainwindow.py | 6 +- deluge/ui/gtkui/menubar.py | 6 +- deluge/ui/gtkui/notification.py | 22 +- deluge/ui/gtkui/peers_tab.py | 7 +- deluge/ui/gtkui/pluginmanager.py | 4 +- deluge/ui/gtkui/preferences.py | 13 +- deluge/ui/gtkui/queuedtorrents.py | 9 +- deluge/ui/gtkui/removetorrentdialog.py | 7 +- deluge/ui/gtkui/sidebar.py | 4 +- deluge/ui/gtkui/status_tab.py | 7 +- deluge/ui/gtkui/statusbar.py | 4 +- deluge/ui/gtkui/systemtray.py | 4 +- deluge/ui/gtkui/toolbar.py | 7 +- deluge/ui/gtkui/torrentdetails.py | 6 +- deluge/ui/gtkui/torrentview.py | 7 +- deluge/ui/sessionproxy.py | 4 +- deluge/ui/tracker_icons.py | 5 +- deluge/ui/ui.py | 18 +- deluge/ui/web/server.py | 14 +- 113 files changed, 795 insertions(+), 321 deletions(-) create mode 100644 deluge/tests/test_log.py diff --git a/ChangeLog b/ChangeLog index 4f48c9d88..c2cc26e48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ === Deluge 1.3.0 (In Development) === + * Improved Logging + ==== Core ==== * Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent * Implement #457 progress bars for folders 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 9fe5915eb..4f5571209 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..8494e2547 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..") @@ -86,6 +89,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 b4aa1759a..198507007 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 ef088fe5b..ef2e3342f 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 93f0a9794..22e139343 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, @@ -857,14 +858,14 @@ class TorrentManager(component.Component): torrent = self.torrents[str(alert.handle.info_hash())] except: return - + # Check to see if we're forcing a recheck and set it back to paused # if necessary if torrent.forcing_recheck: torrent.forcing_recheck = False if torrent.forcing_recheck_paused: torrent.handle.pause() - + # Set the torrent state torrent.update_state() 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..a0a4e1dbc 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 logging +import inspect +import pkg_resources +from deluge import configmanager, common, component +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, "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,141 @@ 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': + handler = 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. + """ + 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'): + if line.strip().startswith("#"): + continue + name, level = line.strip().split(':') + if level in levels: + log.warn("Setting logger \"%s\" to logging level \"%s\"", name, level) + logging.getLogger(name).setLevel(levels.get(level)) + + +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 4256a46c4..2b4bb88b8 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/autoadd/core.py b/deluge/plugins/autoadd/autoadd/core.py index aa58d8f53..67d3cc409 100644 --- a/deluge/plugins/autoadd/autoadd/core.py +++ b/deluge/plugins/autoadd/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 @@ -57,7 +59,7 @@ OPTIONS_AVAILABLE = { #option: builtin "enabled":False, "path":False, "append_extension":False, - "abspath":False, + "abspath":False, "download_location":True, "max_download_speed":True, "max_upload_speed":True, @@ -88,7 +90,7 @@ def CheckInput(cond, message): class Core(CorePluginBase): def enable(self): - + #reduce typing, assigning some values to self... self.config = deluge.configmanager.ConfigManager("autoadd.conf", DEFAULT_PREFS) self.watchdirs = self.config["watchdirs"] @@ -127,7 +129,7 @@ class Core(CorePluginBase): def update(self): pass - + @export() def set_options(self, watchdir_id, options): """Update the options for a watch folder.""" @@ -147,14 +149,14 @@ class Core(CorePluginBase): #disable the watch loop if it was active if watchdir_id in self.update_timers: self.disable_watchdir(watchdir_id) - + self.watchdirs[watchdir_id].update(options) #re-enable watch loop if appropriate if self.watchdirs[watchdir_id]['enabled']: self.enable_watchdir(watchdir_id) self.config.save() component.get("EventManager").emit(AutoaddOptionsChangedEvent()) - + def load_torrent(self, filename): try: log.debug("Attempting to open %s for add.", filename) @@ -171,7 +173,7 @@ class Core(CorePluginBase): info = lt.torrent_info(lt.bdecode(filedump)) return filedump - + def update_watchdir(self, watchdir_id): """Check the watch folder for new torrents to add.""" watchdir_id = str(watchdir_id) @@ -185,7 +187,7 @@ class Core(CorePluginBase): log.warning("Invalid AutoAdd folder: %s", watchdir["abspath"]) self.disable_watchdir(watchdir_id) return - + # Generate options dict for watchdir opts = {} if 'stop_at_ratio_toggle' in watchdir: @@ -246,7 +248,7 @@ class Core(CorePluginBase): """Disables any watch folders with unhandled exceptions.""" self.disable_watchdir(watchdir_id) log.error("Disabling '%s', error during update: %s" % (self.watchdirs[watchdir_id]["path"], failure)) - + @export def enable_watchdir(self, watchdir_id): watchdir_id = str(watchdir_id) @@ -259,7 +261,7 @@ class Core(CorePluginBase): self.watchdirs[watchdir_id]['enabled'] = True self.config.save() component.get("EventManager").emit(AutoaddOptionsChangedEvent()) - + @export def disable_watchdir(self, watchdir_id): watchdir_id = str(watchdir_id) @@ -287,7 +289,7 @@ class Core(CorePluginBase): def get_config(self): """Returns the config dictionary.""" return self.config.config - + @export() def get_watchdirs(self): return self.watchdirs.keys() @@ -319,7 +321,7 @@ class Core(CorePluginBase): self.config.save() component.get("EventManager").emit(AutoaddOptionsChangedEvent()) return watchdir_id - + @export def remove(self, watchdir_id): """Remove a watch folder.""" diff --git a/deluge/plugins/autoadd/autoadd/gtkui.py b/deluge/plugins/autoadd/autoadd/gtkui.py index 3fe74ca29..98d3b7c62 100644 --- a/deluge/plugins/autoadd/autoadd/gtkui.py +++ b/deluge/plugins/autoadd/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"] @@ -113,22 +115,22 @@ class OptionsDialog(): self.glade.get_widget(field+"_entry").show() self.glade.get_widget(field+"_chooser").hide() self.set_sensitive() - + def on_get_enabled_plugins(result): - if 'Label' in result: + if 'Label' in result: self.glade.get_widget('label_frame').show() else: self.glade.get_widget('label_frame').hide() self.glade.get_widget('label_toggle').set_active(False) - + client.core.get_enabled_plugins().addCallback(on_get_enabled_plugins) - + def set_sensitive(self): maintoggles = ['download_location', 'append_extension', 'move_completed', 'label', \ 'max_download_speed', 'max_upload_speed', 'max_connections', \ 'max_upload_slots', 'add_paused', 'auto_managed', 'stop_at_ratio', 'queue_to_top'] [self.on_toggle_toggled(self.glade.get_widget(x+'_toggle')) for x in maintoggles] - + def on_toggle_toggled(self, tb): toggle = str(tb.name).replace("_toggle", "") isactive = tb.get_active() @@ -166,29 +168,29 @@ class OptionsDialog(): self.glade.get_widget('stop_at_ratio').set_active(isactive) self.glade.get_widget('stop_ratio').set_sensitive(isactive) self.glade.get_widget('remove_at_ratio').set_sensitive(isactive) - + def on_apply(self, Event=None): client.autoadd.set_options(str(self.watchdir_id), self.generate_opts()).addCallbacks(self.on_added, self.on_error_show) - + def on_error_show(self, result): self.glade.get_widget('error_label').set_text(result.value.exception_msg) self.err_dialog = self.glade.get_widget('error_dialog') self.err_dialog.set_transient_for(self.dialog) result.cleanFailure() self.err_dialog.show() - + def on_added(self, result): self.dialog.destroy() - + def on_error_ok(self, Event=None): self.err_dialog.hide() - + def on_add(self, Event=None): client.autoadd.add(self.generate_opts()).addCallbacks(self.on_added, self.on_error_show) - + def on_cancel(self, Event=None): self.dialog.destroy() - + def generate_opts(self): # generate options dict based on gtk objects options = {} @@ -217,11 +219,11 @@ class OptionsDialog(): options[id] = self.glade.get_widget(id).get_active() options[id+'_toggle'] = self.glade.get_widget(id+'_toggle').get_active() return options - + class GtkUI(GtkPluginBase): def enable(self): - + self.glade = gtk.glade.XML(get_resource("config.glade")) self.glade.signal_autoconnect({ "on_add_button_clicked": self.on_add_button_clicked, @@ -229,18 +231,18 @@ class GtkUI(GtkPluginBase): "on_remove_button_clicked": self.on_remove_button_clicked }) self.opts_dialog = OptionsDialog() - + component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) client.register_event_handler("AutoaddOptionsChangedEvent", self.on_options_changed_event) - + self.watchdirs = {} - + vbox = self.glade.get_widget("watchdirs_vbox") sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - + vbox.pack_start(sw, True, True, 0) self.store = self.create_model() @@ -256,28 +258,28 @@ class GtkUI(GtkPluginBase): component.get("Preferences").add_page("AutoAdd", self.glade.get_widget("prefs_box")) self.on_show_prefs() - + def disable(self): component.get("Preferences").remove_page("AutoAdd") component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs) - + def create_model(self): - + store = gtk.ListStore(str, bool, str) for watchdir_id, watchdir in self.watchdirs.iteritems(): store.append([watchdir_id, watchdir['enabled'], watchdir['path']]) return store - + def create_columns(self, treeView): rendererToggle = gtk.CellRendererToggle() column = gtk.TreeViewColumn("On", rendererToggle, activatable=True, active=1) - column.set_sort_column_id(1) + column.set_sort_column_id(1) treeView.append_column(column) tt = gtk.Tooltip() tt.set_text('Double-click to toggle') treeView.set_tooltip_cell(tt, None, None, rendererToggle) - + rendererText = gtk.CellRendererText() column = gtk.TreeViewColumn("Path", rendererText, text=2) column.set_sort_column_id(2) @@ -289,20 +291,20 @@ class GtkUI(GtkPluginBase): def load_watchdir_list(self): pass - + def add_watchdir_entry(self): pass - + def on_add_button_clicked(self, Event=None): #display options_window self.opts_dialog.show() - + def on_remove_button_clicked(self, Event=None): tree, tree_id = self.treeView.get_selection().get_selected() watchdir_id = str(self.store.get_value(tree_id, 0)) if watchdir_id: client.autoadd.remove(watchdir_id) - + def on_edit_button_clicked(self, Event=None, a=None, col=None): tree, tree_id = self.treeView.get_selection().get_selected() watchdir_id = str(self.store.get_value(tree_id, 0)) @@ -314,7 +316,7 @@ class GtkUI(GtkPluginBase): client.autoadd.enable_watchdir(watchdir_id) else: self.opts_dialog.show(self.watchdirs[watchdir_id], watchdir_id) - + def on_listitem_activated(self, treeview): tree, tree_id = self.treeView.get_selection().get_selected() if tree_id: @@ -323,7 +325,7 @@ class GtkUI(GtkPluginBase): else: self.glade.get_widget('edit_button').set_sensitive(False) self.glade.get_widget('remove_button').set_sensitive(False) - + def on_apply_prefs(self): log.debug("applying prefs for AutoAdd") for watchdir_id, watchdir in self.watchdirs.iteritems(): @@ -331,7 +333,7 @@ class GtkUI(GtkPluginBase): def on_show_prefs(self): client.autoadd.get_config().addCallback(self.cb_get_config) - + def on_options_changed_event(self): client.autoadd.get_config().addCallback(self.cb_get_config) @@ -344,4 +346,4 @@ class GtkUI(GtkPluginBase): # Disable the remove and edit buttons, because nothing in the store is selected self.glade.get_widget('remove_button').set_sensitive(False) self.glade.get_widget('edit_button').set_sensitive(False) - + diff --git a/deluge/plugins/autoadd/autoadd/webui.py b/deluge/plugins/autoadd/autoadd/webui.py index a09a819f3..eab62a355 100644 --- a/deluge/plugins/autoadd/autoadd/webui.py +++ b/deluge/plugins/autoadd/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/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index 62edc960b..f6ca3f52c 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/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/blocklist/gtkui.py b/deluge/plugins/blocklist/blocklist/gtkui.py index 2c2ad0038..98c858dae 100644 --- a/deluge/plugins/blocklist/blocklist/gtkui.py +++ b/deluge/plugins/blocklist/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/blocklist/peerguardian.py b/deluge/plugins/blocklist/blocklist/peerguardian.py index c9f0550c6..2d8a0256d 100644 --- a/deluge/plugins/blocklist/blocklist/peerguardian.py +++ b/deluge/plugins/blocklist/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/blocklist/webui.py b/deluge/plugins/blocklist/blocklist/webui.py index 572d2b047..2c4e0de4a 100644 --- a/deluge/plugins/blocklist/blocklist/webui.py +++ b/deluge/plugins/blocklist/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/example/core.py b/deluge/plugins/example/example/core.py index 2d78d1bf9..319580c91 100644 --- a/deluge/plugins/example/example/core.py +++ b/deluge/plugins/example/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/example/gtkui.py b/deluge/plugins/example/example/gtkui.py index 39f1b77a9..9227cd511 100644 --- a/deluge/plugins/example/example/gtkui.py +++ b/deluge/plugins/example/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/example/webui.py b/deluge/plugins/example/example/webui.py index df2efadd5..961cb49e7 100644 --- a/deluge/plugins/example/example/webui.py +++ b/deluge/plugins/example/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/execute/core.py b/deluge/plugins/execute/execute/core.py index 4c5e66005..54362b1c7 100644 --- a/deluge/plugins/execute/execute/core.py +++ b/deluge/plugins/execute/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/execute/gtkui.py b/deluge/plugins/execute/execute/gtkui.py index 7a341ea2b..3cd148a55 100644 --- a/deluge/plugins/execute/execute/gtkui.py +++ b/deluge/plugins/execute/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/execute/webui.py b/deluge/plugins/execute/execute/webui.py index 991219b04..0a29a9eb7 100644 --- a/deluge/plugins/execute/execute/webui.py +++ b/deluge/plugins/execute/execute/webui.py @@ -35,14 +35,16 @@ import pkg_resources -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")] debug_scripts = scripts diff --git a/deluge/plugins/extractor/extractor/core.py b/deluge/plugins/extractor/extractor/core.py index f7c888e17..e84534533 100644 --- a/deluge/plugins/extractor/extractor/core.py +++ b/deluge/plugins/extractor/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 @@ -98,22 +100,22 @@ class Core(CorePluginBase): # Now that we have the cmd, lets run it to extract the files fp = os.path.join(save_path, f["path"]) - + # Get the destination path dest = self.config["extract_path"] if self.config["use_name_folder"]: name = component.get("TorrentManager")[torrent_id].get_status(["name"])["name"] dest = os.path.join(dest, name) - # Create the destination folder if it doesn't exist + # Create the destination folder if it doesn't exist if not os.path.exists(dest): try: os.makedirs(dest) except Exception, e: log.error("Error creating destination folder: %s", e) return - - log.debug("Extracting to %s", dest) + + log.debug("Extracting to %s", dest) def on_extract_success(result, torrent_id): # XXX: Emit an event log.debug("Extract was successful for %s", torrent_id) diff --git a/deluge/plugins/extractor/extractor/gtkui.py b/deluge/plugins/extractor/extractor/gtkui.py index 9e3bf617b..d27e253ed 100644 --- a/deluge/plugins/extractor/extractor/gtkui.py +++ b/deluge/plugins/extractor/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/extractor/webui.py b/deluge/plugins/extractor/extractor/webui.py index 3cc135bf7..5f198981d 100644 --- a/deluge/plugins/extractor/extractor/webui.py +++ b/deluge/plugins/extractor/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/feeder/core.py b/deluge/plugins/feeder/feeder/core.py index 0324556e3..ad74c1c23 100644 --- a/deluge/plugins/feeder/feeder/core.py +++ b/deluge/plugins/feeder/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/feeder/webui.py b/deluge/plugins/feeder/feeder/webui.py index 4769155f3..662e13c5d 100644 --- a/deluge/plugins/feeder/feeder/webui.py +++ b/deluge/plugins/feeder/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/freespace/__init__.py b/deluge/plugins/freespace/freespace/__init__.py index 7f5b5704c..b09dc0f57 100644 --- a/deluge/plugins/freespace/freespace/__init__.py +++ b/deluge/plugins/freespace/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/freespace/common.py b/deluge/plugins/freespace/freespace/common.py index ef27e0af8..8bdce351f 100644 --- a/deluge/plugins/freespace/freespace/common.py +++ b/deluge/plugins/freespace/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/freespace/core.py b/deluge/plugins/freespace/freespace/core.py index 42aed12a6..eb90ecb68 100644 --- a/deluge/plugins/freespace/freespace/core.py +++ b/deluge/plugins/freespace/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/freespace/gtkui.py b/deluge/plugins/freespace/freespace/gtkui.py index 57a8117e4..21405ccda 100644 --- a/deluge/plugins/freespace/freespace/gtkui.py +++ b/deluge/plugins/freespace/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/freespace/webui.py b/deluge/plugins/freespace/freespace/webui.py index 9bee15849..a2686597b 100644 --- a/deluge/plugins/freespace/freespace/webui.py +++ b/deluge/plugins/freespace/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 3c0dce66f..1d2ad7c05 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 __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/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/label/label/core.py b/deluge/plugins/label/label/core.py index 70b8e3554..b5613d698 100644 --- a/deluge/plugins/label/label/core.py +++ b/deluge/plugins/label/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/label/gtkui/__init__.py b/deluge/plugins/label/label/gtkui/__init__.py index 62e97eab6..81dbe8e52 100644 --- a/deluge/plugins/label/label/gtkui/__init__.py +++ b/deluge/plugins/label/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/label/gtkui/label_config.py b/deluge/plugins/label/label/gtkui/label_config.py index a434155bb..1288f7165 100644 --- a/deluge/plugins/label/label/gtkui/label_config.py +++ b/deluge/plugins/label/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/label/gtkui/sidebar_menu.py b/deluge/plugins/label/label/gtkui/sidebar_menu.py index acbd9b591..0bcfb0835 100644 --- a/deluge/plugins/label/label/gtkui/sidebar_menu.py +++ b/deluge/plugins/label/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/label/gtkui/submenu.py b/deluge/plugins/label/label/gtkui/submenu.py index 085a34c18..a2e12ea57 100644 --- a/deluge/plugins/label/label/gtkui/submenu.py +++ b/deluge/plugins/label/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/label/webui.py b/deluge/plugins/label/label/webui.py index bfc495307..4025317b5 100644 --- a/deluge/plugins/label/label/webui.py +++ b/deluge/plugins/label/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("label", os.path.join("data", filename)) diff --git a/deluge/plugins/notifications/notifications/__init__.py b/deluge/plugins/notifications/notifications/__init__.py index 7f5b5704c..b09dc0f57 100644 --- a/deluge/plugins/notifications/notifications/__init__.py +++ b/deluge/plugins/notifications/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/notifications/common.py b/deluge/plugins/notifications/notifications/common.py index 7353e5a8e..98a7828b4 100644 --- a/deluge/plugins/notifications/notifications/common.py +++ b/deluge/plugins/notifications/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/notifications/core.py b/deluge/plugins/notifications/notifications/core.py index 9586f7f5f..2139de257 100644 --- a/deluge/plugins/notifications/notifications/core.py +++ b/deluge/plugins/notifications/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 notifications.common import CustomNotifications +log = getPluginLogger(__name__) + DEFAULT_PREFS = { "smtp_enabled": False, "smtp_host": "", diff --git a/deluge/plugins/notifications/notifications/gtkui.py b/deluge/plugins/notifications/notifications/gtkui.py index ae8909f45..79b272ac8 100644 --- a/deluge/plugins/notifications/notifications/gtkui.py +++ b/deluge/plugins/notifications/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/notifications/test.py b/deluge/plugins/notifications/notifications/test.py index 1ff385d4e..648d4ad0c 100644 --- a/deluge/plugins/notifications/notifications/test.py +++ b/deluge/plugins/notifications/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/notifications/webui.py b/deluge/plugins/notifications/notifications/webui.py index 3abf447a9..9ab62bdf9 100644 --- a/deluge/plugins/notifications/notifications/webui.py +++ b/deluge/plugins/notifications/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 b7098e22c..b9834ff8b 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/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/plugins/scheduler/scheduler/core.py b/deluge/plugins/scheduler/scheduler/core.py index e7fd86aae..e33ef94dc 100644 --- a/deluge/plugins/scheduler/scheduler/core.py +++ b/deluge/plugins/scheduler/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/scheduler/gtkui.py b/deluge/plugins/scheduler/scheduler/gtkui.py index e688d345b..739f29ab5 100644 --- a/deluge/plugins/scheduler/scheduler/gtkui.py +++ b/deluge/plugins/scheduler/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/scheduler/webui.py b/deluge/plugins/scheduler/scheduler/webui.py index 71cc8cc9a..fd06cfe8e 100644 --- a/deluge/plugins/scheduler/scheduler/webui.py +++ b/deluge/plugins/scheduler/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")] \ No newline at end of file + + scripts = [get_resource("scheduler.js")] diff --git a/deluge/plugins/stats/stats/core.py b/deluge/plugins/stats/stats/core.py index e6af5e2d1..b16aa7c8f 100644 --- a/deluge/plugins/stats/stats/core.py +++ b/deluge/plugins/stats/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/stats/graph.py b/deluge/plugins/stats/stats/graph.py index 2fba2d7d2..8432bc2e9 100644 --- a/deluge/plugins/stats/stats/graph.py +++ b/deluge/plugins/stats/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/stats/gtkui.py b/deluge/plugins/stats/stats/gtkui.py index 30888ed37..b2ed73730 100644 --- a/deluge/plugins/stats/stats/gtkui.py +++ b/deluge/plugins/stats/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/stats/webui.py b/deluge/plugins/stats/stats/webui.py index b1a235297..d78ff86c9 100644 --- a/deluge/plugins/stats/stats/webui.py +++ b/deluge/plugins/stats/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/toggle/core.py b/deluge/plugins/toggle/toggle/core.py index ccd0fcc88..1e229c180 100644 --- a/deluge/plugins/toggle/toggle/core.py +++ b/deluge/plugins/toggle/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/toggle/gtkui.py b/deluge/plugins/toggle/toggle/gtkui.py index da019692d..eb2941269 100644 --- a/deluge/plugins/toggle/toggle/gtkui.py +++ b/deluge/plugins/toggle/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/toggle/webui.py b/deluge/plugins/toggle/toggle/webui.py index a4ddfc6b7..023085a05 100644 --- a/deluge/plugins/toggle/toggle/webui.py +++ b/deluge/plugins/toggle/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/webui/core.py b/deluge/plugins/webui/webui/core.py index 9ad4abd4e..3f5fb8686 100644 --- a/deluge/plugins/webui/webui/core.py +++ b/deluge/plugins/webui/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/webui/gtkui.py b/deluge/plugins/webui/webui/gtkui.py index fc45eee42..47b02e9ab 100644 --- a/deluge/plugins/webui/webui/gtkui.py +++ b/deluge/plugins/webui/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/scripts/create_plugin.py b/deluge/scripts/create_plugin.py index d195fbccf..eac7b54dd 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 @@ -64,7 +65,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) @@ -98,7 +100,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 @@ -192,6 +193,7 @@ setup( """ COMMON = """ + def get_resource(filename): import pkg_resources, os return pkg_resources.resource_filename("%(safe_name)s", os.path.join("data", filename)) @@ -200,7 +202,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 @@ -208,6 +210,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")) @@ -266,13 +270,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")] @@ -289,7 +295,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) @@ -318,20 +324,20 @@ Copyright: */ %(name)sPlugin = Ext.extend(Deluge.Plugin, { - constructor: function(config) { - config = Ext.apply({ - name: "%(name)s" - }, config); - %(name)sPlugin.superclass.constructor.call(this, config); - }, + constructor: function(config) { + config = Ext.apply({ + name: "%(name)s" + }, config); + %(name)sPlugin.superclass.constructor.call(this, config); + }, - onDisable: function() { + onDisable: function() { - }, + }, - onEnable: function() { + onEnable: function() { - } + } }); new %(name)sPlugin(); """ @@ -339,12 +345,13 @@ 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 # Copyright (C) 2007-2009 Andrew Resch # Copyright (C) 2009 Damien Churchill +# Copyright (C) 2010 Pedro Algarvio # # Deluge is free software. # 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 3fbae6e6f..f7d808018 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 if deluge.common.windows_check(): import win32api @@ -55,6 +55,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()]) @@ -140,7 +142,7 @@ class DelugeRPCProtocol(Protocol): while data: # Increase the byte counter self.factory.bytes_recv += len(data) - + dobj = zlib.decompressobj() try: request = rencode.loads(dobj.decompress(data)) @@ -213,7 +215,7 @@ class DelugeRPCClientFactory(ClientFactory): def __init__(self, daemon, event_handlers): self.daemon = daemon self.event_handlers = event_handlers - + self.bytes_recv = 0 self.bytes_sent = 0 @@ -329,7 +331,7 @@ class DaemonSSLProxy(DaemonProxy): :param request_id: the request_id of the Deferred to pop :type request_id: int - + """ return self.__deferred.pop(request_id) @@ -343,7 +345,7 @@ class DaemonSSLProxy(DaemonProxy): :param handler: the function to be called when `:param:event` is emitted from the daemon :type handler: function - + """ if event not in self.__factory.event_handlers: # This is a new event to handle, so we need to tell the daemon @@ -422,10 +424,10 @@ class DaemonSSLProxy(DaemonProxy): def get_bytes_recv(self): return self.__factory.bytes_recv - + def get_bytes_sent(self): return self.__factory.bytes_sent - + class DaemonClassicProxy(DaemonProxy): def __init__(self, event_handlers={}): import deluge.core.daemon @@ -466,7 +468,7 @@ class DaemonClassicProxy(DaemonProxy): :param handler: the function to be called when `:param:event` is emitted from the daemon :type handler: function - + """ self.__daemon.core.eventmanager.register_event_handler(event, handler) @@ -571,7 +573,7 @@ class Client(object): :rtype: bool :raises OSError: received from subprocess.call() - + """ try: if deluge.common.windows_check(): @@ -679,7 +681,7 @@ class Client(object): def get_bytes_recv(self): """ Returns the number of bytes received from the daemon. - + :returns: the number of bytes received :rtype: int """ @@ -688,11 +690,11 @@ class Client(object): def get_bytes_sent(self): """ Returns the number of bytes sent to the daemon. - + :returns: the number of bytes sent :rtype: int """ return self._daemon_proxy.get_bytes_sent() - + # This is the object clients will use client = Client() 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 91e258ae1..df1447bae 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 8235ee907..09f534482 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 c56019729..6120dcfa8 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 c43d85b1b..6feeab7ea 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 344359f5b..12fa5a96d 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 1a9026965..901e6b3c6 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 8d0126461..b5169977d 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 a95e78b61..60202a213 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 807852399..95beafac6 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 5f1e45228..3753fa105 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 50b8af4ee..f1e5d3e3c 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")