Ejemplo n.º 1
0
def importCookieCrumbler(context):
    """ Import cookie crumbler settings from an XML file.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    cctool = getToolByName(site, 'cookie_authentication')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Cookie crumbler: Nothing to import.'

    importer = INodeImporter(cctool, None)
    if importer is None:
        return 'Cookie crumbler: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Cookie crumbler settings imported.'
Ejemplo n.º 2
0
def importMailHost(context):
    """ Import mailhost settings from an XML file.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    mailhost = getToolByName(site, 'MailHost')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Mailhost: Nothing to import.'

    importer = INodeImporter(mailhost, None)
    if importer is None:
        return 'Mailhost: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Mailhost settings imported.'
Ejemplo n.º 3
0
def importCatalogTool(context):
    """ Import catalog tool.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    ctool = getToolByName(site, 'portal_catalog')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Catalog tool: Nothing to import.'

    importer = INodeImporter(ctool, None)
    if importer is None:
        return 'Catalog tool: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Catalog tool imported.'
Ejemplo n.º 4
0
def importActionProviders(context):
    """ Import actions tool.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    atool = getToolByName(site, 'portal_actions')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Actions tool: Nothing to import.'

    importer = INodeImporter(atool, None)
    if importer is None:
        return 'Actions tool: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Actions tool imported.'
Ejemplo n.º 5
0
def importMailHost(context):
    """ Import mailhost settings from an XML file.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    mailhost = getToolByName(site, 'MailHost')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Mailhost: Nothing to import.'

    importer = INodeImporter(mailhost, None)
    if importer is None:
        return 'Mailhost: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Mailhost settings imported.'
Ejemplo n.º 6
0
def importCookieCrumbler(context):
    """ Import cookie crumbler settings from an XML file.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    cctool = getToolByName(site, 'cookie_authentication')

    body = context.readDataFile(_FILENAME)
    if body is None:
        return 'Cookie crumbler: Nothing to import.'

    importer = INodeImporter(cctool, None)
    if importer is None:
        return 'Cookie crumbler: Import adapter misssing.'

    importer.importNode(parseString(body).documentElement, mode=mode)
    return 'Cookie crumbler settings imported.'
Ejemplo n.º 7
0
 def importNode(self, node, mode=PURGE):
     """Import the object from the DOM node.
     """
     for child in node.childNodes:
         if child.nodeName == 'filtered_set':
             set_id = str(child.getAttribute('name'))
             set_meta_type = str(child.getAttribute('meta_type'))
             self.context.addFilteredSet(set_id, set_meta_type, '')
             set = self.context.filteredSets[set_id]
             INodeImporter(set).importNode(child)
     self.context.clear()
Ejemplo n.º 8
0
def manage_addAction(self, id, settings_id='', REQUEST=None):
    """Add a new CMF Action object with ID *id*.
    """
    settings_node = None
    if settings_id:
        stool = getToolByName(self, 'portal_setup', None)
        if stool:
            path = settings_id.split('/')
            context = stool._getImportContext(path.pop(0))
            body = context.readDataFile('actions.xml')
            if body is not None:
                root = parseString(body).documentElement
                for node in root.childNodes:
                    if node.nodeName != 'object':
                        continue
                    for obj_id in path:
                        for child in node.childNodes:
                            if child.nodeName != 'object':
                                continue
                            if child.getAttribute('name') != obj_id:
                                continue
                            if child.getAttribute(
                                    'meta_type') == Action.meta_type:
                                settings_node = child
                            else:
                                node = child
                            break
                    if settings_node:
                        if not id:
                            id = obj_id
                        break
    obj = Action(id)
    if settings_node:
        INodeImporter(obj).importNode(settings_node)
    self._setObject(id, obj)

    if REQUEST:
        return self.manage_main(self, REQUEST)
Ejemplo n.º 9
0
def manage_addTypeInfo(dispatcher,
                       add_meta_type,
                       id,
                       settings_id='',
                       REQUEST=None):
    """Add a new TypeInformation object of type 'add_meta_type' with ID 'id'.
    """
    settings_node = None
    if settings_id:
        stool = getToolByName(dispatcher, 'portal_setup', None)
        if stool:
            profile_id, type_id = settings_id.split('/')
            context = stool._getImportContext(profile_id)
            filenames = context.listDirectory('types')
            for filename in filenames or ():
                body = context.readDataFile(filename, subdir='types')
                if body is not None:
                    root = parseString(body).documentElement
                    if root.getAttribute('name') != type_id:
                        continue
                    if root.getAttribute('meta_type') == add_meta_type:
                        settings_node = root
                        if not id:
                            id = type_id
                        break
    for mt in Products.meta_types:
        if mt['name'] == add_meta_type:
            klass = mt['instance']
            break
    else:
        raise ValueError('Meta type %s is not a type class.' % add_meta_type)
    obj = klass(id)
    if settings_node:
        INodeImporter(obj).importNode(settings_node)
    dispatcher._setObject(id, obj)

    if REQUEST:
        return dispatcher.manage_main(dispatcher, REQUEST)
