Ejemplo n.º 1
0
def init(loop, argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config='./config/polls.yaml')
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)

    config = commandline.config_from_options(options, TRAFARET)

    # setup application and extensions
    app = web.Application(loop=loop)

    # load config from yaml file in current dir
    app['config'] = config

    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates'))

    # create connection to the database
    app.on_startup.append(init_pg)
    # shutdown db connection on exit
    app.on_cleanup.append(close_pg)
    # setup views and routes
    setup_routes(app)
    setup_middlewares(app)

    return app
Ejemplo n.º 2
0
def init(loop, argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config='./config/polls.yaml')
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)

    config = commandline.config_from_options(options, TRAFARET)

    # setup application and extensions
    app = web.Application(loop=loop)

    # load config from yaml file in current dir
    app['config'] = config

    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates'))

    # setup views and routes
    setup_routes(app)
    setup_middlewares(app)

    return app
Ejemplo n.º 3
0
def init(loop, argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config='./config/polls.yaml')
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)

    config = commandline.config_from_options(options, TRAFARET)

    # setup application and extensions
    app = web.Application(loop=loop)

    # load config from yaml file in current dir
    app['config'] = config

    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(app,
                         loader=jinja2.PackageLoader('aiohttpdemo_polls',
                                                     'templates'))

    # create connection to the database
    app.on_startup.append(init_pg)
    # shutdown db connection on exit
    app.on_cleanup.append(close_pg)
    # setup views and routes
    setup_routes(app)
    setup_middlewares(app)

    # tracing
    trace_app(app, tracer, service='async-web')
    return app
Ejemplo n.º 4
0
async def init_app():
    app = web.Application()
    app['config'] = config
    aiohttp_jinja2.setup(app,
                         loader=jinja2.PackageLoader('aiohttpdemo_polls',
                                                     'templates'))
    app.on_startup.append(init_pg)
    app.on_cleanup.append(close_pg)
    setup_routes(app)
    setup_middlewares(app)
    return app
Ejemplo n.º 5
0
def function612(arg574, arg63):
    var1242 = argparse.ArgumentParser()
    commandline.standard_argparse_options(var1242,
                                          default_config='./config/polls.yaml')
    var4700 = var1242.parse_args(arg63)
    var2907 = commandline.config_from_options(var4700, TRAFARET)
    var206 = web.Application(loop=arg574)
    var206['config'] = var2907
    aiohttp_jinja2.setup(var206,
                         loader=jinja2.PackageLoader('aiohttpdemo_polls',
                                                     'templates'))
    var206.on_startup.append(init_pg)
    var206.on_cleanup.append(close_pg)
    setup_routes(var206)
    setup_middlewares(var206)
    return var206
Ejemplo n.º 6
0
async def init(loop):
    # setup application and extensions
    app = web.Application(loop=loop)
    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates'))
    # load config from yaml file in current dir
    conf = load_config(str(pathlib.Path('.') / 'config' / 'polls.yaml'))

    # create connection to the database
    db = await init_postgres(conf['postgres'], loop)
    app['db'] = db

    app.on_cleanup.append(close_pg)
    # setup views and routes
    setup_routes(app, PROJ_ROOT)
    setup_middlewares(app)

    host, port = conf['host'], conf['port']
    return app, host, port
Ejemplo n.º 7
0
async def init_app(argv=None):

    app = web.Application()

    app['config'] = get_config(argv)

    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates')
    )

    # create db connection on startup, shutdown on exit
    app.on_startup.append(init_pg)
    app.on_cleanup.append(close_pg)

    # setup views and routes
    setup_routes(app)

    setup_middlewares(app)

    return app
Ejemplo n.º 8
0
Archivo: main.py Proyecto: emmith/polls
async def init_app(argv=None):
    # 申请一个web应用,我们的网页的相关信息将要和它绑定
    app = web.Application()
    # 获取有关设置
    app['config'] = get_config(argv)
    # 设置渲染,也就是html相关的文件所在地
    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(app,
                         loader=jinja2.PackageLoader('aiohttpdemo_polls',
                                                     'templates'))

    # startup 建立数据库连接, 退出后则关闭
    app.on_startup.append(init_pg)
    app.on_cleanup.append(close_pg)

    # 设置视图和路由
    setup_routes(app)
    # 设置中间件
    setup_middlewares(app)

    return app
Ejemplo n.º 9
0
async def init(loop):
    # setup application and extensions
    app = web.Application(loop=loop)
    aiohttp_jinja2.setup(app, loader=jinja2.PackageLoader("aiohttpdemo_polls", "templates"))
    # load config from yaml file
    conf = load_config(str(PROJ_ROOT / "config" / "polls.yaml"))

    # create connection to the database
    pg = await init_postgres(conf["postgres"], loop)

    async def close_pg(app):
        pg.close()
        await pg.wait_closed()

    app.on_cleanup.append(close_pg)

    # setup views and routes
    handler = SiteHandler(pg)
    setup_routes(app, handler, PROJ_ROOT)
    setup_middlewares(app)

    host, port = conf["host"], conf["port"]
    return app, host, port
Ejemplo n.º 10
0
def init():
    loop = asyncio.get_event_loop()

    # setup application and extensions
    app = web.Application(loop=loop)

    # load config from yaml file in current dir
    conf = load_config(str(pathlib.Path('.') / 'config' / 'polls.yaml'))
    app['config'] = conf

    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates'))

    # create connection to the database
    app.on_startup.append(init_pg)
    # shutdown db connection on exit
    app.on_cleanup.append(close_pg)
    # setup views and routes
    setup_routes(app)
    setup_middlewares(app)

    return app
Ejemplo n.º 11
0
async def init(loop):
    # setup application and extensions
    app = web.Application(loop=loop)
    aiohttp_jinja2.setup(
        app, loader=jinja2.PackageLoader('aiohttpdemo_polls', 'templates'))
    # load config from yaml file
    conf = load_config(str(PROJ_ROOT / 'config' / 'polls.yaml'))

    # create connection to the database
    pg = await init_postgres(conf['postgres'], loop)

    async def close_pg(app):
        pg.close()
        await pg.wait_closed()

    app.on_cleanup.append(close_pg)

    # setup views and routes
    handler = SiteHandler(pg)
    setup_routes(app, handler, PROJ_ROOT)
    setup_middlewares(app)

    host, port = conf['host'], conf['port']
    return app, host, port
Ejemplo n.º 12
0
async def init(loop):
    # setup application and extensions
    app = web.Application(loop=loop)
    aiohttp_jinja2.setup(
        app, loader=jinja2.FileSystemLoader(str(TEMPLATES_ROOT)))
    # load config from yaml file
    conf = load_config(str(PROJ_ROOT / 'config' / 'polls.yaml'))

    # create connection to the database
    pg = await init_postgres(conf['postgres'], loop)

    async def close_pg(app):
        pg.close()
        await pg.wait_closed()

    app.on_cleanup.append(close_pg)

    # setup views and routes
    handler = SiteHandler(pg)
    setup_routes(app, handler, PROJ_ROOT)
    setup_middlewares(app)

    host, port = conf['host'], conf['port']
    return app, host, port