Rename Owner.log to Owner.logmark

Since every plugin has a log method (to do actual logging), the log command
was conflicting with that.  The attempted workaround was overly complicated
and broken.  Simply renaming the command to logmark simplifies everything.

Closes Sf #2889709

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
(cherry picked from commit acaa9b1fd6)
This commit is contained in:
James Vega 2009-10-31 18:22:14 -04:00
parent d95cdfec34
commit c53f8cd510
2 changed files with 13 additions and 36 deletions

View File

@ -1,6 +1,6 @@
### ###
# Copyright (c) 2002-2005, Jeremiah Fincher # Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2008, James Vega # Copyright (c) 2008-2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -100,32 +100,6 @@ registerDefaultPlugin('capabilities', 'User')
registerDefaultPlugin('addcapability', 'Admin') registerDefaultPlugin('addcapability', 'Admin')
registerDefaultPlugin('removecapability', 'Admin') registerDefaultPlugin('removecapability', 'Admin')
class holder(object):
pass
# This is used so we can support a "log" command as well as a "self.log"
# Logger.
class LogProxy(object):
"""<text>
Logs <text> to the global Supybot log at critical priority. Useful for
marking logfiles for later searching.
"""
__name__ = 'log' # Necessary for help.
def __init__(self, log):
self.log = log
self.im_func = holder()
self.im_func.func_name = 'log'
def __call__(self, irc, msg, args, text):
log.critical(text)
irc.replySuccess()
__call__ = wrap(__call__, ['text'])
def __getattr__(self, attr):
return getattr(self.log, attr)
class Owner(callbacks.Plugin): class Owner(callbacks.Plugin):
# This plugin must be first; its priority must be lowest; otherwise odd # This plugin must be first; its priority must be lowest; otherwise odd
# things will happen when adding callbacks. # things will happen when adding callbacks.
@ -134,8 +108,6 @@ class Owner(callbacks.Plugin):
assert not irc.getCallback(self.name()) assert not irc.getCallback(self.name())
self.__parent = super(Owner, self) self.__parent = super(Owner, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
# Setup log object/command.
self.log = LogProxy(self.log)
# Setup command flood detection. # Setup command flood detection.
self.commands = ircutils.FloodQueue(60) self.commands = ircutils.FloodQueue(60)
# Setup plugins and default plugins for commands. # Setup plugins and default plugins for commands.
@ -185,10 +157,6 @@ class Owner(callbacks.Plugin):
return None return None
return msg return msg
def isCommandMethod(self, name):
return name == 'log' or \
self.__parent.isCommandMethod(name)
def reset(self): def reset(self):
# This has to be done somewhere, I figure here is as good place as any. # This has to be done somewhere, I figure here is as good place as any.
callbacks.IrcObjectProxy._mores.clear() callbacks.IrcObjectProxy._mores.clear()
@ -298,6 +266,16 @@ class Owner(callbacks.Plugin):
except SyntaxError, e: except SyntaxError, e:
irc.queueMsg(callbacks.error(msg, str(e))) irc.queueMsg(callbacks.error(msg, str(e)))
def logmark(self, irc, msg, args, text):
"""<text>
Logs <text> to the global Supybot log at critical priority. Useful for
marking logfiles for later searching.
"""
self.log.critical(text)
irc.replySuccess()
logmark = wrap(logmark, ['text'])
def announce(self, irc, msg, args, text): def announce(self, irc, msg, args, text):
"""<text> """<text>
@ -622,4 +600,3 @@ class Owner(callbacks.Plugin):
Class = Owner Class = Owner
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2002-2005, Jeremiah Fincher # Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -33,10 +34,9 @@ import supybot.conf as conf
import supybot.plugin as plugin import supybot.plugin as plugin
class OwnerTestCase(PluginTestCase): class OwnerTestCase(PluginTestCase):
# Defaults, but hey, I'm cool.
plugins = ('Owner', 'Config', 'Misc', 'Admin') plugins = ('Owner', 'Config', 'Misc', 'Admin')
def testHelpLog(self): def testHelpLog(self):
self.assertHelp('help log') self.assertHelp('help logmark')
def testSrcAmbiguity(self): def testSrcAmbiguity(self):
self.assertError('capability add foo bar') self.assertError('capability add foo bar')