コード例 #1
0
def grok(*module_names):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.compat', config)
    zcml.do_grok('grokcore.component.meta', config)
    for module_name in module_names:
        zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #2
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.security.testing', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #3
0
ファイル: testing.py プロジェクト: clozinski/grok
def grok(module_name=None):
    """Grok a module.

    Test helper to 'grok' a module named by `module_name`, a dotted
    path to a module like ``'mypkg.mymodule'``. 'grokking' hereby
    means to do all the ZCML configurations triggered by directives
    like ``grok.context()`` etc. This is only needed if your module
    was not `grokked` during test setup time as it normally happens
    with functional tests.
    """
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grokcore.catalog.meta', config)
    zcml.do_grok('grokcore.traverser.meta', config)
    zcml.do_grok('grokcore.rest.meta', config)
    zcml.do_grok('grokcore.xmlrpc.meta', config)
    if module_name is not None:
        zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #4
0
ファイル: testing.py プロジェクト: py361/grok
def grok(module_name=None):
    """Grok a module.

    Test helper to 'grok' a module named by `module_name`, a dotted
    path to a module like ``'mypkg.mymodule'``. 'grokking' hereby
    means to do all the ZCML configurations triggered by directives
    like ``grok.context()`` etc. This is only needed if your module
    was not `grokked` during test setup time as it normally happens
    with functional tests.
    """
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grokcore.catalog.meta', config)
    zcml.do_grok('grokcore.traverser.meta', config)
    zcml.do_grok('grokcore.rest.meta', config)
    zcml.do_grok('grokcore.xmlrpc.meta', config)
    if module_name is not None:
        zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #5
0
ファイル: registry.py プロジェクト: msiedlarek/alpaca
 def load_zcml(self, zcml_asset_specification):
     def _get_site_manager(context=None):
         return self
     if ':' not in zcml_asset_specification:
         import alpaca
         config_package = alpaca
         config_file = zcml_asset_specification
     else:
         package_name, config_file = zcml_asset_specification.split(':')
         __import__(package_name)
         config_package = sys.modules[package_name]
     context = ConfigurationMachine()
     context.package = config_package
     xmlconfig.registerCommonDirectives(context)
     xmlconfig.file(
         config_file,
         package=config_package,
         context=context,
         execute=False
     )
     getSiteManager.sethook(_get_site_manager)
     try:
         context.execute_actions()
     finally:
         getSiteManager.reset()
コード例 #6
0
ファイル: testing.py プロジェクト: CGTIC/Plone_SP
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.security.testing', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #7
0
def grok(*modules):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.viewlet.meta', config)
    for name in modules:
        zcml.do_grok(name, config)
    config.execute_actions()
コード例 #8
0
ファイル: main.py プロジェクト: collective/transmogrifier
def configure(arguments):
    # Enable venuasianconfiguration
    if HAS_VENUSIANCONFIGURATION:
        import venusianconfiguration
        venusianconfiguration.enable()

    # BBB: Support Zope's global configuration context
    if HAS_ZOPE:
        try:
            import Zope2.App.zcml
            config = Zope2.App.zcml._context or ConfigurationMachine()
        except (ImportError, AttributeError):
            config = ConfigurationMachine()
    else:
        config = ConfigurationMachine()

    # Parse and evaluate configuration and plugins
    registerCommonDirectives(config)

    import transmogrifier
    xmlconfig.include(config, package=transmogrifier, file='meta.zcml')
    xmlconfig.include(config, package=transmogrifier, file='configure.zcml')

    # Resolve includes
    for include in set(arguments.get('--include')):
        package, filename = parse_include(include)
        if package and filename:
            package = importlib.import_module(package)
            xmlconfig.include(config, package=package, file=filename)
        elif package and HAS_VENUSIANCONFIGURATION:
            # Support including single module in the current working directory
            import venusianconfiguration
            venusianconfiguration.venusianscan(package, config)

    config.execute_actions()
