def setup_app(loop=None, js_profiles_path=None):
app = web.Application(loop=loop, middlewares=[error_middleware])
js_profiles = {}
if js_profiles_path:
root, _, files, _ = next(os.fwalk(js_profiles_path))
js_files = filter(lambda f: os.path.splitext(f)[1] == '.js', files)
_, profile_name = os.path.split(root)
log.debug('adding profile "{}"'.format(profile_name))
js_profiles[profile_name] = ""
for f in js_files:
code = open(os.path.join(root, f)).read()
js_profiles[profile_name] += '{}\n'.format(code)
app.on_shutdown.append(on_shutdown)
c = Chrome(host=HOST, port=PORT)
app['chrome-driver'] = c
app['js-profiles'] = js_profiles
setup_routes(app)
return app
评论列表
文章目录