예제 #1
0
def get_config(argv: Any = None) -> Any:
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config=DEFAULT_CONFIG_PATH)
    options = ap.parse_args(argv)

    return commandline.config_from_options(options, CONFIG_TRAFARET)
예제 #2
0
async def init(argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap, default_config='./config/geonames.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()

    endpoint = az.create_endpoint('geonames_app', ipv4='127.0.0.1', port=9001)

    zipkin_address = 'http://127.0.0.1:9411'
    tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
    az.setup(app, tracer)

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

    # 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)

    return app
예제 #3
0
def init(loop, argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap, default_config='./config/organizations.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

    # create connection to the database
    app.on_startup.append(init_sqlite)

    app.on_cleanup.append(close_sqlite)

    # setup views and routes
    setup_routes(app)

    return app
예제 #4
0
def init_app(loop, argv):
    '''初始化程序实例'''
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config='./app/config.yaml')
    options = ap.parse_args(argv)
    config = commandline.config_from_options(options, TRAFARET)
    #上面的主要是读取配置文件

    app = web.Application(loop=loop)  #创建程序实例
    app['config'] = config  #将配置文件的内容加载进程序实例

    #提供template服务
    aiohttp_jinja2.setup(
        app,
        loader=jinja2.FileSystemLoader('../aiohttpLearn/public/templates/'))
    #或者像下面的这样,下面的这种情况需要public目录是一个python包
    # aiohttp_jinja2.setup(app,
    #                      loader=jinja2.PackageLoader('public','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
예제 #5
0
파일: main.py 프로젝트: ystallonne/ownconf
def init(loop, argv):
    """Init application."""
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap, default_config='./config/signalling.yaml')

    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

    room = Room()
    app['room'] = room

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

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

    return app
예제 #6
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
예제 #7
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
예제 #8
0
def init(loop, argv):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap, default_config='./config/webserver.yaml')
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)
    config = commandline.config_from_options(options, CONFIG_PARSER)

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

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

    # set up kvs db (redis)
    setup_kvs(app, loop, config['db']['redis'])

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

    # create connection to the database
    app.on_startup.append(kvs_connect)

    # shutdown db connection on exit
    app.on_cleanup.append(kvs_disconnect)

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

    return app
예제 #9
0
def init(argv):
    ap = ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config='./config/dev.yaml')
    options = ap.parse_args(argv)

    config = commandline.config_from_options(options, CONFIG_SCHEMA)

    app = Application(
        debug=True,
        middlewares=[
            session_middleware,
            # csrf_middleware,
            error_middleware,
        ])
    app['config'] = config

    setup_jinja(app,
                loader=PackageLoader('sqli', 'templates'),
                context_processors=[csrf_processor, auth_user_processor],
                autoescape=False)
    setup_database(app)
    setup_redis(app)
    setup_routes(app)

    return app
예제 #10
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
예제 #11
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
    print(jinja2.FileSystemLoader('./templates').list_templates())
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('./templates'))

    # create connection to the database
    app.on_startup.append(init_db)
    # shutdown db connection on exit
    app.on_cleanup.append(close_db)
    # setup views and routes
    myargs = {'path': {'client_id' : 1 }}
    asd = str('/pool/{client_id}').format_map(myargs['path'])
    setup_routes(app)
    setup_middlewares(app)
    return app
예제 #12
0
def get_config(argv):
    ap = argparse.ArgumentParser()
    config_path = '{root_dir}config/application.yaml'.format(root_dir=ROOT_DIR)
    commandline.standard_argparse_options(ap,
                                          default_config=config_path)
    options = ap.parse_args(argv)
    config = commandline.config_from_options(options, TRAFARET)
    return config
예제 #13
0
def get_config(argv=None):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config=DEFAULT_CONFIG_PATH)

    # ignore unknown options
    options, unknown = ap.parse_known_args(argv)

    return commandline.config_from_options(options, TRAFARET)
예제 #14
0
def load_config(argv, path='config/join.yaml'):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap, default_config=path)
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)

    return commandline.config_from_options(options, TRAFARET)
예제 #15
0
파일: common.py 프로젝트: jsandovalc/poster
def get_config(argv: Any = None) -> Any:
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap,
        default_config=DEFAULT_CONFIG_PATH,
    )
    options = ap.parse_args(argv)

    return commandline.config_from_options(options, CONFIG_TRAFARET)
예제 #16
0
def get_config(configuration_path, argv=None):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap,
        default_config=configuration_path,
    )

    options, unknown = ap.parse_known_args(argv)
    config = commandline.config_from_options(options, TRAFARET)

    return config
