Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CMFCore.DirectoryView.DirectoryInformation Class Reference
Collaboration diagram for CMFCore.DirectoryView.DirectoryInformation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getSubdirs
def reload
def getContents
def prepareContents

Public Attributes

 ignore
 subdirs
 objects

Static Public Attributes

 data = None

Private Member Functions

def _isAllowableFilename
def _readTypesFile
def _changed
def _changed

Private Attributes

 _filepath
 _reg_key
 _walker
 _v_last_read
 _v_last_filelist

Static Private Attributes

int _v_last_read = 0
list _v_last_filelist = []

Detailed Description

Definition at line 109 of file DirectoryView.py.


Constructor & Destructor Documentation

def CMFCore.DirectoryView.DirectoryInformation.__init__ (   self,
  filepath,
  reg_key,
  ignore = ignore 
)

Definition at line 114 of file DirectoryView.py.

00114 
00115     def __init__(self, filepath, reg_key, ignore=ignore):
00116         self._filepath = filepath
00117         self._reg_key = reg_key
00118         self.ignore = base_ignore + tuple(ignore)
00119         if platform == 'win32':
00120             self._walker = _walker(self.ignore)
00121         subdirs = []
00122         for entry in _filtered_listdir(self._filepath, ignore=self.ignore):
00123            entry_filepath = path.join(self._filepath, entry)
00124            if path.isdir(entry_filepath):
00125                subdirs.append(entry)
00126         self.subdirs = tuple(subdirs)


Member Function Documentation

Definition at line 162 of file DirectoryView.py.

00162 
00163         def _changed(self):
00164             mtime=0
00165             filelist=[]
00166             try:
00167                 mtime = stat(self._filepath)[8]
00168                 if platform == 'win32':
00169                     # some Windows directories don't change mtime
00170                     # when a file is added to or deleted from them :-(
00171                     # So keep a list of files as well, and see if that
00172                     # changes
00173                     path.walk(self._filepath, self._walker, filelist)
00174                     filelist.sort()
00175             except:
00176                 logger.exception("Error checking for directory modification")
00177 
00178             if mtime != self._v_last_read or filelist != self._v_last_filelist:
00179                 self._v_last_read = mtime
00180                 self._v_last_filelist = filelist
00181 
00182                 return 1
00183 
00184             return 0

Here is the caller graph for this function:

Definition at line 187 of file DirectoryView.py.

00187 
00188         def _changed(self):
00189             return 0

Here is the call graph for this function:

Definition at line 130 of file DirectoryView.py.

00130 
00131     def _isAllowableFilename(self, entry):
00132         if entry[-1:] == '~':
00133             return 0
00134         if entry[:1] in ('_', '#'):
00135             return 0
00136         return 1

Here is the caller graph for this function:

Read the .objects file produced by FSDump.

Definition at line 140 of file DirectoryView.py.

00140 
00141     def _readTypesFile(self):
00142         """ Read the .objects file produced by FSDump.
00143         """
00144         types = {}
00145         try:
00146             f = open( path.join(self._filepath, '.objects'), 'rt' )
00147         except IOError:
00148             pass
00149         else:
00150             lines = f.readlines()
00151             f.close()
00152             for line in lines:
00153                 try:
00154                     obname, meta_type = line.split(':')
00155                 except ValueError:
00156                     pass
00157                 else:
00158                     types[obname.strip()] = meta_type.strip()
00159         return types

Here is the caller graph for this function:

Definition at line 190 of file DirectoryView.py.

00190 
00191     def getContents(self, registry):
00192         changed = self._changed()
00193         if self.data is None or changed:
00194             try:
00195                 self.data, self.objects = self.prepareContents(registry,
00196                     register_subdirs=changed)
00197             except:
00198                 logger.exception("Error during prepareContents")
00199                 self.data = {}
00200                 self.objects = ()
00201 
00202         return self.data, self.objects

Here is the call graph for this function:

Definition at line 127 of file DirectoryView.py.

00127 
00128     def getSubdirs(self):
00129         return self.subdirs

def CMFCore.DirectoryView.DirectoryInformation.prepareContents (   self,
  registry,
  register_subdirs = 0 
)

Definition at line 203 of file DirectoryView.py.

