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