예제 #17
0
def get_config() -> Any:
    argv = ['-c', DEFAULT_CONFIG_PATH.as_posix()]

    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap,
        default_config=DEFAULT_CONFIG_PATH,
    )
    config = commandline.config_from_options(ap.parse_args(argv),
                                             CONFIG_TRAFARET)

    return config
예제 #18
0
def get_config(argv=None) -> dict:
    try:
        ap = argparse.ArgumentParser()
        commandline.standard_argparse_options(
            ap,
            default_config=DEFAULT_CONFIG_PATH,
        )
        options = ap.parse_args(argv)
        config = commandline.config_from_options(options, TRAFARET)
        return config
    except ConfigError as e:
        e.output()
        sys.exit(1)
예제 #19
0
def get_config(argv=None):

    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config=DEFAULT_CONFIG_PATH)

    options, unknown = ap.parse_known_args(argv)

    if argv:
        options.config = "{}/config/{}.yaml".format(BASE_DIR, options.config)

    config = commandline.config_from_options(options, TRAFARET)

    return config
예제 #20
0
def get_config(argv: Any = None) -> Any:
    """ Main function of config. Get default config or custom and
    verification them by trafaret scheme.

    :param argv: Any
    :return: Any
    """
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap,
        default_config=DEFAULT_CONFIG_PATH,
    )
    options = ap.parse_args(argv)

    return commandline.config_from_options(options, CONFIG_TRAFARET)
예제 #21
0
def get_config(request):
    """
    Get configuration from config.yaml, en_config.yaml

    :param request:
    :type request: pyramid.util.Request
    :return:
    :rtype Dict
    """
    ap_config_gen = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap_config_gen,
                                          default_config='config/config.yaml')
    options_config_gen = ap_config_gen.parse_args('')
    config_gen = commandline.config_from_options(options_config_gen, TRAFARET)
    # TODO languages from request
    ap_config_lan = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        ap_config_lan, default_config='config/en_config.yaml')
    options_config_lan = ap_config_lan.parse_args('')
    config_lan = commandline.config_from_options(options_config_lan,
                                                 TRAFARET_LAN)

    config = dicts_merge(config_gen, config_lan)
    return config
예제 #22
0
def config_from_options(options, vars=None):  # pylint: disable=W0622
    if vars is None:
        vars = os.environ

    if not os.path.exists(options.config):
        resource_name = options.config
        if resources.exists(resource_name):
            options.config = resources.get_path(resource_name)
        else:
            resource_name = resources.config_folder + '/' + resource_name
            if resources.exists(resource_name):
                options.config = resources.get_path(resource_name)

    logger.debug("Loading '%s'", options.config)

    return trafaret_config_cmd.config_from_options(options, trafaret=app_schema, vars=vars)
예제 #23
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
예제 #24
0
def config_from_options(options, vars=None): # pylint: disable=W0622
    if vars is None:
        vars = os.environ

    if not os.path.exists(options.config):
        resource_name = options.config
        if resources.exists(resource_name):
            options.config = resources.get_path(resource_name)
        else:
            resource_name = RSC_CONFIG_DIR_KEY + '/' + resource_name
            if resources.exists(resource_name):
                options.config = resources.get_path(resource_name)

    log.debug("loading %s", options.config)

    return commandline.config_from_options(options, trafaret=schema, vars=vars)
예제 #25
0
def config_from_options(options, schema, vars=None):  # pylint: disable=redefined-builtin
    if vars is None:
        vars = os.environ

    if not os.path.exists(options.config):
        resource_name = options.config
        if resources.exists(resource_name):
            options.config = resources.get_path(resource_name)
        else:
            resource_name = resources.config_folder + "/" + resource_name
            if resources.exists(resource_name):
                options.config = resources.get_path(resource_name)

    log.debug("Loading '%s'", options.config)

    return commandline.config_from_options(options, trafaret=schema, vars=vars)
예제 #26
0
def main():
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s - %(name)-12s - %(levelname)-5s - %(message)s',
        datefmt='%y-%m-%d %H:%M:%S'
    )

    parser = argparse.ArgumentParser()
    commandline.standard_argparse_options(parser, default_config='config/config.yaml')

    options, unknown = parser.parse_known_args()
    config = commandline.config_from_options(options, TRAFARET)

    server.on_startup.append(on_startup)
    server.on_shutdown.append(on_shutdown)
    server.run_server(config)
