diff options
-rw-r--r-- | ec2init/util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ec2init/util.py b/ec2init/util.py new file mode 100644 index 00000000..8b36274e --- /dev/null +++ b/ec2init/util.py @@ -0,0 +1,29 @@ +import yaml + +def read_conf(fname): + stream = file(fname) + conf = yaml.load(stream) + stream.close() + return conf + +def get_cfg_option_bool(yobj, key, default=False): + if not yobj.has_key(key): return default + val = yobj[key] + if yobj[key] in [ True, '1', 'on', 'yes', 'true']: + return True + return False + +def get_cfg_option_str(yobj, key, default=None): + if not yobj.has_key(key): return default + return yobj[key] + +# merge values from src into cand. +# if src has a key, cand will not override +def mergedict(src,cand): + if isinstance(src,dict) and isinstance(cand,dict): + for k,v in cand.iteritems(): + if k not in src: + src[k] = v + else: + src[k] = merge(src[k],v) + return src |