当前位置: 首页>>代码示例>>Python>>正文


Python config.Config类代码示例

本文整理汇总了Python中flask.config.Config的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, settings=None):
        
        self.settings = settings
        
        log_cfg = Config('')

        log_cfg.from_pyfile( settings['LOGGING_CONFIG'])        
        
        self.log = logging_factory.get_logger(settings['APP_NAME'], settings['LOGGING_PATH'], log_cfg['LOGGING'])
        
        self.dbattr_dict = {'ORA':'ora_db','PG':'pg_db', 'DB':'db'}
        
        self.name_dict = {'ORA':'oracle','PG':'postgresql', 'DB':'oracle'}
        
        #import dbsession after logger initialized
        from mabolab.database import dbfactory
        
        for db_type in settings['DB_TYPE']:       

            if not hasattr(self, self.dbattr_dict[db_type]):
                #self.log.debug("set %s" %(db_type) )
                setattr(self, self.dbattr_dict[db_type], dbfactory.get_db(self.name_dict[db_type], settings) )
        
        if not hasattr(self, 'db'):
            setattr(self, 'db', dbfactory.get_db(self.name_dict['DB'], settings) )
开发者ID:mabotech,项目名称:maboss.py,代码行数:25,代码来源:base.py

示例2: cli

def cli(ctx):
    '''
    Access and modify data from a PISS server on the command line.
    '''
    current_dir = os.path.dirname(os.path.realpath(__file__))
    config_file = os.path.splitext(os.path.basename(__file__))[0] + ".cfg"

    ctx.obj = {}
    ctx.obj['current_dir'] = current_dir
    ctx.obj['config_file'] = config_file

    if ctx.args[0] != 'register':
        if not os.path.isfile(os.path.join(current_dir, config_file)):
            click.echo('No configuration file found! Use `register <url>`  to\
 create one!')
            ctx.abort()

        try:
            app_config = Config(current_dir)
            app_config.from_pyfile(config_file)
        except Exception as e:
            click.echo('Could not load config from file. Use `register <url>`\
 to create a new one!')
            ctx.abort()

        try:
            ctx.obj['credentials'] = app_config['CREDENTIALS']
            ctx.obj['meta_url'] = app_config['META_URL']
            meta_post = app_config['META_POST']
            ctx.obj['meta_post'] = meta_post
            ctx.obj['url'] = meta_post['server']['urls']['posts_feed']
        except Exception as e:
            click.echo('Parameters missing from configuration file! Use\
 `register <url>` to fix!')
            ctx.abort()
开发者ID:dephraser,项目名称:piss,代码行数:35,代码来源:piss_cli.py

示例3: app_config

def app_config(postgres_user_conf):
    from flask.config import Config
    from datacat.settings import testing

    conf = Config('')
    conf.from_object(testing)
    conf['DATABASE'] = postgres_user_conf
    return conf
开发者ID:rshk-archive,项目名称:datacat-poc-140825,代码行数:8,代码来源:conftest.py

示例4: setUp

    def setUp(self):
    
        tmp = '../config/logging_config.py'
        
        
        log_cfg = Config('')

        log_cfg.from_pyfile(tmp)    
       
        self.logging_cfg = log_cfg['LOGGING']        
开发者ID:mabotech,项目名称:mabopy,代码行数:10,代码来源:test_logging.py

示例5: load_config

def load_config():
    cfg = Config(dirname(dirname(__file__)))
    cfg.from_object("autobit.settings")
    if "AUTOBIT_SETTINGS" in os.environ:
        cfg.from_envvar("AUTOBIT_SETTINGS")

    if not exists(cfg['WATCH_DIR']):
        logger.info("Creating watch dir: {}".format(cfg['WATCH_DIR']))
        os.makedirs(cfg['WATCH_DIR'])

    return cfg
开发者ID:leighmacdonald,项目名称:autobit,代码行数:11,代码来源:__init__.py

示例6: load

def load(config_filename='settings.py'):
    """Create a Flask config that will be used to update the application
    config when it is created."""
    config = Config("pjuu")

    # Load the default settings
    config.from_pyfile(config_filename)

    # Load the setting from the Environment variable
    config.from_envvar('PJUU_SETTINGS', silent=True)

    return config
开发者ID:pjuu,项目名称:pjuu,代码行数:12,代码来源:configurator.py

示例7: configs

    def configs(self):
        if not hasattr(self, '_configs'):
            configs = Config(ROOT)
            resoure = ResourceLoader.get().get_resoure('settings.py')
            config_files = resoure.as_list()
            if config_files:
                for path in config_files:
                    configs.from_pyfile(path)
            else:
                raise Exception('need a configuration file to start app')

            self._configs = configs
        return self._configs
开发者ID:IamFive,项目名称:vclassifieds,代码行数:13,代码来源:env.py

示例8: download_users

def download_users():
    """
    Download users.xml file.
    """
    import urllib2
    from flask.config import Config
    config = Config(etc())
    config.from_pyfile("deploy.cfg")
    response = urllib2.urlopen(config['USERS_URL'])
    users_xml = os.path.join('runtime', 'data', 'users.xml')
    if response.code == 200:
        with open(users_xml, 'w') as f:
            f.write(response.read())
