@stay_put
def _compile(args):
    path = args.path
    os.chdir(path)
    if os.getcwd() not in sys.path:
        sys.path.insert(0, os.getcwd())

    import settings
    SETTINGS = {k:v for k,v in vars(settings).items() \
                        if not k.startswith('__')}
    import handlers

    if os.path.isfile('app'):
        sys.exit("Fatal: \
            There can't be a file named 'app' in the project dir.")
    elif os.path.isdir('app'):
        shutil.rmtree('app')
    shutil.copytree(
        os.path.join(ASHIBA_SHARE, 'compiled_project_files'), 'app')

    ENAML = False
    if os.path.isfile('myapp.enaml'):
        compile_enaml('myapp.enaml')
        ENAML = True

    for fname in [x for x in os.listdir('.') if not x.startswith('.')]:
        root, ext = os.path.splitext(fname)
        if ext in ['.py']:
            shutil.copy(fname, os.path.join('app', fname))
        elif ext == '.html':
            if root != 'myapp':
                shutil.copy(fname, os.path.join('app', 'templates', fname))
            elif not ENAML:
                in_file = open(fname)
                out_file = open(os.path.join('app', 'templates', fname), 'w')
                out_file.write(templatify_html(in_file))
                out_file.close()

    if os.path.isdir('static'):
        for item in [os.path.join('static', x) for x in os.listdir('static')]:
            src, dst = item, os.path.join('app', item)
            if os.path.isdir(item):
                shutil.copytree(src, dst)
            else:
                shutil.copy(src, dst)

    for item in SETTINGS.get('DATA_FILES', []):
        src, dst = item, os.path.join('app', item)
        try:
            shutil.copy(src, dst)
        except __HOLE__:
            print 'Error copying "{}".'.format(item)
        else:
            print 'Copied data file:', item

    file_path = os.path.join('app','static','ashiba_compiled.js')
    print "Writing to:", os.path.abspath(file_path)
    outfile = open(file_path, 'w')
    outfile.write("/* Compiled with Ashiba v{} */\n".format(ashiba.__version__))
    outfile.write("\n$(window).load(function(){")
    fcn_names = [k for k in vars(handlers) if re.match('[\\w]+?__[\\w]+', k)]

    for fcn_name in fcn_names:
        print "--> Translating", fcn_name
        name, event = fcn_name.rsplit('__', 1)
        if name.startswith('_'):
            selector = '.'
        else:
            selector = '#'
        jquery_string = """
  $("{selector}{name}").on("{event}",
    ashiba.eventHandlerFactory("{name}", "{event}")
  );""".format(selector=selector, name=name.lstrip('_'), event=event)

        outfile.write(jquery_string)

    outfile.write("\n});") #end document.ready
    outfile.close()
dataset/ETHPy150Open ContinuumIO/ashiba/ashiba/main.py/_compile