cli.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:slam 作者: miguelgrinberg 项目源码 文件源码
def _generate_lambda_handler(config, output='.slam/handler.py'):
    """Generate a handler.py file for the lambda function start up."""
    # Determine what the start up code is. The default is to just run the
    # function, but it can be overriden by a plugin such as wsgi for a more
    # elaborated way to run the function.
    run_function = _run_lambda_function
    for name, plugin in plugins.items():
        if name in config and hasattr(plugin, 'run_lambda_function'):
            run_function = plugin.run_lambda_function
    run_code = ''.join(inspect.getsourcelines(run_function)[0][1:])

    # generate handler.py
    with open(os.path.join(os.path.dirname(__file__),
                           'templates/handler.py.template')) as f:
        template = f.read()
    template = render_template(template, module=config['function']['module'],
                               app=config['function']['app'],
                               run_lambda_function=run_code,
                               config_json=json.dumps(config,
                                                      separators=(',', ':')))
    with open(output, 'wt') as f:
        f.write(template + '\n')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号