本文整理匯總了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)