01ce193
#!/usr/bin/python
01ce193
# Clean out files which look to have been generated by antlr
01ce193
# Author: Colin Walters <walters@verbum.org>
01ce193
# This file is hereby placed into the public domain.
01ce193
01ce193
import os,sys,re
01ce193
01ce193
_antlr_compiled_re = re.compile(r'// \$ANTLR.*:.*->.*\$$')
01ce193
01ce193
def clean_antlr_generated(basedir):
01ce193
  for (dpath,subdirs,fnames) in os.walk(basedir):
01ce193
    for fname in fnames:
01ce193
      fpath = os.path.join(dpath, fname)
01ce193
      f = open(fpath)
01ce193
      first = f.readline()
01ce193
      f.close()
01ce193
      if _antlr_compiled_re.match(first):
01ce193
        print "Deleting antlr-compiled %s" % (fpath,)
01ce193
        os.unlink(fpath)
01ce193
01ce193
if __name__ == '__main__':
01ce193
  basedir = sys.argv[1]
01ce193
  clean_antlr_generated(basedir)