def parse_param_string(param):
"""Parses a parameter string such as 'param1=x,param2=y'. Loads
config files if specified in the string. If ``param`` points to a
file, load this file with YAML.
"""
if not param:
return {}
if os.path.isfile(param):
param = "config_file=%s" % param
config = {}
for pair in param.strip().split(","):
(k,v) = pair.split("=", 1)
if k == 'config_file':
if not YAML_AVAILABLE:
logging.fatal("Install PyYAML in order to use config files.")
else:
with open(v) as f:
data = yaml.load(f)
for config_file_key, config_file_value in data.items():
config[config_file_key] = config_file_value
else:
config[k] = v
return config
评论列表
文章目录