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 os
import time import time
import socket import socket
import rp
def esc(arg): def esc(arg):
return "'" + arg.replace("'", r"'\''") + "'" return "'" + arg.replace("'", r"'\''") + "'"
@ -21,7 +22,7 @@ class Arsenic(firebot.FireBot, ProcBot):
debug = False debug = False
bindings = [] bindings = []
ping_interval = 120 ping_interval = 120
chatty = False # #x can't play nice chatty = True # Maybe #x can play nice now
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
firebot.FireBot.__init__(self, *args, **kwargs) firebot.FireBot.__init__(self, *args, **kwargs)
@ -44,12 +45,16 @@ class Arsenic(firebot.FireBot, ProcBot):
runcmd)) runcmd))
def rp(self, sender, forum, addl, match): def rp(self, sender, forum, addl, match):
command = 'rp' long = match.group('long') and True
argstr = match.group('args') conn = rp.make_connection()
Finger(('db.nic.lanl.gov', 5833), rows = rp.rp(match.group('args').strip(), conn=conn)
argstr, ret = rp.format(rows, long=long)
lambda l: self.proc_cb('%s: ' % command, sender, forum, l, 0)) if long:
bindings.append((re.compile(r"^(?P<command>rp) +(?P<args>.*)$"), 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)) rp))
def finger(self, sender, forum, addl, match): 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"), bindings.append((re.compile(r"^\008[,: ]+ (what is the )?(server )?lag"),
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) bindings.extend(firebot.FireBot.bindings)
@ -142,8 +132,11 @@ class Arsenic(firebot.FireBot, ProcBot):
if __name__ == '__main__': if __name__ == '__main__':
import daemon import daemon
import sys
debug = True debug = False
if "-d" in sys.argv:
debug = True
if not debug: if not debug:
# Become a daemon # Become a daemon

View File

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

View File

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