예제 #1
0
def change_configuration(tree):
    config_elem = tree.find("configurationData/configuration")
    
    for element in config_elem:
        tag = element.tag
        print tag
        for configurator in CONFIGURATORS:
            if configurator.element_name == tag:
                break
        else:
            raise Exception("Invalid configuration element '%s' found." % tag)

        configurator.parse(element)

    write_ngeo_config()
예제 #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()
예제 #3
0
def change_configuration(tree):
    config_elem = tree.find("configurationData/configuration")

    if config_elem is None:
        raise Exception("Invalid configuration provided.")

    for element in config_elem:
        tag = element.tag
        for configurator in CONFIGURATORS:
            if configurator.element_name == tag:
                break
        else:
            raise Exception("Invalid configuration element '%s' found." % tag)

        configurator.parse(element)

    write_ngeo_config()
예제 #4
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()
예제 #5
0
파일: views.py 프로젝트: v-manip/ngeo-b
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
        )
예제 #6
0
파일: views.py 프로젝트: baloola/ngeo-b
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)