Пример #1
0
def registerTranslations(_context, directory):
    path = os.path.normpath(directory)
    domains = {}

    # Gettext has the domain-specific catalogs inside the language directory,
    # which is exactly the opposite as we need it. So create a dictionary that
    # reverses the nesting.
    for language in os.listdir(path):
        lc_messages_path = os.path.join(path, language, 'LC_MESSAGES')
        if os.path.isdir(lc_messages_path):
            for domain_file in os.listdir(lc_messages_path):
                if domain_file.endswith('.mo'):
                    domain_path = os.path.join(lc_messages_path, domain_file)
                    domain = domain_file[:-3]
                    if not domain in domains:
                        domains[domain] = {}
                    domains[domain][language] = domain_path

    # Now create TranslationDomain objects and add them as utilities
    for name, langs in domains.items():
        domain = TranslationDomain(name)

        for lang, file in langs.items():
            domain.addCatalog(GettextMessageCatalog(lang, name, file))

        # make sure we have a TEST catalog for each domain:
        domain.addCatalog(TestMessageCatalog(name))

        utility(_context, ITranslationDomain, domain, name=name)
Пример #2
0
def engine(_context, url, name='', echo=False, pool_recycle=-1, **kwargs):

    component = sqlalchemy.create_engine( url, echo=echo, pool_recycle=pool_recycle, **kwargs )

    utility( _context,
             provides = interfaces.IDatabaseEngine,
             component = component,
             permission = PublicPermission,
             name = name )
Пример #3
0
def tool(_context, interface, title, description=None,
         folder="tools", unique=False):
    name = interface.getName()
    permission = 'zope.ManageContent'
    tool = ToolConfiguration(interface, title, description, unique)

    ifaceDirective(_context, interface, IToolType)
    utility(_context, IToolConfiguration, tool,
            permission=permission, name=name)
Пример #4
0
def appengine(_context,app_id,host,username,password):
    auth_func = lambda:(username,password)
    remote_api_stub.ConfigureRemoteDatastore(app_id,'/content_mirror',auth_func,host)
    datastore = DataStore(db)
    utility(_context,
            provides=interfaces.IAppEngine,
            component=datastore,
            permission=PublicPermission,
            name='appengine'
           )
Пример #5
0
def engine(_context, url, name='', echo=False, pool_recycle=-1, **kwargs):

    component = sqlalchemy.create_engine(url,
                                         echo=echo,
                                         pool_recycle=pool_recycle,
                                         **kwargs)

    utility(_context,
            provides=interfaces.IDatabaseEngine,
            component=component,
            permission=PublicPermission,
            name=name)
Пример #6
0
def unauthenticatedPrincipal(_context, id, title, description=''):
    principal = principalregistry.UnauthenticatedPrincipal(
        id, title, description)
    _context.action(
        discriminator = 'unauthenticatedPrincipal',
        callable = principalregistry.principalRegistry.defineDefaultPrincipal,
        args = (id, title, description, principal) )
    utility(_context, interfaces.IUnauthenticatedPrincipal, principal)
    _context.action(
        discriminator = None,
        callable = _unauthenticatedPrincipal,
        args = (),
        )
Пример #7
0
def everybodyGroup(_context, id, title, description=''):
    principal = principalregistry.EverybodyGroup(
        id, title, description)
    utility(_context, interfaces.IEveryoneGroup, principal)
    _context.action(
        discriminator = None,
        callable = _everybodyGroup,
        args = (principal.id, ),
        )
    _context.action(
        discriminator = None,
        callable = principalregistry.principalRegistry.registerGroup,
        args = (principal, ),
        )
Пример #8
0
def authenticatedGroup(_context, id, title, description=''):
    principal = principalregistry.AuthenticatedGroup(
        id, title, description)
    utility(_context, interfaces.IAuthenticatedGroup, principal)
    _context.action(
        discriminator = None,
        callable = _authenticatedGroup,
        args = (principal.id, ),
        )
    _context.action(
        discriminator = None,
        callable = principalregistry.principalRegistry.registerGroup,
        args = (principal, ),
        )
Пример #9
0
def menuDirective(_context, id=None, class_=BrowserMenu, interface=None, title=u"", description=u""):
    """Registers a new browser menu."""
    if id is None and interface is None:
        raise ConfigurationError("You must specify the 'id' or 'interface' attribute.")

    if interface is None:
        interface = InterfaceClass(id, (), __doc__="Menu Item Type: %s" % id, __module__="zope.app.menus")
        # Add the menu item type to the `menus` module.
        # Note: We have to do this immediately, so that directives using the
        # MenuField can find the menu item type.
        setattr(menus, id, interface)
        path = "zope.app.menus." + id
    else:
        path = interface.__module__ + "." + interface.getName()

        # If an id was specified, make this menu available under this id.
        # Note that the menu will be still available under its path, since it
        # is an adapter, and the `MenuField` can resolve paths as well.
        if id is None:
            id = path
        else:
            # Make the interface available in the `zope.app.menus` module, so
            # that other directives can find the interface under the name
            # before the CA is setup.
            _context.action(
                discriminator=("browser", "MenuItemType", path),
                callable=provideInterface,
                args=(path, interface, IMenuItemType, _context.info),
            )
            setattr(menus, id, interface)

    # Register the layer interface as an interface
    _context.action(
        discriminator=("interface", path), callable=provideInterface, args=(path, interface), kw={"info": _context.info}
    )

    # Register the menu item type interface as an IMenuItemType
    _context.action(
        discriminator=("browser", "MenuItemType", id),
        callable=provideInterface,
        args=(id, interface, IMenuItemType, _context.info),
    )

    # Register the menu as a utility
    utility(_context, IBrowserMenu, class_(id, title, description), name=id)
Пример #10
0
def definePermission(_context, id, title, description=''):
    permission = Permission(id, title, description)
    utility(_context, IPermission, permission, name=id)
Пример #11
0
def rootModule(_context, module):
    """Register a new module as a root module for the class browser."""
    utility(_context, IAPIDocRootModule, RootModule(module), name=module)
Пример #12
0
def vocabulary(_context, name, factory, **kw):
    if kw:
        factory = FactoryKeywordPasser(factory, kw)
    directlyProvides(factory, IVocabularyFactory)
    utility(_context, IVocabularyFactory, factory, name=name)
Пример #13
0
def preferenceGroup(_context, id=None, schema=None,
                    title=u'', description=u'', category=False):
    if id is None:
        id = ''
    group = PreferenceGroup(id, schema, title, description, category)
    utility(_context, IPreferenceGroup, group, name=id)