How to use the mapchete.errors.MapcheteConfigError function in mapchete

To help you get started, we’ve selected a few mapchete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ungarj / mapchete / mapchete / config.py View on Github external
DeprecationWarning(
                "use new config element 'zoom_levels' instead of 'process_zoom', "
                "'process_minzoom' and 'process_maxzoom'"
            )
        )
        if "process_zoom" in config:
            config["zoom_levels"] = config["process_zoom"]
        elif all([
            i in config for i in ["process_minzoom", "process_maxzoom"]
        ]):
            config["zoom_levels"] = dict(
                min=config["process_minzoom"],
                max=config["process_maxzoom"]
            )
        else:
            raise MapcheteConfigError("process zoom levels not provided in config")

    if "bounds" not in config:
        if "process_bounds" in config:
            warnings.warn(
                DeprecationWarning(
                    "'process_bounds' are deprecated and renamed to 'bounds'"
                )
            )
            config["bounds"] = config["process_bounds"]
        else:
            config["bounds"] = None

    if "input" not in config:
        if "input_files" in config:
            warnings.warn(
                DeprecationWarning("'input_files' are deprecated and renamed to 'input'")
github ungarj / mapchete / mapchete / config.py View on Github external
)
            config["bounds"] = config["process_bounds"]
        else:
            config["bounds"] = None

    if "input" not in config:
        if "input_files" in config:
            warnings.warn(
                DeprecationWarning("'input_files' are deprecated and renamed to 'input'")
            )
            config["input"] = config["input_files"]
        else:
            raise MapcheteConfigError("no 'input' found")

    elif "input_files" in config:
        raise MapcheteConfigError(
            "'input' and 'input_files' are not allowed at the same time")

    if "process_file" in config:
        warnings.warn(
            DeprecationWarning("'process_file' is deprecated and renamed to 'process'")
        )
        config["process"] = config.pop("process_file")

    return config
github ungarj / mapchete / mapchete / config.py View on Github external
def _map_to_new_config(config):
    try:
        validate_values(config, [("output", dict)])
    except Exception as e:
        raise MapcheteConfigError(e)

    if "type" in config["output"]:  # pragma: no cover
        warnings.warn(DeprecationWarning("'type' is deprecated and should be 'grid'"))
        if "grid" not in config["output"]:
            config["output"]["grid"] = config["output"].pop("type")

    if "pyramid" not in config:
        warnings.warn(
            DeprecationWarning("'pyramid' needs to be defined in root config element.")
        )
        config["pyramid"] = dict(
            grid=config["output"]["grid"],
            metatiling=config.get("metatiling", 1),
            pixelbuffer=config.get("pixelbuffer", 0))

    if "zoom_levels" not in config:
github ungarj / mapchete / mapchete / config.py View on Github external
raise MapcheteConfigError(
                "process zoom levels not provided in config")
    if "bounds" not in config:
        if "process_bounds" in config:
            warnings.warn(
                "'process_bounds' are deprecated and renamed to 'bounds'")
            config["bounds"] = config["process_bounds"]
        else:
            config["bounds"] = None
    if "input" not in config:
        if "input_files" in config:
            warnings.warn(
                "'input_files' are deprecated and renamed to 'input'")
            config["input"] = config["input_files"]
        else:
            raise MapcheteConfigError("no 'input' found")
    elif "input_files" in config:
        raise MapcheteConfigError(
            "'input' and 'input_files' are not allowed at the same time")
    if "process_file" in config:
        warnings.warn("'process_file' is deprecated and renamed to 'process'")
        config["process"] = config.pop("process_file")

    return config
github ungarj / mapchete / mapchete / config.py View on Github external
def _load_process_module(process_path=None, config_dir=None, run_compile=False):
    if process_path.endswith(".py"):
        abs_path = os.path.join(config_dir, process_path)
        if not os.path.isfile(abs_path):
            raise MapcheteConfigError("%s is not available" % abs_path)
        try:
            if run_compile:
                py_compile.compile(abs_path, doraise=True)
            module = imp.load_source(
                os.path.splitext(os.path.basename(abs_path))[0], abs_path
            )
            # configure process file logger
            add_module_logger(module.__name__)
        except py_compile.PyCompileError as e:
            raise MapcheteProcessSyntaxError(e)
        except ImportError as e:
            raise MapcheteProcessImportError(e)
    else:
        try:
            module = importlib.import_module(process_path)
        except ImportError as e:
github ungarj / mapchete / mapchete / config.py View on Github external
def get_zoom_levels(process_zoom_levels=None, init_zoom_levels=None):
    """Validate and return zoom levels."""
    process_zoom_levels = _validate_zooms(process_zoom_levels)
    if init_zoom_levels is None:
        return process_zoom_levels
    else:
        init_zoom_levels = _validate_zooms(init_zoom_levels)
        if not set(init_zoom_levels).issubset(set(process_zoom_levels)):
            raise MapcheteConfigError(
                "init zooms must be a subset of process zoom")
        return init_zoom_levels
github ungarj / mapchete / mapchete / config.py View on Github external
if "bounds" not in config:
        if "process_bounds" in config:
            warnings.warn(
                "'process_bounds' are deprecated and renamed to 'bounds'")
            config["bounds"] = config["process_bounds"]
        else:
            config["bounds"] = None
    if "input" not in config:
        if "input_files" in config:
            warnings.warn(
                "'input_files' are deprecated and renamed to 'input'")
            config["input"] = config["input_files"]
        else:
            raise MapcheteConfigError("no 'input' found")
    elif "input_files" in config:
        raise MapcheteConfigError(
            "'input' and 'input_files' are not allowed at the same time")
    if "process_file" in config:
        warnings.warn("'process_file' is deprecated and renamed to 'process'")
        config["process"] = config.pop("process_file")

    return config
github ungarj / mapchete / mapchete / config.py View on Github external
def _validate_zooms(zooms):
    """
    Return a list of zoom levels.

    Following inputs are converted:
    - int --> [int]
    - dict{min, max} --> range(min, max + 1)
    - [int] --> [int]
    - [int, int] --> range(smaller int, bigger int + 1)
    """
    if isinstance(zooms, dict):
        if any([a not in zooms for a in ["min", "max"]]):
            raise MapcheteConfigError("min and max zoom required")
        zmin = _validate_zoom(zooms["min"])
        zmax = _validate_zoom(zooms["max"])
        if zmin > zmax:
            raise MapcheteConfigError(
                "max zoom must not be smaller than min zoom")
        return list(range(zmin, zmax + 1))
    elif isinstance(zooms, list):
        if len(zooms) == 1:
            return zooms
        elif len(zooms) == 2:
            zmin, zmax = sorted([_validate_zoom(z) for z in zooms])
            return list(range(zmin, zmax + 1))
        else:
            raise MapcheteConfigError(
                "when providing zooms as list, just min and max are allowed")
    else:
github ungarj / mapchete / mapchete / config.py View on Github external
grid=self.output_pyramid.grid,
            pixelbuffer=self.output_pyramid.pixelbuffer,
            metatiling=self.output_pyramid.metatiling,
            delimiters=self._delimiters,
            mode=self.mode
        )
        if "path" in output_params:
            output_params.update(
                path=absolute_path(path=output_params["path"], base_dir=self.config_dir)
            )

        if "format" not in output_params:
            raise MapcheteConfigError("output format not specified")

        if output_params["format"] not in available_output_formats():
            raise MapcheteConfigError(
                "format %s not available in %s" % (
                    output_params["format"], str(available_output_formats())
                )
            )
        return output_params