Ejemplo n.º 1
0
def get_config_loader() -> ConfigLoader:
    """
    Get the config loader with all extensions

    :return: The fully extended config loader
    """

    # Patch the parser because otherwise it will reject the example section in the schema

    # Construct the paths to all necessary files
    schema_filename = os.path.abspath(os.path.join(os.path.dirname(__file__), "config_schema.xml"))

    # Patch the parser if we have an old version of ZConfig
    # noinspection PyProtectedMember
    if 'schema' not in BaseParser._allowed_parents['example']:
        # noinspection PyProtectedMember
        BaseParser._allowed_parents['example'] += ['schema', 'sectiontype']

        # Add some properties
        ZConfig.info.SchemaType.example = None
        ZConfig.info.SectionType.example = None

        # Patch a method by saving the old method and replacing the original with a patched version
        ZConfig.info.oldCreateDerivedSchema = ZConfig.info.createDerivedSchema

        # noinspection PyUnresolvedReferences,PyPep8Naming
        def patchedCreateDerivedSchema(base: ZConfig.info.SchemaType) -> ZConfig.info.SchemaType:
            """
            Also copy the example section.

            :param base: The original
            :return: The copy
            """
            new = ZConfig.info.oldCreateDerivedSchema(base)
            new.example = base.example
            return new

        ZConfig.info.createDerivedSchema = patchedCreateDerivedSchema

    # Load the schema
    schema_loader = SchemaLoader()
    schema = schema_loader.loadURL(url=schema_filename)

    # Build the config loader based on the schema, extended with the schemas of option handlers
    config_loader = ConfigLoader(schema=schema)

    # Iterate over all server extensions
    for extension_name, extension in server_extension_registry.items():
        # Option handlers that refer to packages contain components
        if inspect.ismodule(extension) and hasattr(extension, '__path__'):
            # It's a package! Try to import
            try:
                config_loader.importSchemaComponent(extension.__name__)
                logger.debug("Configuration extension {} loaded".format(extension_name))
            except SchemaResourceError:
                # Component missing, assume it's a package without a config component
                pass

    return config_loader
Ejemplo n.º 2
0
def loadSchema(filepath, registry=fssRegistry, overwrite=False):
    """Sets up fssSchema
    @param filepath: path to schema xml file
    @param registry: ZConfig.datatypes.Registry
    @param overwrite: True to change fss
    """

    global fssSchema
    if fssSchema is not None and not overwrite:
        raise RuntimeError, 'Schema already loaded'
    schemaLoader = SchemaLoader(registry=registry)
    fssSchema = schemaLoader.loadURL(filepath)
    return fssSchema
Ejemplo n.º 3
0
def loadSchema(file, registry=atctRegistry, overwrite=False):
    """Loads a schema file
    
    * file
      A path to a file
    * registry
      A ZConfig datatypes registry instance
    * overwrite
      Overwriting the existing global schema is not possible unless overwrite
      is set to true. Useful only for unit testing.
    """
    global atctSchema
    if atctSchema is not None and not overwrite:
        raise RuntimeError, 'Schema is already loaded'
    schemaLoader = SchemaLoader(registry=registry)
    atctSchema = schemaLoader.loadURL(file)
    return atctSchema
Ejemplo n.º 4
0
def loadSchema(file, registry=Registry(), overwrite=False):
    """Loads a schema file
    
    * file
      A path to a file
    * registry
      A ZConfig datatypes registry instance
    * overwrite
      Overwriting the existing global schema is not possible unless overwrite
      is set to true. Useful only for unit testing.
    """
    global coreblog2Schema
    if coreblog2Schema is not None and not overwrite:
        raise RuntimeError, 'Schema is already loaded'
    schemaLoader = SchemaLoader(registry=registry)
    coreblog2Schema = schemaLoader.loadURL(file)
    return coreblog2Schema