summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-12-09 19:45:37 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-12-10 03:04:06 +0100
commit4571b94e7b04acaa7f462262dac509843287e4af (patch)
treef8d29c7295ba2570c37f75fa792101dbed3e5236 /source4
parentc565da0f7148fcfb560bea9abe4b9e2bb59a81e1 (diff)
downloadsamba-4571b94e7b04acaa7f462262dac509843287e4af.tar.gz
samba-4571b94e7b04acaa7f462262dac509843287e4af.tar.bz2
samba-4571b94e7b04acaa7f462262dac509843287e4af.zip
s4-python: Split up ensure_external_module.
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/scripting/bin/subunitrun3
-rw-r--r--source4/scripting/python/samba/__init__.py30
2 files changed, 23 insertions, 10 deletions
diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun
index 72f6429188..87519d5661 100755
--- a/source4/scripting/bin/subunitrun
+++ b/source4/scripting/bin/subunitrun
@@ -22,15 +22,14 @@ import sys
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
-from subunit.run import TestProgram
import optparse
import samba
samba.ensure_external_module("testtools", "testtools")
samba.ensure_external_module("subunit", "subunit/python")
+from subunit.run import SubunitTestRunner, TestProgram
import samba.getopt as options
import samba.tests
-from subunit.run import SubunitTestRunner
parser = optparse.OptionParser("subunitrun [options] <tests>")
credopts = options.CredentialsOptions(parser)
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index bd7628993e..f88ac74dca 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -304,6 +304,26 @@ def valid_netbios_name(name):
return True
+def import_bundled_package(modulename, location):
+ """Import the bundled version of a package.
+
+ :note: This should only be called if the system version of the package
+ is not adequate.
+
+ :param modulename: Module name to import
+ :param location: Location to add to sys.path (can be relative to
+ ${srcdir}/lib)
+ """
+ if in_source_tree():
+ sys.path.insert(0,
+ os.path.join(os.path.dirname(__file__),
+ "../../../../lib", location))
+ __import__(modulename)
+ else:
+ sys.modules[modulename] = __import__(
+ "samba.external.%s" % modulename, fromlist=["samba.external"])
+
+
def ensure_external_module(modulename, location):
"""Add a location to sys.path if an external dependency can't be found.
@@ -314,14 +334,8 @@ def ensure_external_module(modulename, location):
try:
__import__(modulename)
except ImportError:
- if in_source_tree():
- sys.path.insert(0,
- os.path.join(os.path.dirname(__file__),
- "../../../../lib", location))
- __import__(modulename)
- else:
- sys.modules[modulename] = __import__(
- "samba.external.%s" % modulename, fromlist=["samba.external"])
+ import_bundled_package(modulename)
+
from samba import _glue
version = _glue.version