示例#1
0
def register_custom_types():
    """Extend TYPE_REGISTRY with the declarations from bungeni_custom/types.xml.
    This is called prior to loading of the workflows for these custom types.
    Returns (type_key, TI) for the newly created TI instance.
    """
    def parse_elem(type_elem):
        type_key = misc.xml_attr_str(type_elem, "name")
        workflow_key = misc.xml_attr_str(type_elem,
                                         "workflow",
                                         default=type_key)
        archetype_key = type_elem.tag  # !+archetype? move to types?
        return type_key, workflow_key, archetype_key

    def enabled_elems(elems):
        for elem in elems:
            if misc.xml_attr_bool(elem, "enabled", default=True):
                yield elem

    # load XML file
    etypes = etree.fromstring(misc.read_file(capi.get_path_for("types.xml")))
    # register enabled types - ignoring not enabled types
    from bungeni.alchemist import type_info
    for edoc in enabled_elems(etypes.iterchildren("doc")):
        type_key, ti = type_info.register_new_custom_type(*parse_elem(edoc))
    # group/member types
    for egroup in enabled_elems(etypes.iterchildren("group")):
        type_key, ti = type_info.register_new_custom_type(*parse_elem(egroup))
        for emember in enabled_elems(egroup.iterchildren("member")):
            type_key, ti = type_info.register_new_custom_type(
                *parse_elem(emember))
示例#2
0
def register_custom_types():
    """Extend TYPE_REGISTRY with the declarations from bungeni_custom/types.xml.
    This is called prior to loading of the workflows for these custom types.
    Returns (type_key, TI) for the newly created TI instance.
    """
        
    def parse_elem(type_elem):
        type_key = misc.xml_attr_str(type_elem, "name")
        workflow_key = misc.xml_attr_str(type_elem, "workflow", default=type_key)
        archetype_key = type_elem.tag # !+archetype? move to types?
        return type_key, workflow_key, archetype_key
    
    def enabled_elems(elems):
        for elem in elems:
            if misc.xml_attr_bool(elem, "enabled", default=True):
                yield elem
    
    # load XML file
    etypes = etree.fromstring(misc.read_file(capi.get_path_for("types.xml")))
    # register enabled types - ignoring not enabled types
    from bungeni.alchemist import type_info
    for edoc in enabled_elems(etypes.iterchildren("doc")):
        type_key, ti = type_info.register_new_custom_type(*parse_elem(edoc))
    # group/member types
    for egroup in enabled_elems(etypes.iterchildren("group")):
        type_key, ti = type_info.register_new_custom_type(*parse_elem(egroup))
        for emember in enabled_elems(egroup.iterchildren("member")):
            type_key, ti = type_info.register_new_custom_type(*parse_elem(emember))
示例#3
0
def validate_file_rng(name, file_path):
    """Load and validate XML file at file_patah, against named RNG schema."""
    xml_doc = etree.fromstring(misc.read_file(file_path))
    log.info("RNG %r SCHEMA validating file: %s", name, file_path)
    RNG[name].assertValid(xml_doc)  # raises etree.DocumentInvalid
    return xml_doc
示例#4
0
def validate_file_rng(name, file_path):
    """Load and validate XML file at file_patah, against named RNG schema."""
    xml_doc = etree.fromstring(misc.read_file(file_path))
    log.info("RNG %r SCHEMA validating file: %s", name, file_path)
    RNG[name].assertValid(xml_doc) # raises etree.DocumentInvalid
    return xml_doc