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: [])
@ -51,10 +57,13 @@ def reload(init=False):
if hasattr(obj, '_skybot_hook'): #check for magic if hasattr(obj, '_skybot_hook'): #check for magic
for type, data in obj._skybot_hook: for type, data in obj._skybot_hook:
bot.plugs[type] += [data] bot.plugs[type] += [data]
if not init:
print '### new plugin (type: %s) loaded:' % type, format_plug(data)
if type == 'init': 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