summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-12-10 00:47:33 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-12-10 03:04:06 +0100
commit636d8cfb423bbdf271df25efbc13c91420ebefe8 (patch)
treed125b9325125bbb94a5b4d2a31089f7265cb6705 /source4/scripting/python
parentbdf5a49cec064c965c1271d875fc9b474b77f634 (diff)
downloadsamba-636d8cfb423bbdf271df25efbc13c91420ebefe8.tar.gz
samba-636d8cfb423bbdf271df25efbc13c91420ebefe8.tar.bz2
samba-636d8cfb423bbdf271df25efbc13c91420ebefe8.zip
s4-python: Add convenience function for forcibly importing bundled
package.
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/__init__.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index b6c53f4b2c..6fcac16691 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -324,6 +324,21 @@ def import_bundled_package(modulename, location):
"samba.external.%s" % modulename, fromlist=["samba.external"])
+def force_bundled_package(packagename, location):
+ """Forcibly use the bundled package.
+
+ This will first unload the system module and then load the bundled one.
+
+ :param packagename: The package name
+ :param location: Location to add to sys.path (can be relative to
+ ${srcdir}/lib)
+ """
+ for m in sys.modules.keys():
+ if m.startswith("%s." % packagename):
+ del sys.modules[m]
+ import_bundled_package(packagename, location)
+
+
def ensure_external_module(modulename, location):
"""Add a location to sys.path if an external dependency can't be found.