from recordbot import RecordBotFactory, Reply from parseHistory import doit import textwrap, sys factory = RecordBotFactory(doit()) f = open('recordbotdocs0.txt') o = open('recordbotdocs1.txt', 'w') ass = None cmds = set() cmdprefix = '* ``recordbot: ' for line in f: if line.startswith(cmdprefix): cmd = line[len(cmdprefix):].split(None, 1)[0].strip('`:') if cmd == '': cmd = 'level' cmds.add(cmd.upper()) if '[assert]' in line: ass = line.split(']', 1)[1].strip() continue print >>o, line[:-1] if line.startswith(' <') and '> recordbot: ' in line: i = line.index('> recordbot: ') + len('> recordbot: ') cmd = line[i:-1] if cmd == "table coop": WIDTH = 10000 else: WIDTH = 90 commands = line[i:-1].split() reply = Reply(None, None, None, None) if commands: cmds.add(commands[0].upper()) try: factory.command(reply, commands) except: import pdb pdb.post_mortem(sys.exc_traceback) output = list(reply.getlines()) if ass: exec 'assert (%s), errmsg'%(ass,) \ in {'output':"\n".join(output), 'errmsg':"%r failed during %r"%(ass, commands)} ass = None for l in output: for l2 in textwrap.wrap(l, WIDTH, initial_indent= ' ', subsequent_indent=' '): print >>o, l2 notdocced = [] for n in dir(factory): if n.startswith('command_'): f = getattr(factory, n).im_func n = n[len('command_'):] if not getattr(f, 'nodoc', False) and n not in cmds: notdocced.append(n) if notdocced: print "you haven't documented these functions:" for n in notdocced: print '-', n print "get to it!" else: print 'you appear to have documented everything.'