import sys, os, time, select from socket import * root = sys.argv[1] rev = int(sys.argv[2]) try: delay = float(sys.argv[3]) except: delay = 2.5 s = socket(AF_INET, SOCK_STREAM) s.connect(('irc.freenode.net', 6667)) channel = '#pypy' f = s.makefile('wb', 0) g = s.makefile('rb', 0) f.write('NICK svncibot\n\r') f.write('USER localhost localhost localhost :Subversion commits bot\n\r') f.write('JOIN %s\n\r' % channel) def tell(lines): lines = ["PRIVMSG %s :%s\n\r" % (channel, s) for s in lines] f.write(''.join(lines)) nextcheck = time.time() + delay*0.5 while 1: delay1 = max(nextcheck - time.time(), 0.1) iwtd, owtd, ewtd = select.select([g], [], [], delay1) if iwtd: line = g.readline() sys.stdout.write(line) if line.startswith('PING'): f.write('PONG :PING\n\r') else: cmdline = 'svn log %s -v -r %d' % (root, rev) print '<---', cmdline childin, childout, childerr = os.popen3(cmdline) childin.close() s = childout.read() childerr.read() childerr.close() print '--->', `s`[:50] if s: lines = s.split('\n') hdr = lines[1].strip().split('|') output = [hdr[0]] for i in range(3, len(lines)): line = lines[i].rstrip() if not line: break output.append(line) i += 1 if i < len(lines): output.append(lines[i].rstrip()) tell(['. '+s for s in output]) rev += 1 else: nextcheck = time.time() + delay