diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-18 13:36:19 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-18 13:36:19 -0700 |
commit | d6cfa558c060d3e19073cc569590afc9a2f1b9ff (patch) | |
tree | 87ecbdfb566d59fbe3437e39bce032f4185dcfd1 | |
parent | 0eabf9cdc2870982bcabc6e5d05c80078fa100cb (diff) | |
parent | 8e97ca8cfaf75edc0b05b0dc2a2ef35c5c82221b (diff) | |
download | vyos-cloud-init-d6cfa558c060d3e19073cc569590afc9a2f1b9ff.tar.gz vyos-cloud-init-d6cfa558c060d3e19073cc569590afc9a2f1b9ff.zip |
Pull from head and a couple more tweaks.
-rw-r--r-- | cloudinit/mergers/__init__.py | 11 | ||||
-rw-r--r-- | cloudinit/mergers/m_dict.py (renamed from cloudinit/mergers/dict.py) | 0 | ||||
-rw-r--r-- | cloudinit/mergers/m_list.py (renamed from cloudinit/mergers/list.py) | 9 | ||||
-rw-r--r-- | cloudinit/mergers/m_str.py (renamed from cloudinit/mergers/str.py) | 2 |
4 files changed, 13 insertions, 9 deletions
diff --git a/cloudinit/mergers/__init__.py b/cloudinit/mergers/__init__.py index e1ff57ba..f504e15f 100644 --- a/cloudinit/mergers/__init__.py +++ b/cloudinit/mergers/__init__.py @@ -26,6 +26,8 @@ NAME_MTCH = re.compile(r"(^[a-zA-Z_][A-Za-z0-9_]*)\((.*?)\)$") LOG = logging.getLogger(__name__) DEF_MERGE_TYPE = "list()+dict()+str()" +MERGER_PREFIX = 'm_' +MERGER_ATTR = 'Merger' class UnknownMerger(object): @@ -136,15 +138,18 @@ def default_mergers(): def construct(parsed_mergers): mergers_to_be = [] for (m_name, m_ops) in parsed_mergers: + if not m_name.startswith(MERGER_PREFIX): + m_name = MERGER_PREFIX + str(m_name) merger_locs = importer.find_module(m_name, [__name__], - ['Merger']) + [MERGER_ATTR]) if not merger_locs: - msg = "Could not find merger named '%s'" % (m_name) + msg = ("Could not find merger module named '%s' " + "with attribute '%s'") % (m_name, MERGER_ATTR) raise ImportError(msg) else: mod = importer.import_module(merger_locs[0]) - mod_attr = getattr(mod, 'Merger') + mod_attr = getattr(mod, MERGER_ATTR) mergers_to_be.append((mod_attr, m_ops)) # Now form them... mergers = [] diff --git a/cloudinit/mergers/dict.py b/cloudinit/mergers/m_dict.py index 929d3865..929d3865 100644 --- a/cloudinit/mergers/dict.py +++ b/cloudinit/mergers/m_dict.py diff --git a/cloudinit/mergers/list.py b/cloudinit/mergers/m_list.py index 7c8b2e2a..208c5f52 100644 --- a/cloudinit/mergers/list.py +++ b/cloudinit/mergers/m_list.py @@ -28,11 +28,10 @@ class Merger(object): # On encountering a list or tuple type this action will be applied # a new list will be returned, if the value to merge with is itself # a list and we have been told to 'extend', then the value here will - # be extended with the other list. If in 'extend' mode then we will - # attempt to merge instead, which means that values from the list - # to merge with will replace values in te original list (they will - # also be merged recursively). + # be extended with the other list. def _on_list(self, value, merge_with): if not self._extend or not isinstance(merge_with, (tuple, list)): return merge_with - return list(value).extend(merge_with) + # Leave the original list alone... + value = list(value) + return value.extend(merge_with) diff --git a/cloudinit/mergers/str.py b/cloudinit/mergers/m_str.py index 291c91c2..a0c57b53 100644 --- a/cloudinit/mergers/str.py +++ b/cloudinit/mergers/m_str.py @@ -31,7 +31,7 @@ class Merger(object): # merge them together, otherwise we will just return value. def _on_str(self, value, merge_with): if not self._append: - return value + return merge_with else: if isinstance(value, (unicode)): return value + unicode(merge_with) |