コード例 #9
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grokcore.catalog.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #10
0
ファイル: main.py プロジェクト: collective/transmogrifier
def configure(arguments):
    # Enable venuasianconfiguration
    if HAS_VENUSIANCONFIGURATION:
        import venusianconfiguration
        venusianconfiguration.enable()

    # BBB: Support Zope's global configuration context
    if HAS_ZOPE:
        try:
            import Zope2.App.zcml
            config = Zope2.App.zcml._context or ConfigurationMachine()
        except (ImportError, AttributeError):
            config = ConfigurationMachine()
    else:
        config = ConfigurationMachine()

    # Parse and evaluate configuration and plugins
    registerCommonDirectives(config)

    import transmogrifier
    xmlconfig.include(config, package=transmogrifier, file='meta.zcml')
    xmlconfig.include(config, package=transmogrifier, file='configure.zcml')

    # Resolve includes
    for include in set(arguments.get('--include')):
        package, filename = parse_include(include)
        if package and filename:
            package = importlib.import_module(package)
            xmlconfig.include(config, package=package, file=filename)
        elif package and HAS_VENUSIANCONFIGURATION:
            # Support including single module in the current working directory
            import venusianconfiguration
            venusianconfiguration.venusianscan(package, config)

    config.execute_actions()
コード例 #11
0
def __main__():
    # Enable logging
    logging.basicConfig(level=logging.INFO)

    # Parse cli arguments
    arguments = docopt(__doc__)

    # Parse and evaluate configuration and plugins
    config = ConfigurationMachine()
    registerCommonDirectives(config)
    xmlconfig.include(config, package=collective.transmogrifier,
                      file='meta.zcml')
    xmlconfig.include(config, package=collective.transmogrifier,
                      file='configure.zcml')
    config.execute_actions()

    if arguments.get('--list'):
        blueprints = dict(getUtilitiesFor(ISectionBlueprint))
        pipelines = map(configuration_registry.getConfiguration,
                        configuration_registry.listConfigurationIds())
        print """
Available blueprints
--------------------
{0:s}

Available pipelines
-------------------
{1:s}
""".format('\n'.join(sorted(blueprints.keys())),
           '\n'.join(['{0:s}\n    {1:s}: {2:s}'.format(
                      p['id'], p['title'], p['description'])
                      for p in pipelines]))
        return

    # Load optional overrides
    overrides = {}
    overrides_path = arguments.get('--overrides')
    if overrides_path and not os.path.isabs(overrides_path):
        overrides_path = os.path.join(os.getcwd(), overrides_path)
    if overrides_path:
        parser = ConfigParser.RawConfigParser()
        parser.optionxform = str  # case sensitive
        with open(overrides_path) as fp:
            parser.readfp(fp)
        overrides.update(dict(((section, dict(parser.items(section)))
                               for section in parser.sections())))

    # Initialize optional context
    context_path = arguments.get('--context')
    if context_path is None:
        context = dict()
    else:
        context_module_path, context_class_name = context_path.rsplit('.', 1)
        context_module = importlib.import_module(context_module_path)
        context = getattr(context_module, context_class_name)()

    # Transmogrify
    for pipeline in arguments.get('<pipeline>'):
        ITransmogrifier(context)(pipeline, **overrides)
コード例 #12
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.view.meta', config)
    zcml.do_grok("dolmen.location", config)
    zcml.do_grok("dolmen.forms.base", config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #13
0
ファイル: testing.py プロジェクト: jean/grokcore.permission
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.permission', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #14
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.view.meta', config)
    if HAS_SECURITY:
        zcml.do_grok('grokcore.security.meta', config)
        zcml.do_grok('dolmen.view.security', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #15
0
ファイル: testing.py プロジェクト: trollfot/dolmen.menu
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.viewlet.meta', config)
    zcml.do_grok('dolmen.location', config)
    zcml.do_grok('dolmen.menu.meta', config)
    zcml.do_grok('dolmen.menu.components', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #16
0
ファイル: testing.py プロジェクト: gyst/grokcore.json
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.json', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #17
0
def setup_module(module):
    config = ConfigurationMachine()
    testing.grok('grokcore.component.meta')
    testing.grok('dolmen.forms.base')
    testing.grok('dolmen.forms.ztk')
    testing.grok('dolmen.view.meta')
    testing.grok('ul.browser')
    testing.grok('ul.auth.browser')
    config.execute_actions()
    provideAdapter(echo_layout, (IRequest, Interface), ILayout, name='')
コード例 #18
0
ファイル: zcml.py プロジェクト: markramm/pyramid
def zcml_configure(name, package):
    """ Given a ZCML filename as ``name`` and a Python package as
    ``package`` which the filename should be relative to, load the
    ZCML into the current ZCML registry.

    """
    context = ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    context.package = package
    xmlconfig.include(context, name, package)
    context.execute_actions(clear=False) # the raison d'etre
    return context.actions
コード例 #19
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.view.meta.views', config)
    zcml.do_grok('grokcore.view.meta.templates', config)
    zcml.do_grok('grokcore.view.meta.skin', config)
    # Use the Five override for the page template factory
    # zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('five.grok.templatereg', config)
    zcml.do_grok('five.grok.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #20
0
ファイル: zcml.py プロジェクト: malthe/repoze.bfg.skins
 def configure(self):
     gsm = component.getGlobalSiteManager
     component.getGlobalSiteManager = get_current_registry
     manager.push({'registry': self.registry})
     try:
         context = ConfigurationMachine()
         for action in self():
             context.action(*action)
         context.execute_actions()
     finally:
         component.getGlobalSiteManager = gsm
         manager.pop()
コード例 #21
0
ファイル: testing.py プロジェクト: grodniewicz/oship
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grok.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #22
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grok.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #23
0
def file(name, package=None, context=None, execute=True):
    """Execute a zcml file
    """

    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)
        context.package = package

    include(context, name, package)
    if execute:
        context.execute_actions()

    return context
コード例 #24
0
ファイル: xmlconfig.py プロジェクト: aregee/Mailman
def file(name, package=None, context=None, execute=True):
    """Execute a zcml file
    """

    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)
        context.package = package

    include(context, name, package)
    if execute:
        context.execute_actions()

    return context
コード例 #25
0
def load_zcml(*args):
    """We rely on grok to load the configuration for our modules, but we depend on some libraries which
    have only zcml based configuration, thus we need to load only those we need."""

    from zope.configuration.config import ConfigurationMachine
    from zope.configuration import xmlconfig

    context = ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)

    for i in args:
        xmlconfig.include(context, "configure.zcml", context.resolve(i))

    context.execute_actions()
コード例 #26
0
def string(s, context=None, name="<string>", execute=True):
    """Execute a zcml string
    """
    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)

    f = StringIO(s)
    f.name = name
    processxmlfile(f, context)

    if execute:
        context.execute_actions()

    return context
