mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 05:03:07 +01:00
commands: Silence noisy logging of command evaluation
This commit is contained in:
parent
ee60431396
commit
ef081746b1
@ -50,6 +50,13 @@ from .utils import minisix
|
|||||||
from .i18n import PluginInternationalization, internationalizeDocstring
|
from .i18n import PluginInternationalization, internationalizeDocstring
|
||||||
_ = PluginInternationalization()
|
_ = PluginInternationalization()
|
||||||
|
|
||||||
|
LOG_CONVERTERS = world.testing
|
||||||
|
"""Defines whether converters and contexts should log the argument stack
|
||||||
|
while parsing it.
|
||||||
|
Disabled by default (unless running via supybot-test) as it is very noisy
|
||||||
|
and rarely needs to be debugged.
|
||||||
|
"""
|
||||||
|
|
||||||
###
|
###
|
||||||
# Non-arg wrappers -- these just change the behavior of a command without
|
# Non-arg wrappers -- these just change the behavior of a command without
|
||||||
# changing the arguments given to it.
|
# changing the arguments given to it.
|
||||||
@ -509,6 +516,7 @@ def getChannel(irc, msg, args, state):
|
|||||||
elif msg.channel:
|
elif msg.channel:
|
||||||
channel = msg.channel
|
channel = msg.channel
|
||||||
else:
|
else:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
state.log.debug('Raising ArgumentError because there is no channel.')
|
state.log.debug('Raising ArgumentError because there is no channel.')
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
state.channel = channel
|
state.channel = channel
|
||||||
@ -520,6 +528,7 @@ def getChannels(irc, msg, args, state):
|
|||||||
elif msg.channel:
|
elif msg.channel:
|
||||||
channels = [msg.channel]
|
channels = [msg.channel]
|
||||||
else:
|
else:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
state.log.debug('Raising ArgumentError because there is no channel.')
|
state.log.debug('Raising ArgumentError because there is no channel.')
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
state.args.append(channels)
|
state.args.append(channels)
|
||||||
@ -898,8 +907,10 @@ class context(object):
|
|||||||
self.converter = spec
|
self.converter = spec
|
||||||
|
|
||||||
def __call__(self, irc, msg, args, state):
|
def __call__(self, irc, msg, args, state):
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('args before %r: %r', self, args)
|
log.debug('args before %r: %r', self, args)
|
||||||
self.converter(irc, msg, args, state, *self.args)
|
self.converter(irc, msg, args, state, *self.args)
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('args after %r: %r', self, args)
|
log.debug('args after %r: %r', self, args)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -929,6 +940,7 @@ class additional(context):
|
|||||||
try:
|
try:
|
||||||
self.__parent.__call__(irc, msg, args, state)
|
self.__parent.__call__(irc, msg, args, state)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('Got IndexError, returning default.')
|
log.debug('Got IndexError, returning default.')
|
||||||
setDefault(state, self.default)
|
setDefault(state, self.default)
|
||||||
|
|
||||||
@ -939,6 +951,7 @@ class optional(additional):
|
|||||||
try:
|
try:
|
||||||
super(optional, self).__call__(irc, msg, args, state)
|
super(optional, self).__call__(irc, msg, args, state)
|
||||||
except (callbacks.ArgumentError, callbacks.Error) as e:
|
except (callbacks.ArgumentError, callbacks.Error) as e:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('Got %s, returning default.', utils.exnToString(e))
|
log.debug('Got %s, returning default.', utils.exnToString(e))
|
||||||
state.errored = False
|
state.errored = False
|
||||||
setDefault(state, self.default)
|
setDefault(state, self.default)
|
||||||
@ -960,6 +973,7 @@ class any(context):
|
|||||||
if not self.continueOnError:
|
if not self.continueOnError:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('Got %s, returning default.', utils.exnToString(e))
|
log.debug('Got %s, returning default.', utils.exnToString(e))
|
||||||
pass
|
pass
|
||||||
state.args.append(st.args)
|
state.args.append(st.args)
|
||||||
@ -1041,10 +1055,12 @@ class getopts(context):
|
|||||||
self.getopts[name] = contextify(spec)
|
self.getopts[name] = contextify(spec)
|
||||||
self.getoptL.append(name + '=')
|
self.getoptL.append(name + '=')
|
||||||
self.getopts[name] = contextify(spec)
|
self.getopts[name] = contextify(spec)
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('getopts: %r', self.getopts)
|
log.debug('getopts: %r', self.getopts)
|
||||||
log.debug('getoptL: %r', self.getoptL)
|
log.debug('getoptL: %r', self.getoptL)
|
||||||
|
|
||||||
def __call__(self, irc, msg, args, state):
|
def __call__(self, irc, msg, args, state):
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('args before %r: %r', self, args)
|
log.debug('args before %r: %r', self, args)
|
||||||
(optlist, rest) = getopt.getopt(args, self.getoptLs, self.getoptL)
|
(optlist, rest) = getopt.getopt(args, self.getoptLs, self.getoptL)
|
||||||
getopts = []
|
getopts = []
|
||||||
@ -1053,6 +1069,7 @@ class getopts(context):
|
|||||||
opt = opt[2:] # Strip --
|
opt = opt[2:] # Strip --
|
||||||
else:
|
else:
|
||||||
opt = opt[1:]
|
opt = opt[1:]
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('opt: %r, arg: %r', opt, arg)
|
log.debug('opt: %r, arg: %r', opt, arg)
|
||||||
context = self.getopts[opt]
|
context = self.getopts[opt]
|
||||||
if context is not None:
|
if context is not None:
|
||||||
@ -1064,6 +1081,7 @@ class getopts(context):
|
|||||||
getopts.append((opt, True))
|
getopts.append((opt, True))
|
||||||
state.args.append(getopts)
|
state.args.append(getopts)
|
||||||
args[:] = rest
|
args[:] = rest
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('args after %r: %r', self, args)
|
log.debug('args after %r: %r', self, args)
|
||||||
|
|
||||||
###
|
###
|
||||||
@ -1123,6 +1141,7 @@ class Spec(object):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
if args and not state.allowExtra:
|
if args and not state.allowExtra:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
log.debug('args and not self.allowExtra: %r', args)
|
log.debug('args and not self.allowExtra: %r', args)
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
return state
|
return state
|
||||||
@ -1134,8 +1153,10 @@ def _wrap(f, specList=[], name=None, checkDoc=True, **kw):
|
|||||||
spec = Spec(specList, **kw)
|
spec = Spec(specList, **kw)
|
||||||
def newf(self, irc, msg, args, **kwargs):
|
def newf(self, irc, msg, args, **kwargs):
|
||||||
state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log})
|
state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log})
|
||||||
|
if LOG_CONVERTERS:
|
||||||
self.log.debug('State before call: %s', state)
|
self.log.debug('State before call: %s', state)
|
||||||
if state.errored:
|
if state.errored:
|
||||||
|
if LOG_CONVERTERS:
|
||||||
self.log.debug('Refusing to call %s due to state.errored.', f)
|
self.log.debug('Refusing to call %s due to state.errored.', f)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user