开发者ID:stxnext-kindergarten,项目名称:presence-analyzer-mslowinski,代码行数:13,代码来源:script.py

示例9: __init__

    def __init__(self, import_name, middlewares=None, loop=None, session=None):
        self.import_name = import_name
        self.root_path = get_root_path(import_name)
        self.config = Config(self.root_path, default_config)

        self._context = {}
        self._loop = loop or asyncio.get_event_loop()
        self._middlewares = SpiderMiddlewareManager(self, middlewares)
        self._session = session or aiohttp.ClientSession(loop=self._loop)
开发者ID:jmcarp,项目名称:pycrawl,代码行数:9,代码来源:core.py

示例10: __init__

 def __init__(self, debug=False):
     self.valid = True
     # loggerを初期化する
     logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s')
     logger = logging.getLogger(self.service_name)
     logger.setLevel(logging.DEBUG)
     self.logger = logger
     # 設定ファイルからAPIkeyとかを読み込む
     current_dir = os.path.dirname(__file__)
     config = Config('../../')
     if os.path.exists(activate_this):
         config.from_pyfile("wsgi_dev.cfg")
     else:
         config.from_pyfile("dev.cfg")
     #self.logger.debug(config)
     self.validate(self.require_config, config['EXTERNAL_CONFIG'])
     self.config = config['EXTERNAL_CONFIG']
     self.debug = config['POST_DEBUG']
开发者ID:yuiseki,项目名称:python_postutil,代码行数:18,代码来源:postutil.py

示例11: test_settings_abs_path

    def test_settings_abs_path(self):
        """Check if the config obj is updated with default_settings when it is 
        passed as a python file absolute path
        """
        abs_path = getcwd() + '/arachne/tests/test_settings.py'
        test_app = self.create_app(settings=abs_path)

        # load config from pyfile
        flask_app = Flask(__name__)
        flask_app.config.from_object('arachne.default_settings')

        config_cls = Config(__name__)
        config_cls.from_pyfile(abs_path)

        # update config with the arachne default settings
        flask_app.config.update(config_cls)

        # test if config dicts are same
        self.assertEquals(test_app.config, flask_app.config)
开发者ID:bjzt10161,项目名称:arachne,代码行数:19,代码来源:test_flaskapp.py

示例12: ImmutableDict

class CartesiusSuite :
	#: Default configuration parameters.
	default_config = ImmutableDict({
		'DEBUG':                                False,
		'SERVER_NAME':                          None,
		'APPLICATION_ROOT':                     None
	})

	def __init__(self, configuration = None) :
		self.make_config(configuration)
		self.make_servers()

	def make_config(self, configuration):
		self.config = Config(None, self.default_config)
		
		if (configuration) :
			self.config.from_object(configuration)

	def make_servers(self) :
		self.servers = {}
		for server in self.config['SERVERS'] :
			server_path = self.config['SERVER_PATH'] + "." + server['path'] + "."
			if( 'app_name' in server ) :
				server_path += server['app_name']
			else :
				server_path += 'app'
			self.servers[server['name']] = CartesiusServer(server_path)

	def start(self, server) :
		self.servers[server].start()

	def start_all(self) :
		for server in self.servers :
			self.servers[server].start()

	def stop(self, server) :
		self.servers[server].stop()

	def stop_all(self) :
		for server in self.servers :
			server.stop()
开发者ID:chebizarro,项目名称:cartesius-suite,代码行数:41,代码来源:app.py

示例13: test_settings_abs_path

    def test_settings_abs_path(self):
        """Check if the config obj is updated with default_settings when it is 
        passed as a python file absolute path
        """
        abs_path = getcwd() + '/arachne/tests/test_settings.py'
        test_app = self.create_app(settings=abs_path)

        # since the object initialized created is always different
        # we ignore CRAWLER_PROCESS setting for test
        if SCRAPY_VERSION >= (1, 0, 0):
            del test_app.config['CRAWLER_PROCESS']

        # load config from pyfile
        flask_app = Flask(__name__)
        flask_app.config.from_object('arachne.default_settings')

        config_cls = Config(__name__)
        config_cls.from_pyfile(abs_path)

        # update config with the arachne default settings
        flask_app.config.update(config_cls)

        # test if config dicts are same
        self.assertEquals(test_app.config, flask_app.config)
开发者ID:JallyHe,项目名称:arachne,代码行数:24,代码来源:test_flaskapp.py

示例14: make_config

def make_config(app=None):
    if app is not None:
        cfg = app.config
    else:
        from flask.config import Config
        root_path = os.path.dirname(__file__).rsplit('/', 1)[0]
        cfg = Config(root_path)

    # customize config here
    cfg.from_object(default_config)
    cfg.from_pyfile('myapp.cfg', silent=True)
    cfg.from_envvar('MYAPP_CONFIG', silent=True)
    cfg['BABEL_DEFAULT_LOCALE'] = cfg['LANG']
    return cfg
开发者ID:haje01,项目名称:flask-plate,代码行数:14,代码来源:make_config.py

示例15: __init__

 def __init__(self, config=None):
     self.config = Config()
     if config is not None:
         self.config.update(config)
开发者ID:rshk-archive,项目名称:datacat-poc-141007,代码行数:4,代码来源:core.py


注:本文中的flask.config.Config类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。