コード例 #27
0
ファイル: xmlconfig.py プロジェクト: aregee/Mailman
def string(s, context=None, name="<string>", execute=True):
    """Execute a zcml string
    """
    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)

    f = StringIO(s)
    f.name = name
    processxmlfile(f, context)

    if execute:
        context.execute_actions()

    return context
コード例 #28
0
ファイル: zcml.py プロジェクト: malthe/repoze.bfg.skins
def register_skin_view(relative_path, path, kwargs):
    registry = get_current_registry()

    for inst in registry.getAllUtilitiesRegisteredFor(ISkinObject):
        if inst.path == path:
            break
    else:
        raise RuntimeError("Skin object not found: %s." % relative_path)

    name = type(inst).component_name(relative_path).replace('/', '_')

    context = ConfigurationMachine()
    register_bfg_view(
        context, name=name, view=inst, **kwargs)
    context.execute_actions()
コード例 #29
0
ファイル: testing.py プロジェクト: grodniewicz/oship
def grok_component(name, component,
                   context=None, module_info=None, templates=None):
    if module_info is None:
        obj_module = getattr(component, '__grok_module__', None)
        if obj_module is None:
            obj_module = getattr(component, '__module__', None)
        module_info = scan.module_info_from_dotted_name(obj_module)

    module = module_info.getModule()
    if context is not None:
        grokcore.component.context.set(module, context)
    if templates is not None:
        module.__grok_templates__ = templates
    config = ConfigurationMachine()
    result = zcml.the_multi_grokker.grok(name, component,
                                         module_info=module_info,
                                         config=config)
    config.execute_actions()    
    return result
