def get_template_content(path):
"""Read either yml or json files and store them as dict"""
template_dict = {}
_filename, file_extension = os.path.splitext(path)
file_extension = file_extension.replace('.', '')
if file_extension in consts.TEMPLATING_EXTS:
try:
template_content = {}
abs_path = os.path.abspath(os.path.expandvars(path))
with open(abs_path, 'r') as stream:
if file_extension in consts.JSON_EXTS:
template_content = json.load(stream) #nosec
elif file_extension in consts.YMAL_EXTS:
template_content = yaml.safe_load(stream) #nosec
template_dict.update(template_content)
except Exception as e:
logger.errorout("Error reading templating file",
file=path, error=e.message)
else:
logger.errorout("No templating file found",
file=path)
return template_dict
评论列表
文章目录