Beispiel #1
0
    def _handle_file(self, filename, config):
        root = etree.parse(filename)

        start_revision = root.findtext(ns_cfg("startRevision"))
        end_revision = root.findtext(ns_cfg("endRevision"))

        remove_layers_elems = root.xpath(
            "cfg:removeConfiguration/cfg:browseLayers",
            namespaces={"cfg": ns_cfg.uri})
        add_layers_elems = root.xpath("cfg:addConfiguration/cfg:browseLayers",
                                      namespaces={"cfg": ns_cfg.uri})

        add_layers = []
        for layers_elem in add_layers_elems:
            add_layers.extend(decode_browse_layers(layers_elem))

        remove_layers = []
        for layers_elem in remove_layers_elems:
            remove_layers.extend(decode_browse_layers(layers_elem))

        # get the mapcache config xml file path to make it transaction safe
        mapcache_config = get_mapcache_seed_config(config)
        mapcache_xml_filename = mapcache_config["config_file"]

        # transaction safety here
        with FileTransaction((mapcache_xml_filename, ), copy=True):
            with transaction.commit_on_success():
                with transaction.commit_on_success(using="mapcache"):
                    for browse_layer in add_layers:
                        if models.BrowseLayer.objects.filter(
                                id=browse_layer.id).exists():
                            update_browse_layer(browse_layer, config)
                        else:
                            add_browse_layer(browse_layer, config)

                    for browse_layer in remove_layers:
                        delete_browse_layer(browse_layer, config=config)

        # set the new revision
        config = config or get_ngeo_config()

        if not config.has_section("config"):
            config.add_section("config")

        revision = int(safe_get(config, "config", "revision", 0))
        config.set("config", "revision", int(end_revision))

        write_ngeo_config()
Beispiel #2
0
    def _handle_file(self, filename, config):
        root = etree.parse(filename)

        start_revision = root.findtext(ns_cfg("startRevision"))
        end_revision = root.findtext(ns_cfg("endRevision"))

        remove_layers_elems = root.xpath("cfg:removeConfiguration/cfg:browseLayers", namespaces={"cfg": ns_cfg.uri})
        add_layers_elems = root.xpath("cfg:addConfiguration/cfg:browseLayers", namespaces={"cfg": ns_cfg.uri})

        add_layers = []
        for layers_elem in add_layers_elems:
            add_layers.extend(decode_browse_layers(layers_elem))

        remove_layers = []
        for layers_elem in remove_layers_elems:
            remove_layers.extend(decode_browse_layers(layers_elem))

        # get the mapcache config xml file path to make it transaction safe
        mapcache_config = get_mapcache_seed_config(config)
        mapcache_xml_filename = mapcache_config["config_file"]

        # transaction safety here
        with FileTransaction((mapcache_xml_filename,), copy=True):
            with transaction.commit_on_success():
                with transaction.commit_on_success(using="mapcache"):
                    for browse_layer in add_layers:
                        if models.BrowseLayer.objects.filter(id=browse_layer.id).exists():
                            update_browse_layer(browse_layer, config)
                        else:
                            add_browse_layer(browse_layer, config)

                    for browse_layer in remove_layers:
                        delete_browse_layer(browse_layer, config=config)

        # set the new revision
        config = config or get_ngeo_config()

        if not config.has_section("config"):
            config.add_section("config")

        revision = int(safe_get(config, "config", "revision", 0))
        config.set("config", "revision", int(end_revision))

        write_ngeo_config()
Beispiel #3
0
    def _handle_file(self, filename, mode, config):
        browse_layers = decode_browse_layers(etree.parse(filename))

        for browse_layer in browse_layers:
            if mode == "add":
                add_browse_layer(browse_layer, config)

            elif mode == "update":
                update_browse_layer(browse_layer, config)

            elif mode == "remove":
                delete_browse_layer(browse_layer, config)
