diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-02-20 10:38:38 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-02-20 10:38:38 -0500 |
commit | 69ebf49d54aac70a42142d0d04e562496bce58ea (patch) | |
tree | ad0f346ff95a14ad49440128ff76d7e2b3f0816a /src/lib/Bcfg2/Server/Plugins/TemplateHelper.py | |
parent | 602ba6af6bd1c9b3910940dee766660ab8e81a19 (diff) | |
parent | e17e41dcff096ead7e129a0db063f75de44aaa2b (diff) | |
download | bcfg2-69ebf49d54aac70a42142d0d04e562496bce58ea.tar.gz bcfg2-69ebf49d54aac70a42142d0d04e562496bce58ea.tar.bz2 bcfg2-69ebf49d54aac70a42142d0d04e562496bce58ea.zip |
Merge branch 'master' into 1.4.x
Conflicts:
doc/appendix/contributors.txt
schemas/bundle.xsd
src/lib/Bcfg2/Client/Tools/__init__.py
src/lib/Bcfg2/Server/Encryption.py
src/lib/Bcfg2/Server/Lint/Genshi.py
src/lib/Bcfg2/Server/Plugins/Bundler.py
src/lib/Bcfg2/Server/Plugins/Decisions.py
src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
src/sbin/bcfg2-test
testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
tools/bcfg2-profile-templates.py
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/TemplateHelper.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/TemplateHelper.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py index e3f8ed749..ad3eb65bc 100644 --- a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py +++ b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py @@ -12,12 +12,25 @@ LOGGER = logging.getLogger(__name__) MODULE_RE = re.compile(r'(?P<filename>(?P<module>[^\/]+)\.py)$') +def safe_module_name(module): + """ Munge the name of a TemplateHelper module to avoid collisions + with other Python modules. E.g., if someone has a helper named + 'ldap.py', it should not be added to ``sys.modules`` as ``ldap``, + but rather as something more obscure. """ + return '__TemplateHelper_%s' % module + + class HelperModule(object): """ Representation of a TemplateHelper module """ def __init__(self, name): self.name = name + + #: The name of the module as used by get_additional_data(). + #: the name of the file with .py stripped off. self._module_name = MODULE_RE.search(self.name).group('module') + + #: The attributes exported by this module self._attrs = [] def HandleEvent(self, event=None): @@ -31,7 +44,8 @@ class HelperModule(object): return try: - module = imp.load_source(self._module_name, self.name) + module = imp.load_source(safe_module_name(self._module_name), + self.name) except: # pylint: disable=W0702 err = sys.exc_info()[1] LOGGER.error("TemplateHelper: Failed to import %s: %s" % @@ -97,7 +111,7 @@ class TemplateHelperLint(Bcfg2.Server.Lint.ServerPlugin): module_name = MODULE_RE.search(helper).group(1) try: - module = imp.load_source(module_name, helper) + module = imp.load_source(safe_module_name(module_name), helper) except: # pylint: disable=W0702 err = sys.exc_info()[1] self.LintError("templatehelper-import-error", |