Пример #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.'
Пример #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.'
Пример #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.'
Пример #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.'
Пример #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.'
Пример #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.'
Пример #7
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.'
Пример #8
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.'