Beispiel #4
0
def config(request):
    try:
        status = get_status()
        config = get_ngeo_config()

        if request.method not in ("PUT", "POST"):
            raise Exception("Invalid request method '%s'." % request.method)

        if request.method == "POST":
            # "setting" new configuration, which means removing the previous one.
            action = "set"
        else:
            action = "update"

        root = etree.parse(request)

        start_revision = root.findtext(ns_cfg("startRevision"))
        end_revision = root.findtext(ns_cfg("endRevision"))

        # TODO: check current and last revision

        remove_layers_elems = root.xpath("cfg:removeConfiguration/cfg:browseLayers", namespaces={"cfg": ns_cfg.uri})
        add_layers_elems = root.xpath("cfg:addConfiguration/cfg:browseLayers", namespaces={"cfg": ns_cfg.uri})

        add_layers = []
        for layers_elem in add_layers_elems:
            add_layers.extend(decode_browse_layers(layers_elem))

        remove_layers = []
        for layers_elem in remove_layers_elems:
            remove_layers.extend(decode_browse_layers(layers_elem))

        # get the mapcache config xml file path to make it transaction safe

        mapcache_config = get_mapcache_seed_config(config)
        mapcache_xml_filename = mapcache_config["config_file"]

        # transaction safety here
        with FileTransaction((mapcache_xml_filename,), copy=True):
            with transaction.commit_on_success():
                with transaction.commit_on_success(using="mapcache"):
                    for browse_layer in add_layers:
                        if models.BrowseLayer.objects.filter(id=browse_layer.id).exists():
                            update_browse_layer(browse_layer, config)
                        else:
                            add_browse_layer(browse_layer, config)

                    for browse_layer in remove_layers:
                        delete_browse_layer(browse_layer, config)

        # set the new revision
        config = get_ngeo_config()

        if not config.has_section("config"):
            config.add_section("config")

        revision = int(safe_get(config, "config", "revision", 0))
        config.set("config", "revision", end_revision)

        write_ngeo_config()

        # return with the new revision
        return HttpResponse('<?xml version="1.0"?>\n'
            '<synchronizeConfigurationResponse>%s</synchronizeConfigurationResponse>'
            % end_revision
        )

    except Exception, e:
        logger.error("%s: %s" % (type(e).__name__, str(e)))
        logger.debug(traceback.format_exc())

        return HttpResponse(
            '<faultcode>ConfigurationError</faultcode>\n'
            '<faultstring>%s</faultstring>' % str(e), status=400
        )
Beispiel #5
0
def import_package(package_path, ignore_cache, config):
    with package.read(package_path) as p:
        browse_layer = decode_browse_layers(etree.parse(p.get_browse_layer()))[0]

        try:
            browse_layer_model = BrowseLayer.objects.get(
                browse_type=browse_layer.browse_type
            )
        except BrowseLayer.DoesNotExist:
            raise ImportException("The browse layer specified in the package "
                                  "does not exist on this server.")

        # check compliance of configuration of browse layers
        check_parameters = [
            "id",
            "browse_type",
            "grid",
            "r_band",
            "g_band",
            "b_band",
            "radiometric_interval_min",
            "radiometric_interval_max",
        ]
        for check_parameter in check_parameters:
            if getattr(browse_layer, check_parameter) != getattr(browse_layer_model, check_parameter):
                raise ImportException("The '%s' configuration of the browse "
                                      "layer specified in the package does not "
                                      "match the one of the browse layer on "
                                      "this server. %s %s" % (check_parameter, getattr(browse_layer, check_parameter), getattr(browse_layer_model, check_parameter)))

        crs = None
        if browse_layer.grid == "urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible":
            crs = "EPSG:3857"
        elif browse_layer.grid == "urn:ogc:def:wkss:OGC:1.0:GoogleCRS84Quad":
            crs = "EPSG:4326"

        import_cache_levels = []
        seed_cache_levels = []

        if not p.has_cache() or ignore_cache:
            seed_cache_levels.append((browse_layer_model.lowest_map_level,
                                      browse_layer_model.highest_map_level))
        else:
            if browse_layer_model.lowest_map_level < browse_layer.lowest_map_level:
                seed_cache_levels.append((browse_layer_model.lowest_map_level,
                                          browse_layer.lowest_map_level))

            if browse_layer_model.highest_map_level > browse_layer.highest_map_level:
                seed_cache_levels.append((browse_layer.highest_map_level,
                                          browse_layer_model.highest_map_level))

            import_cache_levels.append((max(browse_layer_model.lowest_map_level,
                                            browse_layer.lowest_map_level),
                                        min(browse_layer_model.highest_map_level,
                                            browse_layer.highest_map_level)))

        logger.debug("Importing cache levels %s" %import_cache_levels)
        logger.debug("Seeding cache levels %s" %seed_cache_levels)


        for browse_report_file in p.get_browse_reports():
            import_browse_report(p, browse_report_file, browse_layer_model, crs,
                                 seed_cache_levels, import_cache_levels, config)
