summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Utils.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-07-24 06:37:33 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-07-24 06:37:33 +0200
commit68b5db49a54f59731ee52a966e0241c2ed0e5ba7 (patch)
treeb9b50d7b0454dc9919bbf319c40510b9b8215ba4 /src/lib/Bcfg2/Utils.py
parentc11fcd8110e537db70bf40b91ed14467184b0e1c (diff)
downloadbcfg2-68b5db49a54f59731ee52a966e0241c2ed0e5ba7.tar.gz
bcfg2-68b5db49a54f59731ee52a966e0241c2ed0e5ba7.tar.bz2
bcfg2-68b5db49a54f59731ee52a966e0241c2ed0e5ba7.zip
Utils: Generalize safe_module_name
Other plugins that also import user generated python source code, may want to use safe_module_name from TemplateHelper.
Diffstat (limited to 'src/lib/Bcfg2/Utils.py')
-rw-r--r--src/lib/Bcfg2/Utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Utils.py b/src/lib/Bcfg2/Utils.py
index 64d0d8b93..2fdc0c3e0 100644
--- a/src/lib/Bcfg2/Utils.py
+++ b/src/lib/Bcfg2/Utils.py
@@ -321,6 +321,15 @@ def safe_input(msg):
return input(msg)
+def safe_module_name(prefix, module):
+ """ Munge the name of a module with prefix to avoid collisions
+ with other Python modules. E.g., if you want to import user
+ defined helper modules and someone has a helper named 'ldap.py',
+ it should not be added to ``sys.modules`` as ``ldap``, but rather
+ as something more obscure. """
+ return '__%s_%s' % (prefix, module)
+
+
class classproperty(object): # pylint: disable=C0103
""" Decorator that can be used to create read-only class
properties. """