[CMF-checkins] CVS: CMF - DirectoryView.py:1.3 __init__.py:1.4
shane@digicool.com
shane@digicool.com
Sat, 7 Apr 2001 18:59:55 -0400 (EDT)
Update of /cvs-repository/CMF/CMFCore
In directory korak:/tmp/cvs-serv7205
Modified Files:
DirectoryView.py __init__.py
Log Message:
Changed implementation of DirectoryView to use "surrogates". This should
speed up skins by a large factor.
--- Updated File DirectoryView.py in package CMF --
--- DirectoryView.py 2001/02/28 22:30:52 1.2
+++ DirectoryView.py 2001/04/07 22:59:53 1.3
@@ -183,23 +183,23 @@
return types
def getContents(self, registry):
- data = self.data
- if data is not None:
- return data
- try:
- self.data = data = self.prepareContents(registry)
- except:
- # DEBUG
- import traceback
- traceback.print_exc()
+ if self.data is None:
+ try:
+ self.data, self.objects = self.prepareContents(registry)
+ except:
+ # DEBUG
+ import traceback
+ traceback.print_exc()
+
+ self.data = {}
+ self.objects = ()
+ return self.data, self.objects
- self.data = data = {}
- return data
-
def prepareContents(self, registry):
# Creates objects for each file.
fp = expandpath(self.filepath)
data = {}
+ objects = []
l = listdir(fp)
types = self._readTypesFile()
for entry in l:
@@ -219,7 +219,9 @@
if t is None:
t = DirectoryView
ob = t(entry, e_filepath)
- data[ob.getId()] = ob
+ ob_id = ob.getId()
+ data[ob_id] = ob
+ objects.append({'id': ob_id, 'meta_type': ob.meta_type})
else:
pos = rfind(entry, '.')
if pos >= 0:
@@ -241,8 +243,10 @@
t = registry.getTypeByExtension(ext)
if t is not None:
ob = t(name, e_filepath, fullname=entry)
- data[ob.getId()] = ob
- return data
+ ob_id = ob.getId()
+ data[ob_id] = ob
+ objects.append({'id': ob_id, 'meta_type': ob.meta_type})
+ return data, tuple(objects)
class DirectoryRegistry:
@@ -330,52 +334,64 @@
rval.append((subpath, name))
listFolderHierarchy(subob, subpath, rval, adding_meta_type)
-
-try: superFolderGetattr = Folder.__getattr__
-except:
- try: superFolderGetattr = Folder.inheritedAttribute('__getattr__')
- except:
- def superFolderGetattr(self, name):
- raise AttributeError, name
-
-class DirectoryView (Folder):
+class DirectoryView (Persistent):
'''
'''
-
- security = ClassSecurityInfo()
-
meta_type = 'Filesystem Directory View'
- all_meta_types = ()
- _isDirectoryView = 1
-
_dirpath = None
+ _objects = ()
def __init__(self, id, dirpath, fullname=None):
self.id = id
self._dirpath = dirpath
- def _getFSObjects(self):
+ def __of__(self, parent):
info = _dirreg.getDirectoryInfo(self._dirpath)
if info is not None:
- return info.getContents(_dirreg)
+ info = info.getContents(_dirreg)
+ if info is None:
+ data = {}
+ objects = ()
else:
- return None
+ data, objects = info
+ s = DirectoryViewSurrogate(self, data, objects)
+ res = s.__of__(parent)
+ return res
+
+Globals.InitializeClass(DirectoryView)
- def __getattr__(self, name, superget=superFolderGetattr):
- obs = self._getFSObjects()
- if obs is not None and obs.has_key(name):
- return obs[name]
- return superget(self, name)
- security.declareProtected(AccessContentsInformation,'getCustomizableObject')
+class DirectoryViewSurrogate (Folder):
+
+ meta_type = 'Filesystem Directory View'
+ all_meta_types = ()
+ _isDirectoryView = 1
+
+ security = ClassSecurityInfo()
+
+ def __init__(self, real, data, objects):
+ d = self.__dict__
+ d.update(data)
+ d.update(real.__dict__)
+ d['_real'] = real
+ d['_objects'] = objects
+
+ def __setattr__(self, name, value):
+ d = self.__dict__
+ d[name] = value
+ setattr(d['_real'], name, value)
+
+ security.declareProtected(AccessContentsInformation,
+ 'getCustomizableObject')
def getCustomizableObject(self):
ob = aq_parent(aq_inner(self))
while getattr(ob, '_isDirectoryView', 0):
ob = aq_parent(aq_inner(ob))
return ob
- security.declareProtected(AccessContentsInformation, 'listCustFolderPaths')
+ security.declareProtected(AccessContentsInformation,
+ 'listCustFolderPaths')
def listCustFolderPaths(self, adding_meta_type=None):
'''
Returns a list of possible customization folders
@@ -387,76 +403,11 @@
rval.sort()
return rval
- security.declarePublic('getid')
+ security.declarePublic('getId')
def getId(self):
return self.id
-
- # Override some methods to make the non-persistent
- # objects visible.
-
- def objectIds(self, spec=None):
- # Returns a list of subobject ids of the current object.
- # If 'spec' is specified, returns objects whose meta_type
- # matches 'spec'.
- fsobs = self._getFSObjects()
- if spec is not None:
- if type(spec)==type('s'):
- spec=[spec]
- set=[]
- for ob in self._objects:
- if ob['meta_type'] in spec:
- set.append(ob['id'])
- if fsobs is not None:
- for key, value in fsobs.items():
- if not key in set and value.meta_type in spec:
- set.append(key)
- return set
-
- set = list(map(lambda i: i['id'], self._objects))
- if fsobs is not None:
- for key in fsobs.keys():
- if not key in set:
- set.append(key)
- return set
-
- def objectMap(self):
- # Return a tuple of mappings containing subobject meta-data.
- objs = []
- fsobs = self._getFSObjects()
- if fsobs is not None:
- for key, value in fsobs.items():
- objs.append({'id':key, 'meta_type':value.meta_type})
- for info in self._objects:
- objs.append(info.copy())
- return tuple(objs)
-
- def objectMap_d(self,t=None):
- if hasattr(self, '_reserved_names'): n=self._reserved_names
- else: n=()
- if not n: return self.objectMap()
- r=[]
- a=r.append
- for d in self.objectMap():
- if d['id'] not in n: a(d)
- return r
-
- def tpValues(self):
- # Return a list of subobjects, used by tree tag.
- r=[]
- if hasattr(aq_base(self), 'tree_ids'):
- for id in self.tree_ids:
- if hasattr(self, id):
- r.append(self._getOb(id))
- else:
- for id in self.objectIds():
- o = self._getOb(id)
- try:
- if o.isPrincipiaFolderish: r.append(o)
- except: pass
-
- return r
-
-Globals.InitializeClass(DirectoryView)
+
+Globals.InitializeClass(DirectoryViewSurrogate)
manage_addDirectoryViewForm = HTMLFile('dtml/addFSDirView', globals())
--- Updated File __init__.py in package CMF --
--- __init__.py 2001/03/21 18:21:34 1.3
+++ __init__.py 2001/04/07 22:59:53 1.4
@@ -94,7 +94,6 @@
import CookieCrumbler
import utils
-
ADD_FOLDERS_PERMISSION = 'Add portal folders'
bases = (
@@ -133,7 +132,7 @@
utils.initializeBasesPhase2(z_tool_bases, context)
context.registerClass(
- DirectoryView.DirectoryView,
+ DirectoryView.DirectoryViewSurrogate,
constructors=(('manage_addDirectoryViewForm',
DirectoryView.manage_addDirectoryViewForm),
DirectoryView.manage_addDirectoryView,