Beispiel #6
0
def config(request):
    try:
        status = get_status()
        config = get_ngeo_config()

        if request.method not in ("PUT", "POST"):
            raise Exception("Invalid request method '%s'." % request.method)

        if request.method == "POST":
            # "setting" new configuration, which means removing the previous one.
            action = "set"
        else:
            action = "update"

        root = etree.parse(request)

        start_revision = root.findtext(ns_cfg("startRevision"))
        end_revision = root.findtext(ns_cfg("endRevision"))

        # TODO: check current and last revision

        remove_layers_elems = root.xpath(
            "cfg:removeConfiguration/cfg:browseLayers",
            namespaces={"cfg": ns_cfg.uri})
        add_layers_elems = root.xpath("cfg:addConfiguration/cfg:browseLayers",
                                      namespaces={"cfg": ns_cfg.uri})

        add_layers = []
        for layers_elem in add_layers_elems:
            add_layers.extend(decode_browse_layers(layers_elem))

        remove_layers = []
        for layers_elem in remove_layers_elems:
            remove_layers.extend(decode_browse_layers(layers_elem))

        # get the mapcache config xml file path to make it transaction safe

        mapcache_config = get_mapcache_seed_config(config)
        mapcache_xml_filename = mapcache_config["config_file"]

        # transaction safety here
        with FileTransaction((mapcache_xml_filename, ), copy=True):
            with transaction.commit_on_success():
                with transaction.commit_on_success(using="mapcache"):
                    for browse_layer in add_layers:
                        if models.BrowseLayer.objects.filter(
                                id=browse_layer.id).exists():
                            update_browse_layer(browse_layer, config)
                        else:
                            add_browse_layer(browse_layer, config)

                    for browse_layer in remove_layers:
                        delete_browse_layer(browse_layer, config=config)

        # set the new revision
        config = get_ngeo_config()

        if not config.has_section("config"):
            config.add_section("config")

        revision = int(safe_get(config, "config", "revision", 0))
        config.set("config", "revision", int(end_revision))

        write_ngeo_config()

        # return with the new revision
        return HttpResponse(
            '<?xml version="1.0"?>\n'
            '<synchronizeConfigurationResponse>%s</synchronizeConfigurationResponse>'
            % end_revision)

    except Exception, e:
        logger.error("%s: %s" % (type(e).__name__, str(e)))
        logger.debug(traceback.format_exc())

        return HttpResponse('<faultcode>ConfigurationError</faultcode>\n'
                            '<faultstring>%s</faultstring>' % str(e),
                            status=400)
Beispiel #7
0
def import_package(package_path, ignore_cache, config):
    with package.read(package_path) as p:
        browse_layer = decode_browse_layers(etree.parse(
            p.get_browse_layer()))[0]

        try:
            browse_layer_model = BrowseLayer.objects.get(
                browse_type=browse_layer.browse_type)
        except BrowseLayer.DoesNotExist:
            raise ImportException("The browse layer specified in the package "
                                  "does not exist on this server.")

        # check compliance of configuration of browse layers
        check_parameters = [
            "id",
            "browse_type",
            "grid",
            "r_band",
            "g_band",
            "b_band",
            "radiometric_interval_min",
            "radiometric_interval_max",
        ]
        for check_parameter in check_parameters:
            if getattr(browse_layer, check_parameter) != getattr(
                    browse_layer_model, check_parameter):
                raise ImportException(
                    "The '%s' configuration of the browse "
                    "layer specified in the package does not "
                    "match the one of the browse layer on "
                    "this server. %s %s" %
                    (check_parameter, getattr(browse_layer, check_parameter),
                     getattr(browse_layer_model, check_parameter)))

        crs = None
        if browse_layer.grid == "urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible":
            crs = "EPSG:3857"
        elif browse_layer.grid == "urn:ogc:def:wkss:OGC:1.0:GoogleCRS84Quad":
            crs = "EPSG:4326"

        import_cache_levels = []
        seed_cache_levels = []

        if not p.has_cache() or ignore_cache:
            seed_cache_levels.append((browse_layer_model.lowest_map_level,
                                      browse_layer_model.highest_map_level))
        else:
            if browse_layer_model.lowest_map_level < browse_layer.lowest_map_level:
                seed_cache_levels.append((browse_layer_model.lowest_map_level,
                                          browse_layer.lowest_map_level))

            if browse_layer_model.highest_map_level > browse_layer.highest_map_level:
                seed_cache_levels.append(
                    (browse_layer.highest_map_level,
                     browse_layer_model.highest_map_level))

            import_cache_levels.append(
                (max(browse_layer_model.lowest_map_level,
                     browse_layer.lowest_map_level),
                 min(browse_layer_model.highest_map_level,
                     browse_layer.highest_map_level)))

        logger.debug("Importing cache levels %s" % import_cache_levels)
        logger.debug("Seeding cache levels %s" % seed_cache_levels)

        for browse_report_file in p.get_browse_reports():
            import_browse_report(p, browse_report_file, browse_layer_model,
                                 crs, seed_cache_levels, import_cache_levels,
                                 config)