本文整理汇总了Python中beaker.util.parse_cache_config_options方法的典型用法代码示例。如果您正苦于以下问题:Python util.parse_cache_config_options方法的具体用法?Python util.parse_cache_config_options怎么用?Python util.parse_cache_config_options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beaker.util
的用法示例。
在下文中一共展示了util.parse_cache_config_options方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from beaker import util [as 别名]
# 或者: from beaker.util import parse_cache_config_options [as 别名]
def __init__(self):
"""
Reads config, creates DB session, and initializes cache
"""
self.config_file_name = 'augur.config.json'
self.__shell_config = None
self.__export_file = None
self.__env_file = None
self.config = default_config
self.env_config = {}
self.root_augur_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
default_config_path = self.root_augur_dir + '/' + self.config_file_name
using_config_file = False
config_locations = [self.config_file_name, default_config_path, f"/opt/augur/{self.config_file_name}"]
if os.getenv('AUGUR_CONFIG_FILE') is not None:
config_file_path = os.getenv('AUGUR_CONFIG_FILE')
using_config_file = True
else:
for index, location in enumerate(config_locations):
try:
f = open(location, "r+")
config_file_path = os.path.abspath(location)
using_config_file = True
f.close()
break
except FileNotFoundError:
pass
if using_config_file:
try:
with open(config_file_path, 'r+') as config_file_handle:
self.config = json.loads(config_file_handle.read())
except json.decoder.JSONDecodeError as e:
logger.warn('%s could not be parsed, using defaults. Fix that file, or delete it and run this again to regenerate it. Error: %s', config_file_path, str(e))
else:
logger.warn('%s could not be parsed, using defaults.')
self.load_env_configuration()
# List of data sources that can do periodic updates
self.cache_config = {
'cache.type': 'file',
'cache.data_dir': 'runtime/cache/',
'cache.lock_dir': 'runtime/cache/'
}
if not os.path.exists(self.cache_config['cache.data_dir']):
os.makedirs(self.cache_config['cache.data_dir'])
if not os.path.exists(self.cache_config['cache.lock_dir']):
os.makedirs(self.cache_config['cache.lock_dir'])
cache_parsed = parse_cache_config_options(self.cache_config)
self.cache = CacheManager(**cache_parsed)
self.metrics = MetricDefinitions(self)