[Zope-Checkins] CVS: Zope/lib/python/App - Common.py:1.12 FindHomes.py:1.9

Chris McDonough chrism@zope.com
Wed, 20 Mar 2002 17:03:18 -0500


Update of /cvs-repository/Zope/lib/python/App
In directory cvs.zope.org:/tmp/cvs-serv27919/lib/python/App

Modified Files:
	Common.py FindHomes.py 
Log Message:
        App/FindHomes.py now computes the "real" path for SOFTWARE_HOME and
        INSTANCE_HOME, resolving any symlinks in any element within paths
        passed in via the INSTANCE_HOME or SOFTWARE_HOME envvars.  Paths that
        are computed by "dead reckoning" from os.getcwd and module paths are
        also "realpathed".  So for instance, if you use '/home/chrism/Instance'
        as your INSTANCE_HOME, and '/home/chrism' is a symlink to
        '/other/home/chrism', your INSTANCE_HOME will be computed as
        '/other/home/chrism/Instance'.  This is necessary to avoid
        weirdnesses while using "dead reckoning" from INSTANCE_HOME and
        SOFTWARE_HOME in other parts of the code.  POSIX systems only.



=== Zope/lib/python/App/Common.py 1.11 => 1.12 ===
 def Dictionary(**kw): return kw # Sorry Guido
     
+def realpath(p):
+    """ Computes the 'real' path of a file or directory devoid of
+    any symlink in any element of the path """
+    p = os.path.abspath(p)
+    if os.name == 'posix':
+        path_list = p.split(os.sep)
+        orig_len = len(path_list)
+        changed = 0
+        i = 1
+        while not changed and i < orig_len:
+            head = path_list[:i]
+            tail = path_list[i:]
+            head_s = os.sep.join(head)
+            tail_s = os.sep.join(tail)
+            if os.path.islink(head_s):
+                head_s = os.readlink(head_s)
+                path_list = head_s.split(os.sep)
+                path_list.extend(tail)
+                p = os.sep.join(path_list)
+                p = realpath(p)
+                changed = 1
+            i = i + 1
+    return p


=== Zope/lib/python/App/FindHomes.py 1.8 => 1.9 ===
 
 import os, sys, Products
-from Common import package_home
+from Common import package_home, realpath
 path_join = os.path.join
 path_split = os.path.split
 
@@ -31,10 +31,12 @@
     if path_split(home)[1]=='..':
         home=path_split(path_split(home)[0])[0]
 
+home=realpath(home)
 sys.modules['__builtin__'].SOFTWARE_HOME=SOFTWARE_HOME=home
 
 try:
     chome=os.environ['INSTANCE_HOME']
+    chome = realpath(chome)
 except:
     chome=home
     d,e=path_split(chome)