Exemple #1
0
async def init(argv=None):

    # app = web.Application()
    loop = asyncio.get_event_loop()

    app = web.Application(loop=loop)
    # app = web.Application(loop=loop, middlewares=[toolbar_middleware_factory])
    # aiohttp_debugtoolbar.setup(app)
    #http://127.0.0.1:9000/_debugtoolbar

    app['settings'] = Settings

    # 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_static_routes(app)
    setup_templates_routes(app)

    # set up
    setup_middlewares(app)
    setup_sessions(app)

    return app
Exemple #2
0
async def init_app():

    app = web.Application()

    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(
                             str(PROJECT_ROOT / 'templates')))
    app['game'] = Colorfight()
    app['game_sockets'] = []
    setup_routes(app)
    setup_static_routes(app)

    return app
Exemple #3
0
async def init_app():
    app = web.Application()

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

    setup_routes(app)
    setup_static_routes(app)

    app['websockets'] = {}

    app.on_startup.append(init_redis)
    app.on_shutdown.append(shutdown)

    return app
Exemple #4
0
async def init_app():

    app = web.Application()

    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(
                             str(PROJECT_ROOT / 'templates')))
    app['game'] = {}
    app['game']['public'] = Colorfight()
    app['game']['public'].replay_lock = asyncio.Lock(
        loop=asyncio.get_event_loop())
    app['game_sockets'] = []
    app['admin_password'] = os.getenv('ADMIN_PASSWORD', "")
    app['firebase'] = Firebase()
    app['process_executor'] = concurrent.futures.ProcessPoolExecutor()
    app['thread_executor'] = concurrent.futures.ThreadPoolExecutor()
    setup_routes(app)
    setup_static_routes(app)

    return app
Exemple #5
0
def main():
    app = web.Application(debug=True)

    fernet_key = fernet.Fernet.generate_key()
    secret_key = base64.urlsafe_b64decode(fernet_key)
    setup(app, EncryptedCookieStorage(secret_key))

    aiohttp_jinja2.setup(app,
                         loader=jinja2.PackageLoader(package_name='main',
                                                     package_path='templates'),
                         context_processors=[current_user])

    setup_routes(app)
    setup_static_routes(app)
    app['static_root_url'] = '/static'

    app['config'] = BaseConfig
    logging.basicConfig(level=logging.DEBUG)

    web.run_app(app, host='0.0.0.0', port=8080)
Exemple #6
0
async def init_app():

    app = web.Application()

    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(
                             str(PROJECT_ROOT / 'templates')))
    init_gamerooms(app)
    app['config'] = {}
    app['config']['max_gameroom_number'] = 15
    app['config']['idle_clear_time'] = 600
    app['config']['allow_create_room'] = True
    app['game_sockets'] = []
    app['admin_password'] = os.getenv('ADMIN_PASSWORD', "")
    app['firebase'] = Firebase()
    app['process_executor'] = concurrent.futures.ProcessPoolExecutor()
    app['thread_executor'] = concurrent.futures.ThreadPoolExecutor()
    setup_routes(app)
    setup_static_routes(app)

    return app
Exemple #7
0
def main():
    # config
    args = parse_args()
    config = load_config(args.config)

    # database
    # print('SQLite {}'.format(sql('select sqlite_version()')[0][0]))

    # bot
    # threading.Thread(target=bot).start()

    # webapp
    app = web.Application()
    app.on_response_prepare.append(on_response_prepare)
    setup_static_routes(app)
    setup_routes(app)
    setup_middlewares(app)
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('app/templates'))
    web.run_app(app,
                host=config['host'],
                port=config['port'],
                ssl_context=tls(config))
Exemple #8
0
async def init_app(argv=None):

    # app = web.Application()
    loop = asyncio.get_event_loop()
    app = web.Application(loop=loop)

    app['config'] = get_config(argv)

    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    app['BASE_DIR'] = BASE_DIR
    # 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_static_routes(app)
    setup_templates_routes(app)

    # set up
    setup_middlewares(app)
    setup_sessions(app)

    return app
Exemple #9
0
    LOGGER.info("Opening steward_wallet")
    app['handles']['wallet'] = await wallet.open_wallet(
        f'{{"id": "{WALLET}"}}', f'{{"key": "{WALLETKEY}"}}')
    for pool_name in app['handles']['pools']:
        LOGGER.info(f"Connecting to pool: {pool_name}")
        app['handles']['pools'][pool_name] = await pool.open_pool_ledger(
            pool_name, None)


async def close_handles():
    LOGGER.info("Closing steward_wallet")
    await wallet.close_wallet(app['handles']['wallet'])
    for pool_name in app['handles']['pools']:
        LOGGER.info(f"Closing pool: {pool_name}")
        await pool.close_pool_ledger(app['handles']['pools'][pool_name])


## - Main - ##
logging.basicConfig(level=LOG_LEVEL)

LOOP = asyncio.get_event_loop()
LOOP.run_until_complete(open_handles())

setup_routes(app)
setup_static_routes(app)
web.run_app(app, host='127.0.0.1', port=8080)

LOOP = asyncio.new_event_loop()
LOOP.run_until_complete(close_handles())
LOOP.close()