Ejemplo n.º 10
0
    def _initIndexes(self, node, mode):
        for child in node.childNodes:
            if child.nodeName != 'index':
                continue
            if child.hasAttribute('deprecated'):
                continue
            zcatalog = self.context

            idx_id = str(child.getAttribute('name'))
            if idx_id not in zcatalog.indexes():
                extra = _extra()
                for sub in child.childNodes:
                    if sub.nodeName == 'extra':
                        name = str(sub.getAttribute('name'))
                        value = str(sub.getAttribute('value'))
                        setattr(extra, name, value)
                extra = extra.__dict__ and extra or None

                meta_type = str(child.getAttribute('meta_type'))
                zcatalog.addIndex(idx_id, meta_type, extra)

            idx = zcatalog._catalog.getIndex(idx_id)
            INodeImporter(idx).importNode(child, mode)
Ejemplo n.º 11
0
def importTypesTool(context):
    """ Import types tool and content types from XML files.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    ttool = getToolByName(site, 'portal_types')

    if context.shouldPurge():
        for type in ttool.objectIds():
            ttool._delObject(type)

    ttc = TypesToolImportConfigurator(site)
    xml = context.readDataFile(_FILENAME)
    if xml is None:
        return 'Types tool: Nothing to import.'

    tool_info = ttc.parseXML(xml)

    for type_info in tool_info['types']:

        filename = type_info['filename']
        sep = filename.rfind('/')
        if sep == -1:
            body = context.readDataFile( filename )
        else:
            body = context.readDataFile( filename[sep+1:], filename[:sep] )

        if body is None:
            continue

        root = parseString(body).documentElement
        ti_id = str(root.getAttribute('name'))
        if not ti_id:
            # BBB: for CMF 1.5 profiles
            #      ID moved from 'id' to 'name'.
            ti_id = str(root.getAttribute('id'))
        if ti_id not in ttool.objectIds():
            # BBB: for CMF 1.5 profiles
            #     'kind' is now 'meta_type', the old 'meta_type' attribute
            #      was replaced by a property element.
            meta_type = str(root.getAttribute('kind'))
            if not meta_type:
                meta_type = str(root.getAttribute('meta_type'))
            for mt_info in Products.meta_types:
                if mt_info['name'] == meta_type:
                    ttool._setObject(ti_id, mt_info['instance'](ti_id))
                    break
            else:
                raise ValueError('unknown meta_type \'%s\'' % ti_id)

        ti = ttool.getTypeInfo(ti_id)
        importer = INodeImporter(ti, None)
        if importer is None:
            continue

        importer.importNode(root, mode=mode)

    # XXX: YAGNI?
    # importScriptsToContainer(ttool, ('typestool_scripts',),
    #                          context)

    return 'Types tool imported.'
Ejemplo n.º 12
0
def importTypesTool(context):
    """ Import types tool and content types from XML files.
    """
    site = context.getSite()
    mode = context.shouldPurge() and PURGE or UPDATE
    ttool = getToolByName(site, 'portal_types')

    if context.shouldPurge():
        for type in ttool.objectIds():
            ttool._delObject(type)

    ttc = TypesToolImportConfigurator(site)
    xml = context.readDataFile(_FILENAME)
    if xml is None:
        return 'Types tool: Nothing to import.'

    tool_info = ttc.parseXML(xml)

    for type_info in tool_info['types']:

        filename = type_info['filename']
        sep = filename.rfind('/')
        if sep == -1:
            body = context.readDataFile(filename)
        else:
            body = context.readDataFile(filename[sep + 1:], filename[:sep])

        if body is None:
            continue

        root = parseString(body).documentElement
        ti_id = str(root.getAttribute('name'))
        if not ti_id:
            # BBB: for CMF 1.5 profiles
            #      ID moved from 'id' to 'name'.
            ti_id = str(root.getAttribute('id'))
        if ti_id not in ttool.objectIds():
            # BBB: for CMF 1.5 profiles
            #     'kind' is now 'meta_type', the old 'meta_type' attribute
            #      was replaced by a property element.
            meta_type = str(root.getAttribute('kind'))
            if not meta_type:
                meta_type = str(root.getAttribute('meta_type'))
            for mt_info in Products.meta_types:
                if mt_info['name'] == meta_type:
                    ttool._setObject(ti_id, mt_info['instance'](ti_id))
                    break
            else:
                raise ValueError('unknown meta_type \'%s\'' % ti_id)

        ti = ttool.getTypeInfo(ti_id)
        importer = INodeImporter(ti, None)
        if importer is None:
            continue

        importer.importNode(root, mode=mode)

    # XXX: YAGNI?
    # importScriptsToContainer(ttool, ('typestool_scripts',),
    #                          context)

    return 'Types tool imported.'