[CMF-checkins] CVS: CMF/CMFCore - DirectoryView.py:1.33 utils.py:1.34
Chris Withers
chrisw@nipltd.com
Tue, 21 Jan 2003 12:00:12 -0500
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv30149/CMFCore
Modified Files:
DirectoryView.py utils.py
Log Message:
Yet more work on FSDVs. This one makes it possible to have CMF in a PRODUCTS_PATH.
Also improves the chances of nto having to manually edit all the FSDV paths.
Currently tests pass on a PRODUCTS_PATH setup.
=== CMF/CMFCore/DirectoryView.py 1.32 => 1.33 ===
--- CMF/CMFCore/DirectoryView.py:1.32 Fri Nov 8 19:25:23 2002
+++ CMF/CMFCore/DirectoryView.py Tue Jan 21 11:59:40 2003
@@ -316,12 +316,20 @@
return self._meta_types.get(mt, None)
def registerDirectory(self, name, _prefix, subdirs=1):
+ # This what is actually called to register a
+ # file system directory to become a FSDV.
if not isinstance(_prefix, StringType):
_prefix = package_home(_prefix)
filepath = path.join(_prefix, name)
self.registerDirectoryByPath(filepath, subdirs)
def registerDirectoryByPath(self, filepath, subdirs=1):
+ # This is indirectly called during registration of
+ # a directory. As you can see, minimalpath is called
+ # on the supplied path at this point.
+ # The idea is that the registry will only contain
+ # small paths that are likely to work across platforms
+ # and SOFTWARE_HOME, INSTANCE_HOME and PRODUCTS_PATH setups
fp = minimalpath(filepath)
normfilepath = path.normpath(filepath)
self._directories[fp] = di = DirectoryInformation(normfilepath, fp)
@@ -336,6 +344,10 @@
info.reload()
def getDirectoryInfo(self, filepath):
+ # This is called when we need to get hold of the information
+ # for a minimal path.
+ # minimalpath is called on the supplied path on the hope
+ # that if it is incorrect, something ca
# Can return None.
return self._directories.get(minimalpath(filepath), None)
=== CMF/CMFCore/utils.py 1.33 => 1.34 ===
--- CMF/CMFCore/utils.py:1.33 Thu Nov 14 11:49:10 2002
+++ CMF/CMFCore/utils.py Tue Jan 21 11:59:40 2003
@@ -595,36 +595,48 @@
#
security.declarePublic('normalize')
def normalize(p):
- return os_path.normcase(os_path.normpath(p.replace('\\','/')))
-
-normINSTANCE_HOME = normalize(INSTANCE_HOME)
-normSOFTWARE_HOME = normalize(SOFTWARE_HOME)
+ return os_path.normcase(os_path.normpath(p))
separators = (os.sep, os.altsep)
+import Products
+ProductsPath = []
+ProductsPath = map(normalize,Products.__path__)
+
security.declarePublic('expandpath')
def expandpath(p):
# Converts a minimal path to an absolute path.
+
+ # This has a slight weakness in that if someone creates a new
+ # product with the same name as an old one, then the skins may
+ # become confused between the two.
+ # However, that's an acceptable risk as people don't seem
+ # to re-use product names ever (it would create ZODB persistence
+ # problems too ;-)
+
p = os_path.normpath(p)
if os_path.isabs(p):
return p
- abs = os_path.join(normINSTANCE_HOME, p)
- if os_path.exists(abs):
- return abs
- return os_path.join(normSOFTWARE_HOME, p)
+
+ for ppath in ProductsPath:
+ abs = os_path.join(ppath, p)
+ if os_path.exists(abs):
+ return abs
+
+ # return the last one, errors will happen else where as as result
+ # and be caught
+ return abs
security.declarePublic('minimalpath')
def minimalpath(p):
- # This trims down to a 'Products' root if it can.
+ # This trims down to just beyond a 'Products' root if it can.
# otherwise, it returns what it was given.
# In either case, the path is normalized.
p = normalize(p)
index = p.find('Products')
if index == -1:
index = p.find('products')
- if index == -1:
- return p
- p = p[index:]
- while p[:1] in separators:
- p = p[1:]
- return p
+ if index == -1:
+ # couldn't normalise
+ return p
+ return p[index+len('products/'):]