def parse_config(filename):
""" parses the YAML config file and expands any environment variables """
pattern = re.compile(r'^\<%= ENV\[\'(.*)\'\] %\>(.*)$')
yaml.add_implicit_resolver("!pathex", pattern)
def pathex_constructor(loader, node):
value = loader.construct_scalar(node)
envVar, remainingPath = pattern.match(value).groups()
return os.environ[envVar] + remainingPath
yaml.add_constructor('!pathex', pathex_constructor)
with open(filename) as f:
return(
yaml.load(f)
)
评论列表
文章目录