[Repoze-checkins] r1258 - repoze.virginia/trunk/repoze/virginia

Chris McDonough chrism at agendaless.com
Tue Jul 8 22:37:28 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Tue Jul  8 22:37:27 2008
New Revision: 1258

Log:
Allow for primitive aliases via symlinks.


Modified:
   repoze.virginia/trunk/repoze/virginia/filesys.py
   repoze.virginia/trunk/repoze/virginia/models.py

Modified: repoze.virginia/trunk/repoze/virginia/filesys.py
==============================================================================
--- repoze.virginia/trunk/repoze/virginia/filesys.py	(original)
+++ repoze.virginia/trunk/repoze/virginia/filesys.py	Tue Jul  8 22:37:27 2008
@@ -99,6 +99,10 @@
         p = self.normalize (self.path_module.join (self.wd, path))
         return self.path_module.isdir (self.translate(p))
 
+    def islink (self, path):
+        p = self.normalize (self.path_module.join (self.wd, path))
+        return self.path_module.islink (self.translate(p))
+
     def cwd (self, path):
         p = self.normalize (self.path_module.join (self.wd, path))
         translated_path = self.translate(p)

Modified: repoze.virginia/trunk/repoze/virginia/models.py
==============================================================================
--- repoze.virginia/trunk/repoze/virginia/models.py	(original)
+++ repoze.virginia/trunk/repoze/virginia/models.py	Tue Jul  8 22:37:27 2008
@@ -14,7 +14,18 @@
     def __getitem__(self, name):
         self.filesystem.cwd(self.path)
         nextpath = os.path.join(self.path, name)
-        if self.filesystem.isdir(name):
+        if self.filesystem.islink(name):
+            realpath = os.path.realpath(os.path.join(self.path, name))
+            if realpath.startswith(self.path):
+                realdir = os.path.dirname(realpath)
+                if len(self.path.split(os.sep)) == len(realdir.split(os.sep)):
+                    # if this symlink is in the same directory as the
+                    # original, treat it as a primitive alias; use the
+                    # link target as the filename so we get the right
+                    # renderer (eg. stx vs html).
+                    ignored, truename = os.path.split(realpath)
+                    return File(self.filesystem, truename)
+        elif self.filesystem.isdir(name):
             return Directory(self.filesystem, nextpath)
         elif self.filesystem.isfile(name):
             return File(self.filesystem, nextpath)


More information about the Repoze-checkins mailing list