#!/usr/bin/python # Automatic recompiler for Flash programs, using the fcsh shell. This # program watches for changes to the source files; whenever one is # changed, it triggers a recompile. # Copyright 2007 Amit J Patel import os, time, select pw, pr, pe = os.popen3('fcsh', 'w') LOG_FILE = 'compile.log' last_compile = os.stat('main.swf').st_mtime def any_files_changed(): for filename in os.listdir('.'): if filename.endswith('.as') and not filename.startswith('.'): if os.stat(filename).st_mtime >= last_compile: return True return False def send(msg): receive() pw.write(msg) pw.flush() print msg, def receive(): log = open(LOG_FILE, 'w') while True: ready, _, _ = select.select([pe, pr], [], [], 1) if pr in ready: line = os.read(pr.fileno(), 10000) log.write(line) print line, elif pe in ready: line = os.read(pe.fileno(), 10000) log.write(line) print line, else: break send('mxmlc -optimize -creator amitp@cs.stanford.edu main.as\n') receive() while True: print 'Recompiling' last_compile = time.time() send('compile 1\n') receive() while not any_files_changed(): time.sleep(0.5)