[ZPT] CVS: Zope3/lib/python/Zope/TAL - setpath.py:1.3.24.2.6.2

Barry Warsaw barry@wooz.org
Tue, 4 Jun 2002 19:05:22 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv30946

Modified Files:
      Tag: fdrake-tal-i18n-branch
	setpath.py 
Log Message:
Use string methods.

Don't crap out immediately if we can't find a .path file, since our
sys.path might already be set up correctly (via $PYTHONPATH).  Only
complain if we still can't import ZODB.


=== Zope3/lib/python/Zope/TAL/setpath.py 1.3.24.2.6.1 => 1.3.24.2.6.2 ===
 
 """
-Read a module search path from .path.
+Read a module search path from .path file.
+
+If .path file isn't found in the directory of the setpath.py module, then try
+to import ZODB.  If that succeeds, we assume the path is already set up
+correctly.  If that import fails, an IOError is raised.
 """
 import os
 import sys
-import string
 
 dir = os.path.dirname(__file__)
 path = os.path.join(dir, ".path")
 try:
     f = open(path)
 except IOError:
-    raise IOError, "Please edit .path to point to <Zope2/lib/python>"
+    try:
+        # If we can import ZODB, our sys.path is set up well enough already
+        import ZODB
+    except ImportError:
+        raise IOError("Can't find ZODB package.  Please edit %s to point to "
+                      "your Zope's lib/python directory" % path)
 else:
     for line in f.readlines():
         line = line.strip()
         if line and line[0] != '#':
-            for dir in string.split(line, os.pathsep):
+            for dir in line.split(os.pathsep):
                 dir = os.path.expanduser(os.path.expandvars(dir))
                 if dir not in sys.path:
                     sys.path.append(dir)
-
-import ZODB # Must import this first to initialize Persistence properly
+        # Must import this first to initialize Persistence properly
+        import ZODB