コード例 #30
0
 def test_w_valid_xml_fp(self):
     # Integration test, really
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file = open(path("samplepackage", "configure.zcml"))
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     self._callFUT(file, context)
     self.assertEqual(foo.data, [])
     context.execute_actions()
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertEqual(clean_info_path(repr(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
     self.assertEqual(clean_info_path(str(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
             + '    <test:foo x="blah" y="0" />')
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
コード例 #31
0
 def test_w_valid_xml_fp(self):
     # Integration test, really
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file = open(path("samplepackage", "configure.zcml"))
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     self._callFUT(file, context)
     self.assertEqual(foo.data, [])
     context.execute_actions()
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertEqual(clean_info_path(repr(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
     self.assertEqual(clean_info_path(str(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
             + '    <test:foo x="blah" y="0" />')
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
コード例 #32
0
def grok_component(name, component,
                   context=None, module_info=None, templates=None, dotted_name=None):
    if module_info is None:
        if dotted_name is None:
            dotted_name = getattr(component, '__grok_module__', None)
            if dotted_name is None:
                dotted_name = getattr(component, '__module__', None)
            module_info = scan.module_info_from_dotted_name(dotted_name)
        module_info = scan.module_info_from_dotted_name(dotted_name)

    module = module_info.getModule()
    if context is not None:
        grokcore.component.context.set(module, context)
    if templates is not None:
        module.__grok_templates__ = templates
    config = ConfigurationMachine()
    result = zcml.the_multi_grokker.grok(name, component,
                                         module_info=module_info,
                                         config=config)
    config.execute_actions()    
    return result
コード例 #33
0
def sectionsSetUp(test):
    setUp(test)

    from collective.transmogrifier.transmogrifier import Transmogrifier
    test.globs['transmogrifier'] = Transmogrifier(test.globs['plone'])

    import collective.transmogrifier.sections

    context = ConfigurationMachine()
    registerCommonDirectives(context)
    xmlconfig.file('testing.zcml', collective.transmogrifier.sections,
                   context=context)
    context.execute_actions()
    provideUtility(SampleSource,
        name=u'collective.transmogrifier.sections.tests.samplesource')
    provideUtility(RangeSource,
        name=u'collective.transmogrifier.sections.tests.rangesource')

    import logging
    from zope.testing import loggingsupport
    test.globs['handler'] = loggingsupport.InstalledHandler(
        'logger', level=logging.INFO)
コード例 #34
0
    def onDiscovery(self, theme, settings, dependenciesSettings):
        res = queryResourceDirectory(THEME_RESOURCE_NAME, theme)
        if res is None:
            return

        directoryName = 'views'
        if 'directory' in settings:
            directoryName = settings['directory']

        if res.isDirectory(directoryName):
            viewsDir = res[directoryName]

            layer = getattr(schemata, theme, None)

            if 'layer' in settings:
                layerName = settings['layer']

                try:
                    layer = resolve(layerName)
                except (
                        ImportError,
                        AttributeError,
                ):
                    logger.warn("Could not import %s" % layerName)
                    return

            viewConfig = SafeConfigParser()

            if viewsDir.isFile(VIEW_CONFIG_FILENAME):
                fp = viewsDir.openFile(VIEW_CONFIG_FILENAME)
                try:
                    viewConfig.readfp(fp)
                finally:
                    try:
                        fp.close()
                    except AttributeError:
                        pass

            views = []
            configurationMachine = ConfigurationMachine()
            path = viewsDir.directory

            for filename in os.listdir(path):
                if not filename.lower().endswith(EXTENSION):
                    continue

                name = viewName = filename[:-3]
                permission = 'zope2.View'
                for_ = Interface
                class_ = None
                template = os.path.join(path, filename)
                menu = {}

                # Read override options from views.cfg if applicable
                if viewConfig.has_section(name):

                    if viewConfig.has_option(name, 'name'):
                        viewName = viewConfig.get(name, 'name')

                    if viewConfig.has_option(name, 'permission'):
                        permission = viewConfig.get(name, 'permission')

                    if viewConfig.has_option(name, 'for'):
                        forStr = viewConfig.get(name, 'for')
                        if forStr != "*":
                            for_ = resolve(forStr)

                    if viewConfig.has_option(name, 'class'):
                        class_ = resolve(viewConfig.get(name, 'class'))

                    if viewConfig.has_option(name, 'menu'):
                        menu = dict(
                            title=viewConfig.get(name, 'menu'),
                            menu=getattr(zope.browsermenu.metaconfigure.menus,
                                         "plone_displayviews"),
                        )

                Products.Five.browser.metaconfigure.page(configurationMachine,
                                                         name=viewName,
                                                         permission=permission,
                                                         for_=for_,
                                                         layer=layer,
                                                         template=template,
                                                         class_=class_,
                                                         **menu)

                views.append(name)

            if len(views) > 0:
                configurationMachine.execute_actions()

            self.registered[theme] = views
コード例 #35
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok(module_name, config)
    config.execute_actions()
コード例 #36
0
def configure(*packages):
    config = ConfigurationMachine()
    for package in packages:
        grok(package, config)
    config.execute_actions()
コード例 #37
0
ファイル: config.py プロジェクト: faassen/crom
def configure(package):
    config = ConfigurationMachine()
    grok(package, config)
    config.execute_actions()
コード例 #38
0
class MetaDirectivesTests(unittest.TestCase):
    def setUp(self):
        self.context = ConfigurationMachine()
        registerCommonDirectives(self.context)

        xmlconfig.file('meta.zcml', collective.transmogrifier,
                       context=self.context)

    def tearDown(self):
        configuration_registry.clear()
        cleanup.cleanUp()

    def testEmptyZCML(self):
        xmlconfig.string('''\
<configure xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier">
</configure>''', context=self.context)
        self.context.execute_actions()
        self.assertEqual(configuration_registry.listConfigurationIds(), ())

    def testConfigZCML(self):
        xmlconfig.string('''\
<configure
    xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier"
    i18n_domain="collective.transmogrifier">
<transmogrifier:registerConfig
    name="collective.transmogrifier.tests.configname"
    title="config title"
    description="config description"
    configuration="filename.cfg"
    />
</configure>''', context=self.context)
        self.context.execute_actions()
        self.assertEqual(configuration_registry.listConfigurationIds(),
                         (u'collective.transmogrifier.tests.configname',))
        self.assertEqual(
            configuration_registry.getConfiguration(
                 u'collective.transmogrifier.tests.configname'),
            dict(id=u'collective.transmogrifier.tests.configname',
                 title=u'config title',
                 description=u'config description',
                 configuration=os.path.join(os.getcwd(), 'filename.cfg')))

    def testConfigZCMLDefaults(self):
        xmlconfig.string('''\
<configure
    xmlns:transmogrifier="http://namespaces.plone.org/transmogrifier"
    i18n_domain="collective.transmogrifier">
<transmogrifier:registerConfig
    name="collective.transmogrifier.tests.configname"
    configuration="filename.cfg"
    />
</configure>''', context=self.context)
        self.context.execute_actions()
        self.assertEqual(configuration_registry.listConfigurationIds(),
                         (u'collective.transmogrifier.tests.configname',))
        self.assertEqual(
            configuration_registry.getConfiguration(
                u'collective.transmogrifier.tests.configname'),
            dict(id=u'collective.transmogrifier.tests.configname',
                 title=u'Pipeline configuration '
                       u"'collective.transmogrifier.tests.configname'",
                 description=u'',
                 configuration=os.path.join(os.getcwd(), 'filename.cfg')))
コード例 #39
0
    def onDiscovery(self, theme, settings, dependenciesSettings):
        res = queryResourceDirectory(THEME_RESOURCE_NAME, theme)
        if res is None:
            return

        directoryName = 'views'
        if 'directory' in settings:
            directoryName = settings['directory']

        if res.isDirectory(directoryName):
            viewsDir = res[directoryName]

            layer = getattr(schemata, theme, None)

            if 'layer' in settings:
                layerName = settings['layer']

                try:
                    layer = resolve(layerName)
                except (ImportError, AttributeError,):
                    logger.warn("Could not import %s" % layerName)
                    return

            viewConfig = SafeConfigParser()

            if viewsDir.isFile(VIEW_CONFIG_FILENAME):
                fp = viewsDir.openFile(VIEW_CONFIG_FILENAME)
                try:
                    viewConfig.readfp(fp)
                finally:
                    try:
                        fp.close()
                    except AttributeError:
                        pass

            views = []
            configurationMachine = ConfigurationMachine()
            path = viewsDir.directory

            for filename in os.listdir(path):
                if not filename.lower().endswith(EXTENSION):
                    continue

                name = viewName = filename[:-3]
                permission = 'zope2.View'
                for_ = Interface
                class_ = None
                template = os.path.join(path, filename)
                menu = {}

                # Read override options from views.cfg if applicable
                if viewConfig.has_section(name):

                    if viewConfig.has_option(name, 'name'):
                        viewName = viewConfig.get(name, 'name')

                    if viewConfig.has_option(name, 'permission'):
                        permission = viewConfig.get(name, 'permission')

                    if viewConfig.has_option(name, 'for'):
                        forStr = viewConfig.get(name, 'for')
                        if forStr != "*":
                            for_ = resolve(forStr)

                    if viewConfig.has_option(name, 'class'):
                        class_ = resolve(viewConfig.get(name, 'class'))

                    if viewConfig.has_option(name, 'menu'):
                        menu = dict(title=viewConfig.get(name, 'menu'),
                                    menu=getattr(
                                        zope.browsermenu.metaconfigure.menus,
                                        "plone_displayviews"
                                        ),
                                )

                Products.Five.browser.metaconfigure.page(
                        configurationMachine,
                        name=viewName,
                        permission=permission,
                        for_=for_,
                        layer=layer,
                        template=template,
                        class_=class_,
                        **menu
                    )

                views.append(name)

            if len(views) > 0:
                configurationMachine.execute_actions()

            self.registered[theme] = views