def _makeOne( self, id, filename ): from Products.CMFCore.FSMetadata import FSMetadata from Products.CMFCore.FSSTXMethod import FSSTXMethod path = os.path.join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSSTXMethod( id, path, properties=metadata.getProperties() )
def _makeOne(self, id, filename): path = join(self.skin_path_name, filename) metadata = FSMetadata(filepath=path) metadata.read() return FSPythonScript(id, filepath=path, properties=metadata.getProperties())
def _makeOne(self, id, filename): from Products.CMFCore.FSMetadata import FSMetadata from Products.CMFCore.FSReSTMethod import FSReSTMethod path = os.path.join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSReSTMethod(id, path, properties=metadata.getProperties())
def _makeOne(self, id, filename): from Products.CMFCore.FSPageTemplate import FSPageTemplate path = path_join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSPageTemplate(id, path, properties=metadata.getProperties())
def _makeOne(self, id, filename): from Products.CMFCore.FSPageTemplate import FSPageTemplate path = path_join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSPageTemplate( id, path, properties=metadata.getProperties() )
def _makeOne(self, id, filename): path = path_join(self.skin_path_name, filename) metadata = FSMetadata(filepath=path) metadata.read() return FSPageTemplate(id, filepath=path, properties=metadata.getProperties())
def _read_validator_metadata(self, id, filepath): self.validators = FormValidatorContainer() metadata = FSMetadata(filepath) cfg = CMFConfigParser() if os.path.exists(filepath + '.metadata'): cfg.read(filepath + '.metadata') _buttons_for_status = {} validators = metadata._getSectionDict(cfg, 'validators') if validators is None: validators = {} for (k, v) in validators.items(): # validators.CONTEXT_TYPE.BUTTON = LIST component = k.split('.') while len(component) < 3: component.append('') if component[0] != 'validators': raise ValueError, '%s: Format for .metadata validators is validators.CONTEXT_TYPE.BUTTON = LIST (not %s)' % (filepath, k) context_type = component[1] self.validators.set(FormValidator(id, component[1], component[2], v)) status_key = str(context_type) if _buttons_for_status.has_key(status_key): _buttons_for_status[status_key].append(component[2]) else: _buttons_for_status[status_key] = [component[2]] for (k, v) in _buttons_for_status.items(): if v and not '' in v: content_type = k if not content_type: content_type = 'ANY' log('%s: No default validators specified for content type %s. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify default validators for this case.' % (str(filepath), content_type))
def _makeOne(self, id, filename): from Products.CMFCore.FSFile import FSFile from Products.CMFCore.FSMetadata import FSMetadata full_path = os.path.join(self.skin_path_name, filename) metadata = FSMetadata(full_path) metadata.read() return FSFile(id, full_path, properties=metadata.getProperties())
def _baseReadMetadata(self): # re-read .metadata file if it exists e_fp = self._filepath + '.metadata' if os.path.exists(e_fp): metadata = FSMetadata(e_fp) metadata.read() self._setProperties(metadata.getProperties()) # re-read actions and validators whenever we re-read the file self._read_action_metadata(self.getId(), self._filepath) self._read_validator_metadata(self.getId(), self._filepath)
def registerDirectory(self, directory, package): """See interface""" dirkey = getDirKey(package, directory) for filename in os.listdir(directory): if len(filename) > 3 and filename.endswith(".pt"): path = osjoin(directory, filename) tmplkey = getTemplateKey(dirkey, filename) metadata = FSMetadata(path) metadata.read() properties = metadata.getProperties() title = properties.get("title", filename[:-3]) self._templates[tmplkey] = (title.decode("utf-8"), ViewPageTemplateFile(path)) migration.add_to_migration_map(tmplkey, path)
def _makeOne( self, id, filename ): from Products.CMFCore.FSFile import FSFile from Products.CMFCore.FSMetadata import FSMetadata full_path = path_join(self.skin_path_name, filename) metadata = FSMetadata(filepath=full_path) metadata.read() fsfile_ob = FSFile(id, filepath=full_path, properties=metadata.getProperties(), ) return fsfile_ob
def registerDirectory(self, directory, package): """See interface""" dirkey = getDirKey(package, directory) for filename in os.listdir(directory): if len(filename) > 3 and filename.endswith('.pt'): path = osjoin(directory, filename) tmplkey = getTemplateKey(dirkey, filename) metadata = FSMetadata(path) metadata.read() properties = metadata.getProperties() title = properties.get('title', filename[:-3]) self._templates[tmplkey] = (title.decode('utf-8'), ViewPageTemplateFile(path)) migration.add_to_migration_map(tmplkey, path)
def _makeOne(self, id, filename): from Products.CMFCore.FSFile import FSFile from Products.CMFCore.FSMetadata import FSMetadata full_path = path_join(self.skin_path_name, filename) metadata = FSMetadata(filepath=full_path) metadata.read() fsfile_ob = FSFile( id, filepath=full_path, properties=metadata.getProperties(), ) return fsfile_ob
def _read_action_metadata(self, id, filepath): self.actions = FormActionContainer() metadata = FSMetadata(filepath) cfg = CMFConfigParser() if os.path.exists(filepath + ".metadata"): cfg.read(filepath + ".metadata") _buttons_for_status = {} actions = metadata._getSectionDict(cfg, "actions") if actions is None: actions = {} for (k, v) in actions.items(): # action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG component = k.split(".") while len(component) < 4: component.append("") if component[0] != "action": raise ValueError, "%s: Format for .metadata actions is action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG (not %s)" % ( filepath, k, ) act = v.split(":", 1) while len(act) < 2: act.append("") context_type = component[2] self.actions.set(FormAction(id, component[1], component[2], component[3], act[0], act[1])) status_key = str(component[1]) + "." + str(context_type) if _buttons_for_status.has_key(status_key): _buttons_for_status[status_key].append(component[3]) else: _buttons_for_status[status_key] = [component[3]] for (k, v) in _buttons_for_status.items(): if v and not "" in v: sk = k.split(".") status = sk[0] content_type = sk[1] if not status: status = "ANY" if not content_type: content_type = "ANY" log( "%s: No default action specified for status %s, content type %s. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify a default action for this case." % (str(filepath), status, content_type), log_level=logging.DEBUG, )
def _read_action_metadata(self, id, filepath): self.actions = FormActionContainer() metadata = FSMetadata(filepath) cfg = CMFConfigParser() if os.path.exists(filepath + '.metadata'): cfg.read(filepath + '.metadata') _buttons_for_status = {} actions = metadata._getSectionDict(cfg, 'actions') if actions is None: actions = {} for (k, v) in actions.items(): # action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG component = k.split('.') while len(component) < 4: component.append('') if component[0] != 'action': raise ValueError, '%s: Format for .metadata actions is action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG (not %s)' % ( filepath, k) act = v.split(':', 1) while len(act) < 2: act.append('') context_type = component[2] self.actions.set( FormAction(id, component[1], component[2], component[3], act[0], act[1])) status_key = str(component[1]) + '.' + str(context_type) if _buttons_for_status.has_key(status_key): _buttons_for_status[status_key].append(component[3]) else: _buttons_for_status[status_key] = [component[3]] for (k, v) in _buttons_for_status.items(): if v and not '' in v: sk = k.split('.') status = sk[0] content_type = sk[1] if not status: status = 'ANY' if not content_type: content_type = 'ANY' log('%s: No default action specified for status %s, content type %s. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify a default action for this case.' % (str(filepath), status, content_type), log_level=logging.DEBUG)
def _read_validator_metadata(self, id, filepath): self.validators = FormValidatorContainer() metadata = FSMetadata(filepath) cfg = CMFConfigParser() if os.path.exists(filepath + '.metadata'): cfg.read(filepath + '.metadata') _buttons_for_status = {} validators = metadata._getSectionDict(cfg, 'validators') if validators is None: validators = {} for (k, v) in validators.items(): # validators.CONTEXT_TYPE.BUTTON = LIST component = k.split('.') while len(component) < 3: component.append('') if component[0] != 'validators': raise ValueError, '%s: Format for .metadata validators is validators.CONTEXT_TYPE.BUTTON = LIST (not %s)' % ( filepath, k) context_type = component[1] self.validators.set( FormValidator(id, component[1], component[2], v)) status_key = str(context_type) if _buttons_for_status.has_key(status_key): _buttons_for_status[status_key].append(component[2]) else: _buttons_for_status[status_key] = [component[2]] for (k, v) in _buttons_for_status.items(): if v and not '' in v: content_type = k if not content_type: content_type = 'ANY' log('%s: No default validators specified for content type %s. Users of IE can submit pages using the return key, resulting in no button in the REQUEST. Please specify default validators for this case.' % (str(filepath), content_type), log_level=logging.DEBUG)
def _makeOne( self, id, filename ): path = path_join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSPageTemplate( id, path, properties=metadata.getProperties() )
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_reg_key = '/'.join((self._reg_key, entry)) info = registry.getDirectoryInfo(entry_reg_key) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByKey(entry_filepath, entry_reg_key) info = registry.getDirectoryInfo(entry_reg_key) 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_reg_key, 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") ########################################################################### # This is the monkeypatch. These lines don't exist in CMFCore. This allows # unauthenticated users to access filesystem-based resources like page # templates and static UI elements. ########################################################################### else: ob.manage_permission('View', ('Authenticated', ), 1) ########################################################################### # End monkeypatch ########################################################################### # 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 _makeOne( self, id, filename ): path = join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSPythonScript( id, path, properties=metadata.getProperties() )
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 = os.path.join(self._filepath, entry) if os.path.isdir(entry_filepath): # Add a subdirectory only if it was previously registered, # unless register_subdirs is set. entry_reg_key = '/'.join((self._reg_key, entry)) info = registry.getDirectoryInfo(entry_reg_key) if info is None and register_subdirs: # Register unknown subdirs registry.registerDirectoryByKey(entry_filepath, entry_reg_key) info = registry.getDirectoryInfo(entry_reg_key) 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_reg_key , 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 = os.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 _makeOne(self, id, filename): path = path_join(self.skin_path_name, filename) metadata = FSMetadata(path) metadata.read() return FSDTMLMethod(id, path, properties=metadata.getProperties())
def _makeOne( self, id, filename ): path = join( self.skin_path_name, filename ) metadata = FSMetadata( filepath=path ) metadata.read() return FSZSQLMethod( id, filepath=path, properties=metadata.getProperties() )