From fe3ece415c5c6d815bd0a88f86a92627e9baae6a Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 20 Jan 2011 06:41:01 -0500 Subject: add caching of parsed configs to util.get_base_cfg add caching of the parsed config, this will allow re-use in cloudinit so that we don't have to load the default config more than once in a program. --- cloudinit/util.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/util.py b/cloudinit/util.py index a2291164..f8c847aa 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -42,9 +42,12 @@ def read_conf(fname): return { } raise -def get_base_cfg(cfgfile,cfg_builtin=""): +def get_base_cfg(cfgfile,cfg_builtin="", parsed_cfgs=None): kerncfg = { } syscfg = { } + if parsed_cfgs and cfgfile in parsed_cfgs: + return(parsed_cfgs[cfgfile]) + contents = read_file_with_includes(cfgfile) if contents: syscfg = yaml.load(contents) @@ -58,9 +61,13 @@ def get_base_cfg(cfgfile,cfg_builtin=""): if cfg_builtin: builtin = yaml.load(cfg_builtin) + fin = mergedict(combined,builtin) else: - return(combined) - return(mergedict(combined,builtin)) + fin = combined + + if parsed_cfgs != None: + parsed_cfgs[cfgfile] = fin + return(fin) def get_cfg_option_bool(yobj, key, default=False): if not yobj.has_key(key): return default -- cgit v1.2.3