Use convenience function for finding setup_dir based on location of
authorJelmer Vernooij <jelmer@samba.org>
Wed, 11 Feb 2009 17:44:57 +0000 (18:44 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 11 Feb 2009 17:44:57 +0000 (18:44 +0100)
python module.

source4/scripting/python/samba/provision.py
source4/setup/provision
source4/setup/provision-backend
source4/setup/upgrade

index 1d7011d305c0a297e312c5adcabc92c8cacd5fab..d77b487512af76786e10609959cff79b2a621752 100644 (file)
@@ -45,6 +45,23 @@ from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
 
 __docformat__ = "restructuredText"
 
+
+def find_setup_dir():
+    """Find the setup directory used by provision."""
+    dirname = os.path.dirname(__file__)
+    if "/site-packages/" in dirname:
+        prefix = dirname[:dirname.index("/site-packages/")]
+        for suffix in ["share/setup", "share/samba/setup", "setup"]:
+            ret = os.path.join(prefix, suffix)
+            if os.path.isdir(ret):
+                return ret
+    # In source tree
+    ret = os.path.join(dirname, "../../../setup")
+    if os.path.isdir(ret):
+        return ret
+    raise Exception("Unable to find setup directory.")
+
+
 DEFAULTSITE = "Default-First-Site-Name"
 
 class InvalidNetbiosName(Exception):
index eab5d09424d066add9d10c9cb6fe8c9c35be1b2c..5cb851ceb79879214ab85a10f16466b4a31ada5d 100755 (executable)
@@ -35,7 +35,7 @@ from samba.credentials import DONT_USE_KERBEROS
 from samba.auth import system_session
 import samba.getopt as options
 from samba import param
-from samba.provision import provision, FILL_FULL, FILL_NT4SYNC, FILL_DRS
+from samba.provision import provision, FILL_FULL, FILL_NT4SYNC, FILL_DRS, find_setup_dir
 
 # how do we make this case insensitive??
 
@@ -168,7 +168,7 @@ creds.set_kerberos_state(DONT_USE_KERBEROS)
 
 setup_dir = opts.setupdir
 if setup_dir is None:
-       setup_dir = os.path.dirname(__file__)
+       setup_dir = find_setup_dir()
 
 samdb_fill = FILL_FULL
 if opts.blank:
index e4e2d56020375736336541ae5a6e3f97ed726a57..eca209cb187ebe4c56081d1eeecd7303ad7be5a1 100755 (executable)
@@ -34,7 +34,7 @@ from samba import param
 
 from samba.auth import system_session
 import samba.getopt as options
-from samba.provision import provision_backend
+from samba.provision import provision_backend, find_setup_dir
 
 parser = optparse.OptionParser("provision [options]")
 sambaopts = options.SambaOptions(parser)
@@ -94,7 +94,7 @@ else:
 
 setup_dir = opts.setupdir
 if setup_dir is None:
-       setup_dir = os.path.dirname(__file__)
+       setup_dir = find_setup_dir()
 
 provision_backend(setup_dir=setup_dir, message=message, smbconf=smbconf, targetdir=opts.targetdir,
                  realm=opts.realm, domain=opts.domain,
index 9c1a0cfce819b56b7e0d6cdb7c27b95f09559106..3d1316949f729e11567d33f9eb0b8fcd46b786f1 100755 (executable)
@@ -65,13 +65,14 @@ else:
     smbconf = os.path.join(libdir, "smb.conf")
 samba3 = Samba3(libdir, smbconf)
 
+from samba.provision import find_setup_dir
 from samba.upgrade import upgrade_provision
 
 message("Provisioning\n")
 
 setup_dir = opts.setupdir
 if setup_dir is None:
-       setup_dir = os.path.dirname(__file__)
+       setup_dir = find_setup_dir()
 
 lp = sambaopts.get_loadparm()
 smbconf = lp.configfile