[CalendarServer-changes] [5167] CalendarServer/trunk/support/py.sh

source_changes at macosforge.org source_changes at macosforge.org
Sun Feb 21 13:27:11 PST 2010


Revision: 5167
          http://trac.macosforge.org/projects/calendarserver/changeset/5167
Author:   wsanchez at apple.com
Date:     2010-02-21 13:27:09 -0800 (Sun, 21 Feb 2010)
Log Message:
-----------
Add -v flag to py_have_module.

Modified Paths:
--------------
    CalendarServer/trunk/support/py.sh

Modified: CalendarServer/trunk/support/py.sh
===================================================================
--- CalendarServer/trunk/support/py.sh	2010-02-21 19:22:47 UTC (rev 5166)
+++ CalendarServer/trunk/support/py.sh	2010-02-21 21:27:09 UTC (rev 5167)
@@ -75,9 +75,57 @@
 
 # Detect if the given Python module is installed in the system Python configuration.
 py_have_module () {
+  local version=""; # Minimum version required
+
+  OPTIND=1;
+  while getopts "v:" option; do
+    case "${option}" in
+      'v') version="${OPTARG}"; ;;
+    esac;
+  done;
+  shift $((${OPTIND} - 1));
+
   local module="$1"; shift;
 
   PYTHONPATH="" "${python}" -c "import ${module}" > /dev/null 2>&1;
+  result=$?;
+
+  if [ $result == 0 ] && [ -n "${version}" ]; then
+    module_version="$(PYTHONPATH="" "${python}" -c 'print __import__("'"${module}"'").__version__')";
+
+     v="${version}";
+    mv="${module_version}";
+
+    no_such_luck="A system version of ${module} exists, but version is ${module_version} (< ${version}).";
+
+    while true; do
+       vh="${v%%.*}"; # Get highest-order segment
+      mvh="${mv%%.*}";
+
+      if [ "$vh" -gt "$mvh" ]; then
+        echo "${no_such_luck}";
+        result=1;
+        break;
+      fi;
+
+      if [ "${v}" == "${v#*.}" ]; then
+        # No dots left, so we're ok
+        break;
+      fi;
+
+      if [ "${mv}" == "${mv#*.}" ]; then
+        # No dots left, so we're not gonna match
+        echo "${no_such_luck}";
+        result=1;
+        break;
+      fi;
+
+       v="${v#*.}";
+      mv="${mv#*.}";
+    done;
+  fi;
+
+  return $result;
 }
 
 # Detect which python to use, and store it in the 'python' variable, as well as
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100221/fbfe46a7/attachment-0001.html>


More information about the calendarserver-changes mailing list