00203 
00204     def prepareContents(self, registry, register_subdirs=0):
00205         # Creates objects for each file.
00206         data = {}
00207         objects = []
00208         types = self._readTypesFile()
00209         for entry in _filtered_listdir(self._filepath, ignore=self.ignore):
00210             if not self._isAllowableFilename(entry):
00211                 continue
00212             entry_filepath = path.join(self._filepath, entry)
00213             if path.isdir(entry_filepath):
00214                 # Add a subdirectory only if it was previously registered,
00215                 # unless register_subdirs is set.
00216                 entry_reg_key = '/'.join((self._reg_key, entry))
00217                 info = registry.getDirectoryInfo(entry_reg_key)
00218                 if info is None and register_subdirs:
00219                     # Register unknown subdirs
00220                     registry.registerDirectoryByKey(entry_filepath,
00221                                                     entry_reg_key)
00222                     info = registry.getDirectoryInfo(entry_reg_key)
00223                 if info is not None:
00224                     # Folders on the file system have no extension or
00225                     # meta_type, as a crutch to enable customizing what gets
00226                     # created to represent a filesystem folder in a
00227                     # DirectoryView we use a fake type "FOLDER". That way
00228                     # other implementations can register for that type and
00229                     # circumvent the hardcoded assumption that all filesystem
00230                     # directories will turn into DirectoryViews.
00231                     mt = types.get(entry) or 'FOLDER'
00232                     t = registry.getTypeByMetaType(mt)
00233                     if t is None:
00234                         t = DirectoryView
00235                     metadata = FSMetadata(entry_filepath)
00236                     metadata.read()
00237                     ob = t( entry
00238                           , entry_reg_key
00239                           , properties=metadata.getProperties()
00240                           )
00241                     ob_id = ob.getId()
00242                     data[ob_id] = ob
00243                     objects.append({'id': ob_id, 'meta_type': ob.meta_type})
00244             else:
00245                 pos = entry.rfind('.')
00246                 if pos >= 0:
00247                     name = entry[:pos]
00248                     ext = path.normcase(entry[pos + 1:])
00249                 else:
00250                     name = entry
00251                     ext = ''
00252                 if not name or name == 'REQUEST':
00253                     # Not an allowable id.
00254                     continue
00255                 mo = bad_id(name)
00256                 if mo is not None and mo != -1:  # Both re and regex formats
00257                     # Not an allowable id.
00258                     continue
00259                 t = None
00260                 mt = types.get(entry, None)
00261                 if mt is None:
00262                     mt = types.get(name, None)
00263                 if mt is not None:
00264                     t = registry.getTypeByMetaType(mt)
00265                 if t is None:
00266                     t = registry.getTypeByExtension(ext)
00267 
00268                 if t is not None:
00269                     metadata = FSMetadata(entry_filepath)
00270                     metadata.read()
00271                     try:
00272                         ob = t(name, entry_filepath, fullname=entry,
00273                                properties=metadata.getProperties())
00274                     except:
00275                         import sys
00276                         import traceback
00277                         typ, val, tb = sys.exc_info()
00278                         try:
00279                             logger.exception("prepareContents")
00280 
00281                             exc_lines = traceback.format_exception( typ,
00282                                                                     val,
00283                                                                     tb )
00284                             ob = BadFile( name,
00285                                           entry_filepath,
00286                                           exc_str='\r\n'.join(exc_lines),
00287                                           fullname=entry )
00288                         finally:
00289                             tb = None   # Avoid leaking frame!
00290 
00291                     # FS-based security
00292                     permissions = metadata.getSecurity()
00293                     if permissions is not None:
00294                         for name in permissions.keys():
00295                             acquire, roles = permissions[name]
00296                             try:
00297                                 ob.manage_permission(name,roles,acquire)
00298                             except ValueError:
00299                                 logger.exception("Error setting permissions")
00300 
00301                     # only DTML Methods and Python Scripts can have proxy roles
00302                     if hasattr(ob, '_proxy_roles'):
00303                         try:
00304                             ob._proxy_roles = tuple(metadata.getProxyRoles())
00305                         except:
00306                             logger.exception("Error setting proxy role")
00307 
00308                     ob_id = ob.getId()
00309                     data[ob_id] = ob
00310                     objects.append({'id': ob_id, 'meta_type': ob.meta_type})
00311 
00312         return data, tuple(objects)
00313 

Here is the call graph for this function:

Definition at line 137 of file DirectoryView.py.

00137 
00138     def reload(self):
00139         self.data = None

Here is the caller graph for this function:


Member Data Documentation

Definition at line 115 of file DirectoryView.py.

Definition at line 116 of file DirectoryView.py.

Definition at line 112 of file DirectoryView.py.

Definition at line 179 of file DirectoryView.py.

Definition at line 111 of file DirectoryView.py.

Definition at line 178 of file DirectoryView.py.

Definition at line 119 of file DirectoryView.py.

Definition at line 110 of file DirectoryView.py.

Definition at line 117 of file DirectoryView.py.

Definition at line 194 of file DirectoryView.py.

Definition at line 125 of file DirectoryView.py.


The documentation for this class was generated from the following file: