[sabayon] Turned ldap into a soft dependency, issue a message in configure



commit 34a30c6cbf53ae7afa254074f5ad2695756c2d8d
Author: Scott Balneaves <sbalneav ltsp org>
Date:   Sat Dec 19 23:00:40 2009 -0600

    Turned ldap into a soft dependency, issue a message in configure

 configure.ac    |   16 +++++++++++++++-
 lib/systemdb.py |   28 ++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b9a935f..d12a974 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,13 +33,27 @@ AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR([Can't locate python headers])])
 # distros may not be aware that Sabayon *requires* xdg.DesktopEntry to run,
 # so we'll check for it at "compilation" time.
 AC_MSG_CHECKING(whether the xdg.DesktopEntry module for Python is available)
-if [ ! python -c "import xdg.DesktopEntry" ]
+if [ ! python -c "import xdg.DesktopEntry" 2> /dev/null ]
 then
 	AC_MSG_FAILURE([Please install the python-xdg or pyxdg package.])
 else
 	AC_MSG_RESULT(yes)
 fi
 
+#
+# Do a soft check for Python bindings for LDAP.  They're not strictly
+# necessary, but if you don't have them, you won't be able to do LDAP
+# queries.
+#
+
+AC_MSG_CHECKING(whether the ldap module for Python is available)
+if [ ! python -c "import ldap" 2> /dev/null ]
+then
+    AC_MSG_RESULT(no)
+else
+    AC_MSG_RESULT(yes)
+fi
+
 # Check for GDK/X11, PyGObject, and pygtk
 PKG_CHECK_MODULES(XLIB_MODULE, gdk-x11-2.0 pygobject-2.0 pygtk-2.0)
 
diff --git a/lib/systemdb.py b/lib/systemdb.py
index 75f8caa..28b85de 100644
--- a/lib/systemdb.py
+++ b/lib/systemdb.py
@@ -26,11 +26,20 @@ import config
 import util
 import cache
 import random
-import ldap
 import socket
 import debuglog
 
 #
+# LDAP should be a soft dependency.
+#
+
+try:
+    import ldap
+    has_ldap = True;
+except ImportError:
+    has_ldap = False;
+
+#
 # Default empty config.
 #
 defaultConf="""<profiles>
@@ -107,6 +116,7 @@ class SystemDatabase(object):
             file = db_file
         self.file = file
         self.xmlquery = None
+        self.nodes = None        # nodes from the XML file for LDAP usage.
         self.modified = 0
         dprint("New UserDatabase(%s) object\n" % self.file)
 
@@ -180,10 +190,7 @@ class SystemDatabase(object):
         return profile
 
     def __open_ldap (self):
-        nodes = self.doc.xpathEval ("/profiles/ldap")
-        if len (nodes) == 0:
-            return None
-        ldap_node = nodes[0]
+        ldap_node = self.nodes[0]
 
         server = get_setting (ldap_node, "server", "localhost")
         port = get_setting (ldap_node, "port", ldap.PORT, int)
@@ -201,10 +208,15 @@ class SystemDatabase(object):
         return l
 
     def __ldap_query (self, map, replace):
-        nodes = self.doc.xpathEval ("/profiles/ldap/" + map)
-        if len (nodes) == 0:
+        global has_ldap
+        if not has_ldap:
             return None
-        map_node = nodes[0]
+        if not self.nodes:
+            self.nodes = self.doc.xpathEval ("/profiles/ldap/" + map)
+            if len (self.nodes) == 0:
+                has_ldap = False        # No LDAP nodes in the xml file.
+                return None
+        map_node = self.nodes[0]
         
         l = self.__open_ldap ()
         if not l:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]