more reload improvements

This commit is contained in:
Ryan Hitchman 2009-11-07 11:37:38 -07:00
parent 038793c226
commit d8026cb535
1 changed files with 12 additions and 7 deletions

View File

@ -8,6 +8,12 @@ if 'mtimes' not in globals():
if 'lastfiles' not in globals(): if 'lastfiles' not in globals():
lastfiles = set() lastfiles = set()
def format_plug(plug, lpad=0, width=40):
out = ' ' * lpad + '%s:%s:%s' % (plug[0])
if len(plug) == 3 and 'hook' in plug[2]:
out += '%s%s' % (' ' * (width - len(out)), plug[2]['hook'])
return out
def reload(init=False): def reload(init=False):
if init: if init:
bot.plugs = collections.defaultdict(lambda: []) bot.plugs = collections.defaultdict(lambda: [])
@ -52,9 +58,12 @@ def reload(init=False):
for type, data in obj._skybot_hook: for type, data in obj._skybot_hook:
bot.plugs[type] += [data] bot.plugs[type] += [data]
if type == 'init': if not init:
print '### new plugin (type: %s) loaded:' % type, format_plug(data)
if type == 'init': # run-once functions
try: try:
obj(bot) obj(bot) # not thread-safe!
except Exception: except Exception:
traceback.print_exc(Exception) traceback.print_exc(Exception)
@ -64,9 +73,5 @@ def reload(init=False):
print ' %s:' % type print ' %s:' % type
for plug in plugs: for plug in plugs:
out = ' %s:%s:%s' % (plug[0]) out = ' %s:%s:%s' % (plug[0])
print out, print format_plug(plug, lpad=6)
if len(plug) == 3 and 'hook' in plug[2]:
print '%s%s' % (' ' * (40 - len(out)), plug[2]['hook'])
else:
print
print print