#!/usr/bin/env /usr/local/share/bin/awe

import os
from compileall import compile_dir
awe_home = os.environ['AWEPIPE']
compile_dir(awe_home)

def visit(arg, dirname, names):
    for name in names:
        # Remove .pyc/.pyo files for which no .py file exists
        if name[-4:] == '.pyc' or name[-4:] == 'pyo':
            pyfile = os.path.join(dirname, name[:-1])
            if not os.path.exists(pyfile):
                os.remove(os.path.join(dirname, name))

os.path.walk(awe_home, visit, None)