예제 #27
0
def config_from_options(options, vars=None):  # pylint: disable=W0622
    if vars is None:
        vars = os.environ

    if not os.path.exists(options.config):
        resource_name = options.config
        if resources.exists(resource_name):
            options.config = resources.get_path(resource_name)
        else:
            resource_name = resources.RESOURCE_CONFIG + '/' + resource_name
            if resources.exists(resource_name):
                options.config = resources.get_path(resource_name)

    log.debug("loading %s", options.config)

    return _tc_cli.config_from_options(options,
                                       trafaret=CONFIG_SCHEMA,
                                       vars=vars)
예제 #28
0
def get_config(argv: Any = None) -> Any:
    """
    Load settings to dict from YML-file
    :param argv:
    :return: Config dict
    """

    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap,
                                          default_config=DEFAULT_CONFIG_PATH)

    # ignore unknown options
    if isinstance(argv, str):
        options, unknown = ap.parse_known_args(['-c', argv])
    else:
        options, unknown = ap.parse_known_args(argv)

    config = commandline.config_from_options(options, TRAFARET)
    return config
예제 #29
0
파일: __main__.py 프로젝트: oohlaf/sprezz
def init(loop: AbstractEventLoop, argv: List[str]) -> Application:
    """Initialize Sprezz application."""
    arg_parser = argparse.ArgumentParser()
    commandline.standard_argparse_options(
        arg_parser,
        default_config='./config/sprezz.yaml')
    options = arg_parser.parse_args(argv)
    config = commandline.config_from_options(options, TRAFARET)
    app = Application(loop=loop, middlewares=[db])
    app['config'] = config
    app['config']['netloc'] = netloc(config)
    app.on_startup.append(init_remotes)
    db.init_app(app)
    registry = Registry()
    app['registry'] = registry
    scanner = venusian.Scanner(app=app)
    scanner.scan(sprezz)
    setup_routes(app)
    return app
예제 #30
0
def init(argv):

    ap = argparse.ArgumentParser()
    dirPath = os.path.dirname(os.path.realpath(__file__))
    configFile = os.path.abspath(os.path.join(dirPath,
                                              '../config/config.yaml'))
    commandline.standard_argparse_options(ap, default_config=configFile)
    #
    # define your command-line arguments here
    #
    options = ap.parse_args(argv)

    config = commandline.config_from_options(options, TRAFARET)

    # setup application and extensions
    loop = asyncio.get_event_loop()
    if isinstance(loop, zmq.asyncio.ZMQEventLoop):
        loop = loop
    else:
        loop = zmq.asyncio.ZMQEventLoop()
        asyncio.set_event_loop(loop)

    app = web.Application(loop=loop)

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

    # websockets
    app['websockets'] = {'Debug': None}

    # create connection to the database
    app.on_startup.append(init_pg)
    # shutdown db connection on exit
    app.on_cleanup.append(close_pg)

    # create log server
    app.on_startup.append(init_log_server)
    # create connection to regression server
    app.on_startup.append(init_regression)
    # setup views and routes
    setup_routes(app)

    return app
예제 #31
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument('--path')
    commandline.standard_argparse_options(ap, default_config='config.yaml')
    #
    # define your command-line arguments here
    #
    options = ap.parse_args()
    config = commandline.config_from_options(options, TRAFARET)

    app = web.Application()
    app['config'] = config

    setup_handlers(app)

    if options.path:
        web.run_app(app, path=options.path)
    else:
        web.run_app(app)
예제 #32
0
def get_config(argv=None) -> dict:
    ap = argparse.ArgumentParser()

    # TODO: pass configuration to load via command line
    # TODO: pass configuration to init db via command line
    commandline.standard_argparse_options(
        ap,
        default_config=DEFAULT_CONFIG_PATH
    )

    # ignore unknown options
    options, unknown = ap.parse_known_args(argv)

    config = commandline.config_from_options(options, T_SCHEMA)

    if "IS_CONTAINER_CONTEXT" in os.environ.keys():
        config['host'] = '0.0.0.0'
        config['postgres']['host'] = 'db'

    _LOGGER.debug("Loading config %s \n\t %s", argv, config)

    return config
예제 #33
0
def get_config(argv, filepath):
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap, default_config=filepath)
    options, unknown = ap.parse_known_args(argv)
    config = commandline.config_from_options(options, TRAFARET)
    return config
예제 #34
0
def main():
    ap = argparse.ArgumentParser()
    commandline.standard_argparse_options(ap, default_config='config.yaml')
    options = ap.parse_args()
    config = commandline.config_from_options(options, TRAFARET)
    pprint.pprint(config)