import os
import sys
+import samba.param
+
+def source_tree_topdir():
+ '''return the top level directory (the one containing the source4 directory)'''
+ paths = [ "../../..", "../../../.." ]
+ for p in paths:
+ topdir = os.path.normpath(os.path.join(os.path.dirname(__file__), p))
+ if os.path.exists(os.path.join(topdir, 'source4')):
+ return topdir
+ raise RuntimeError("unable to find top level source directory")
+
+def in_source_tree():
+ '''return True if we are running from within the samba source tree'''
+ try:
+ topdir = source_tree_topdir()
+ except RuntimeError:
+ return False
+ return True
-def _in_source_tree():
- """Check whether the script is being run from the source dir. """
- return os.path.exists("%s/../../../selftest/skip" % os.path.dirname(__file__))
-
-
-# When running, in-tree, make sure bin/python is in the PYTHONPATH
-if _in_source_tree():
- srcdir = "%s/../../.." % os.path.dirname(__file__)
- sys.path.append("%s/bin/python" % srcdir)
- default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir
-else:
- default_ldb_modules_dir = None
import ldb
if modules_dir is not None:
self.set_modules_dir(modules_dir)
- elif default_ldb_modules_dir is not None:
- self.set_modules_dir(default_ldb_modules_dir)
- elif lp is not None:
- self.set_modules_dir(os.path.join(lp.get("modules dir"), "ldb"))
+ else:
+ self.set_modules_dir(os.path.join(samba.param.modules_dir(), "ldb"))
if session_info is not None:
self.set_session_info(session_info)
def erase_users_computers(self, dn):
"""Erases user and computer objects from our AD.
-
+
This is needed since the 'samldb' module denies the deletion of primary
groups. Therefore all groups shouldn't be primary somewhere anymore.
"""
def erase_except_schema_controlled(self):
"""Erase this ldb.
-
+
:note: Removes all records, except those that are controlled by
Samba4's schema.
"""
def check_all_substituted(text):
- """Make sure that all substitution variables in a string have been replaced.
+ """Check that all substitution variables in a string have been replaced.
+
If not, raise an exception.
:param text: The text to search for substitution variables
var_start = text.find("${")
var_end = text.find("}", var_start)
- raise Exception("Not all variables substituted: %s" % text[var_start:var_end+1])
+ raise Exception("Not all variables substituted: %s" %
+ text[var_start:var_end+1])
def read_and_sub_file(file_name, subst_vars):
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(source_tree_topdir(), "lib", location))
+ sys.modules[modulename] = __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.
:param modulename: Module name to import
- :param location: Location to add to sys.path (can be relative to
- ${srcdir}/lib
+ :param location: Location to add to sys.path (can be relative to
+ ${srcdir}/lib)
"""
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, location)
+
from samba import _glue
version = _glue.version
interface_ips = _glue.interface_ips
set_debug_level = _glue.set_debug_level
+get_debug_level = _glue.get_debug_level
+unix2nttime = _glue.unix2nttime
+nttime2string = _glue.nttime2string
+nttime2unix = _glue.nttime2unix
unix2nttime = _glue.unix2nttime
generate_random_password = _glue.generate_random_password
-talloc_report_full = _glue.talloc_report_full
-talloc_enable_null_tracking = _glue.talloc_enable_null_tracking
-talloc_total_blocks = _glue.talloc_total_blocks
+strcasecmp_m = _glue.strcasecmp_m
+strstr_m = _glue.strstr_m