Beispiel #1
0
def register_settings(name, *nodes, **kw):
    title = kw.get('title', '')
    description = kw.get('description', '')
    validator = kw.get('validator', None)

    iname = name
    for ch in ('.', '-'):
        iname = iname.replace(ch, '_')

    category = InterfaceClass(
        'SettingsGroup:%s' % iname.upper(), (),
        __doc__='Settings group: %s' % name,
        __module__='ptah.config.settings')

    group = Group(name, title, description, category, *nodes)

    if validator is not None:
        if type(validator) not in (list, tuple):
            validator = validator,

        for v in validator:
            group.schema.validator.add(v)

    ac = Action(
        lambda config, group: config.get_cfg_storage(SETTINGS_GROUP_ID)\
            .update({group.name: group}),
        (group,),
        discriminator=(SETTINGS_GROUP_ID, name))

    info = DirectiveInfo()
    info.attach(ac)

    return group
Beispiel #2
0
def register_settings(name, *nodes, **kw):
    title = kw.get('title', '')
    description = kw.get('description', '')
    validator = kw.get('validator', None)

    iname = name
    for ch in ('.', '-'):
        iname = iname.replace(ch, '_')

    category = InterfaceClass(
        'SettingsGroup:%s'%iname.upper(), (),
        __doc__='Settings group: %s' %name,
        __module__='ptah.config.settings')

    if name in Settings:
        group = Settings[name]
    else:
        group = Group(name, Settings, title, description, category)

    Settings.register(group)

    if validator is not None:
        if type(validator) not in (list, tuple):
            validator = validator,

        for v in validator:
            group.schema.validator.add(v)

    info = DirectiveInfo()

    for node in nodes:
        if not isinstance(node, schema.SchemaNode):
            raise RuntimeError(
                "Node '%s' has to be instance of "
                "ptah.config.SchemaNode"%node.name)

        ac = Action(
            _register_settings_impl, (group, node),
            discriminator = ('ptah.config:setting', node.name, name))

        # mutate hash
        ac.hash = info.hash + (node.name,)

        info.attach(ac)

    return group