Prettier tracebacks

This commit is contained in:
Neale Pickett 2008-03-27 16:57:17 -06:00
parent 5d26919667
commit f580eda2b0
3 changed files with 27 additions and 37 deletions

View File

@ -10,6 +10,7 @@ import re
import os
import time
import socket
import rp
def esc(arg):
return "'" + arg.replace("'", r"'\''") + "'"
@ -21,7 +22,7 @@ class Arsenic(firebot.FireBot, ProcBot):
debug = False
bindings = []
ping_interval = 120
chatty = False # #x can't play nice
chatty = True # Maybe #x can play nice now
def __init__(self, *args, **kwargs):
firebot.FireBot.__init__(self, *args, **kwargs)
@ -44,12 +45,16 @@ class Arsenic(firebot.FireBot, ProcBot):
runcmd))
def rp(self, sender, forum, addl, match):
command = 'rp'
argstr = match.group('args')
Finger(('db.nic.lanl.gov', 5833),
argstr,
lambda l: self.proc_cb('%s: ' % command, sender, forum, l, 0))
bindings.append((re.compile(r"^(?P<command>rp) +(?P<args>.*)$"),
long = match.group('long') and True
conn = rp.make_connection()
rows = rp.rp(match.group('args').strip(), conn=conn)
ret = rp.format(rows, long=long)
if long:
forum.msg('[Sending privately]')
self.despool(sender, ret)
else:
self.despool(forum, ret)
bindings.append((re.compile(r"^rp +(?P<long>(-l|--long) +)?(?P<args>.*)$"),
rp))
def finger(self, sender, forum, addl, match):
@ -66,21 +71,6 @@ class Arsenic(firebot.FireBot, ProcBot):
bindings.append((re.compile(r"^\008[,: ]+ (what is the )?(server )?lag"),
lag))
def note(self, sender, forum, addl, match):
whom = match.group('whom')
what = match.group('what')
when = time.time()
key = '\013notes:%s' % whom
note = (when, sender.name(), what)
try:
n = self.db[key]
except KeyError:
n = []
n.append(note)
self.db[key] = n
forum.msg(self.gettext('okay', sender=sender.name()))
bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P<whom>[^: ]+):? +(?P<what>.*)"),
note))
bindings.extend(firebot.FireBot.bindings)
@ -142,7 +132,10 @@ class Arsenic(firebot.FireBot, ProcBot):
if __name__ == '__main__':
import daemon
import sys
debug = False
if "-d" in sys.argv:
debug = True
if not debug:

View File

@ -2,6 +2,7 @@ import irc
import re
import random
import types
import os
class Match:
"""A wrapper around a regex match, to replace \008 with a word.
@ -38,21 +39,17 @@ class BindingsBot(irc.Bot):
"""Save the traceback for later inspection"""
irc.Bot.err(self, exception)
t,v,tb = exception
tbinfo = []
info = []
while 1:
tbinfo.append ((
tb.tb_frame.f_code.co_filename,
tb.tb_frame.f_code.co_name,
str(tb.tb_lineno)
))
info.append('%s:%d(%s)' % (os.path.basename(tb.tb_frame.f_code.co_filename),
tb.tb_lineno,
tb.tb_frame.f_code.co_name))
tb = tb.tb_next
if not tb:
break
# just to be safe
del tb
file, function, line = tbinfo[-1]
info = '[' + '] ['.join(map(lambda x: '|'.join(x), tbinfo)) + ']'
self.last_tb = '%s %s %s' % (t, v, info)
del tb # just to be safe
infostr = '[' + '] ['.join(info) + ']'
self.last_tb = '%s %s %s' % (t, v, infostr)
print self.last_tb
def matches(self, text):

View File

@ -169,14 +169,14 @@ class InfoBot(BindingsBot):
bindings.append((re.compile(r"^\008[,: ]+unlock (?P<key>.+)$", re.IGNORECASE),
unlock_entry))
def forget_and_lock(self, sender, forum, addl, match):
def obliterate(self, sender, forum, addl, match):
key = match.group('key')
self.unlock(key)
self.delete(key)
self.lock(key)
forum.msg(self.gettext('okay', key=key, sender=sender.name()))
bindings.append((re.compile(r"^\008[,: ]+forget and lock (?P<key>.+)$", re.IGNORECASE),
forget_and_lock))
bindings.append((re.compile(r"^\008[,: ]+obliterate (?P<key>.+)$", re.IGNORECASE),
obliterate))
# Literal entry
def literal(self, sender, forum, addl, match):