def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. fp = expandpath(self.filepath) data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(fp): if not self._isAllowableFilename(entry): continue e_filepath = path.join(self.filepath, entry) e_fp = expandpath(e_filepath) if path.isdir(e_fp): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. info = registry.getDirectoryInfo(e_filepath) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(e_fp) info = registry.getDirectoryInfo(e_filepath) if info is not None: mt = types.get(entry) t = None if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView ob = t(entry, e_filepath) 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: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: properties = self._readProperties(e_fp + '.properties') try: ob = t(name, e_filepath, fullname=entry, properties=properties) except: import traceback typ, val, tb = exc_info() try: exc_lines = traceback.format_exception( typ, val, tb) LOG('DirectoryView', ERROR, join(exc_lines, '\n')) ob = BadFile(name, e_filepath, exc_str=join(exc_lines, '\r\n'), fullname=entry) finally: tb = None # Avoid leaking frame! ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(self._filepath, ignore=self.ignore): if not self._isAllowableFilename(entry): continue entry_filepath = path.join(self._filepath, entry) if path.isdir(entry_filepath): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. entry_minimal_fp = '/'.join((self._minimal_fp, entry)) info = registry.getDirectoryInfo(entry_minimal_fp) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(entry_filepath) info = registry.getDirectoryInfo(entry_minimal_fp) if info is not None: # Folders on the file system have no extension or # meta_type, as a crutch to enable customizing what gets # created to represent a filesystem folder in a # DirectoryView we use a fake type "FOLDER". That way # other implementations can register for that type and # circumvent the hardcoded assumption that all filesystem # directories will turn into DirectoryViews. mt = types.get(entry) or 'FOLDER' t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView metadata = FSMetadata(entry_filepath) metadata.read() ob = t(entry, entry_minimal_fp, properties=metadata.getProperties()) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) else: pos = entry.rfind('.') if pos >= 0: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: metadata = FSMetadata(entry_filepath) metadata.read() try: ob = t(name, entry_filepath, fullname=entry, properties=metadata.getProperties()) except: import sys import traceback typ, val, tb = sys.exc_info() try: logger.exception("prepareContents") exc_lines = traceback.format_exception( typ, val, tb) ob = BadFile(name, entry_filepath, exc_str='\r\n'.join(exc_lines), fullname=entry) finally: tb = None # Avoid leaking frame! # FS-based security permissions = metadata.getSecurity() if permissions is not None: for name in permissions.keys(): acquire, roles = permissions[name] try: ob.manage_permission(name, roles, acquire) except ValueError: logger.exception("Error setting permissions") # only DTML Methods and Python Scripts can have proxy roles if hasattr(ob, '_proxy_roles'): try: ob._proxy_roles = tuple(metadata.getProxyRoles()) except: logger.exception("Error setting proxy role") ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(self._filepath, ignore=self.ignore): if not self._isAllowableFilename(entry): continue entry_minimal_fp = '/'.join((self._minimal_fp, entry)) entry_filepath = path.join(self._filepath, entry) if path.isdir(entry_filepath): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. info = registry.getDirectoryInfo(entry_minimal_fp) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(entry_filepath) info = registry.getDirectoryInfo(entry_minimal_fp) if info is not None: mt = types.get(entry) t = None if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView ob = t(entry, entry_minimal_fp) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) else: pos = entry.rfind('.') if pos >= 0: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: metadata = FSMetadata(entry_filepath) metadata.read() try: ob = t(name, entry_minimal_fp, fullname=entry, properties=metadata.getProperties()) except: import traceback typ, val, tb = exc_info() try: exc_lines = traceback.format_exception( typ, val, tb) LOG('DirectoryView', ERROR, '\n'.join(exc_lines)) ob = BadFile(name, entry_minimal_fp, exc_str='\r\n'.join(exc_lines), fullname=entry) finally: tb = None # Avoid leaking frame! # FS-based security permissions = metadata.getSecurity() if permissions is not None: for name in permissions.keys(): acquire, roles = permissions[name] try: ob.manage_permission(name, roles, acquire) except ValueError: LOG('DirectoryView', ERROR, 'Error setting permissions', error=exc_info()) # only DTML Methods and Python Scripts can have proxy roles if hasattr(ob, '_proxy_roles'): try: ob._proxy_roles = tuple(metadata.getProxyRoles()) except: LOG('DirectoryView', ERROR, 'Error setting proxy role', error=exc_info()) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(self._filepath, ignore=self.ignore): if not self._isAllowableFilename(entry): continue entry_filepath = path.join(self._filepath, entry) if path.isdir(entry_filepath): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. entry_minimal_fp = '/'.join( (self._minimal_fp, entry) ) info = registry.getDirectoryInfo(entry_minimal_fp) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(entry_filepath) info = registry.getDirectoryInfo(entry_minimal_fp) if info is not None: # Folders on the file system have no extension or # meta_type, as a crutch to enable customizing what gets # created to represent a filesystem folder in a # DirectoryView we use a fake type "FOLDER". That way # other implementations can register for that type and # circumvent the hardcoded assumption that all filesystem # directories will turn into DirectoryViews. mt = types.get(entry) or 'FOLDER' t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView metadata = FSMetadata(entry_filepath) metadata.read() ob = t( entry , entry_minimal_fp , properties=metadata.getProperties() ) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) else: pos = entry.rfind('.') if pos >= 0: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: metadata = FSMetadata(entry_filepath) metadata.read() try: ob = t(name, entry_filepath, fullname=entry, properties=metadata.getProperties()) except: import sys import traceback typ, val, tb = sys.exc_info() try: logger.exception("prepareContents") exc_lines = traceback.format_exception( typ, val, tb ) ob = BadFile( name, entry_filepath, exc_str='\r\n'.join(exc_lines), fullname=entry ) finally: tb = None # Avoid leaking frame! # FS-based security permissions = metadata.getSecurity() if permissions is not None: for name in permissions.keys(): acquire, roles = permissions[name] try: ob.manage_permission(name,roles,acquire) except ValueError: logger.exception("Error setting permissions") # only DTML Methods and Python Scripts can have proxy roles if hasattr(ob, '_proxy_roles'): try: ob._proxy_roles = tuple(metadata.getProxyRoles()) except: logger.exception("Error setting proxy role") ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. fp = expandpath(self.filepath) data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(fp): if not self._isAllowableFilename(entry): continue e_filepath = path.join(self.filepath, entry) e_fp = expandpath(e_filepath) if path.isdir(e_fp): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. info = registry.getDirectoryInfo(e_filepath) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(e_fp) info = registry.getDirectoryInfo(e_filepath) if info is not None: mt = types.get(entry) t = None if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView ob = t(entry, e_filepath) 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: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: properties = self._readProperties( e_fp + '.properties') try: ob = t(name, e_filepath, fullname=entry, properties=properties) except: import traceback typ, val, tb = exc_info() try: exc_lines = traceback.format_exception( typ, val, tb ) LOG( 'DirectoryView', ERROR, join( exc_lines, '\n' ) ) ob = BadFile( name, e_filepath, exc_str=join( exc_lines, '\r\n' ), fullname=entry ) finally: tb = None # Avoid leaking frame! # FS-based security try: permissions = self._readSecurity(e_fp + '.security') if permissions is not None: for name in permissions.keys(): acquire,roles = permissions[name] ob.manage_permission(name,roles,acquire) except: LOG('DirectoryView', ERROR, 'Error setting permission from .security file information', error=exc_info()) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. data = {} objects = [] types = self._readTypesFile() for entry in _filtered_listdir(self._filepath): if not self._isAllowableFilename(entry): continue entry_minimal_fp = '/'.join( (self._minimal_fp, entry) ) entry_filepath = path.join(self._filepath, entry) if path.isdir(entry_filepath): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. info = registry.getDirectoryInfo(entry_minimal_fp) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByPath(entry_filepath) info = registry.getDirectoryInfo(entry_minimal_fp) if info is not None: mt = types.get(entry) t = None if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView ob = t(entry, entry_minimal_fp) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) else: pos = entry.rfind('.') if pos >= 0: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: metadata = FSMetadata(entry_filepath) metadata.read() try: ob = t(name, entry_minimal_fp, fullname=entry, properties=metadata.getProperties()) except: import traceback typ, val, tb = exc_info() try: exc_lines = traceback.format_exception( typ, val, tb ) LOG( 'DirectoryView', ERROR, '\n'.join(exc_lines) ) ob = BadFile( name, entry_minimal_fp, exc_str='\r\n'.join(exc_lines), fullname=entry ) finally: tb = None # Avoid leaking frame! # FS-based security permissions = metadata.getSecurity() if permissions is not None: for name in permissions.keys(): acquire, roles = permissions[name] try: ob.manage_permission(name,roles,acquire) except ValueError: LOG('DirectoryView', ERROR, 'Error setting permissions', error=exc_info()) # only DTML Methods can have proxy roles if hasattr(ob, '_proxy_roles'): try: ob._proxy_roles = tuple(metadata.getProxyRoles()) except: LOG('DirectoryView', ERROR, 'Error setting proxy role', error=exc_info()) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)
def prepareContents(self, registry, register_subdirs=0): # Creates objects for each file. fp = expandpath(self.filepath) data = {} objects = [] l = listdir(fp) types = self._readTypesFile() for entry in l: if not self._isAllowableFilename(entry): continue e_filepath = path.join(self.filepath, entry) e_fp = expandpath(e_filepath) if path.isdir(e_fp): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. info = registry.getDirectoryInfo(e_filepath) if info is None and register_subdirs: # Register unknown subdirs if entry not in ('CVS', 'SVN', '.', '..'): registry.registerDirectoryByPath(e_fp) info = registry.getDirectoryInfo(e_filepath) if info is not None: mt = types.get(entry) t = None if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = DirectoryView ob = t(entry, e_filepath) 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: name = entry[:pos] ext = path.normcase(entry[pos + 1:]) else: name = entry ext = '' if not name or name == 'REQUEST': # Not an allowable id. continue mo = bad_id(name) if mo is not None and mo != -1: # Both re and regex formats # Not an allowable id. continue t = None mt = types.get(entry, None) if mt is None: mt = types.get(name, None) if mt is not None: t = registry.getTypeByMetaType(mt) if t is None: t = registry.getTypeByExtension(ext) if t is not None: try: ob = t(name, e_filepath, fullname=entry) except: from zLOG import LOG, ERROR import sys, traceback typ, val, tb = sys.exc_info() exc_lines = traceback.format_exception( typ, val, tb ) LOG( 'DirectoryView', ERROR, join( exc_lines, '\n' ) ) ob = BadFile( name , e_filepath , exc_str=join( exc_lines, '\r\n' ) , fullname=entry ) ob_id = ob.getId() data[ob_id] = ob objects.append({'id': ob_id, 'meta_type': ob.meta_type}) return data, tuple(objects)