diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-17 08:46:58 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-04-17 08:46:58 -0700 |
commit | 87963dd237ff2080be62cc6a8afb4138471e4f20 (patch) | |
tree | 615d52483b48ec20d0b8eca7342e62b1602cfaaa /cloudinit/mergers/__init__.py | |
parent | 7dac7bbd48bb56971c2fddfcf13d439d577740c1 (diff) | |
download | vyos-cloud-init-87963dd237ff2080be62cc6a8afb4138471e4f20.tar.gz vyos-cloud-init-87963dd237ff2080be62cc6a8afb4138471e4f20.zip |
Handle namespacing issues.
Move from using the inbuilt type names as module names
which is a bad thing to use it appears due to naming conflicts
in the __init__ module and reduce the chances of these conflicts
by enforcing a m_ prefix for merging modules.
Diffstat (limited to 'cloudinit/mergers/__init__.py')
-rw-r--r-- | cloudinit/mergers/__init__.py | 11 |
1 files changed, 8 insertions, 3 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 = [] |