From c0e2f8d39e2581335390561e7d8a4d8deefd7e56 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 7 Feb 2011 13:04:40 -0500 Subject: add utility function get_cfg_by_path --- cloudinit/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'cloudinit') diff --git a/cloudinit/util.py b/cloudinit/util.py index d6b1860b..40925b94 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -82,6 +82,15 @@ def get_cfg_option_list_or_str(yobj, key, default=None): if isinstance(yobj[key],list): return yobj[key] return([yobj[key]]) +# get a cfg entry by its path array +# for f['a']['b']: get_cfg_by_path(mycfg,('a','b')) +def get_cfg_by_path(yobj,keyp,default=None): + cur = yobj + for tok in keyp: + if tok not in cur: return(default) + cur = cur[tok] + return(cur) + # merge values from src into cand. # if src has a key, cand will not override def mergedict(src,cand): -- cgit v1.2.3