Beispiel #1
0
    def POST(self, map_name, l_name, format):
        data = get_data(name="style", mandatory=["resource"],
                        authorized=["name", "title", "abstract", "resource"])

        url = urlparse.urlparse(data["resource"]["href"])
        if url.path.startswith(web.ctx.homepath):
            path = url.path[len(web.ctx.homepath):]
        else:
            raise webapp.BadRequest(message="Resource href (%s) is not handled by MRA." % url.path)

        try:
            _, map_name, _, s_name = path.rsplit("/", 3)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

        s_name = s_name.rsplit(".", 1)[0]

        # Get the new style.
        mf = get_mapfile(map_name)

        try:
            style = open(tools.get_style_path(s_name)).read()
        except IOError, OSError:
            with webapp.mightNotFound("style", mapfile=map_name):
                style = mf.get_style_sld(s_name)
Beispiel #2
0
    def GET(self, map_name, s_name, format):
        mf = get_mapfile(map_name)

        if format == "sld":
            # We look for styles on disk and in the mapfiles.
            try:
                return open(tools.get_style_path(s_name)).read()
            except IOError, OSError:
                with webapp.mightNotFound("style", mapfile=map_name):
                    return mf.get_style_sld(s_name)
Beispiel #3
0
    def PUT(self, map_name, s_name, format):
        path = tools.get_style_path(s_name)
        try:
            os.remove(path)
        except OSError:
            mf = get_mapfile(map_name)
            if s_name in mf.iter_styles():
                raise webapp.NotImplemented(message="Updating manually added styles is not implemented.")
            else:
                raise webapp.NotFound("style '%s' not found in mapfile '%s'." % (s_name, map_name))

        data = web.data()
        with open(path, "w") as f:
            f.write(data)
Beispiel #4
0
    def DELETE(self, map_name, s_name, format):
        mf = get_mapfile(map_name)

        # OK check any(class.group == s_name for class in layer.iter_classes)
        layers_using = [layer.ms.name for layer in mf.iter_layers()
                        if any(clazz.ms.group == s_name for clazz in layer.iter_classes())]

        if layers_using:
            raise webapp.Forbidden(message="Can't remove style '%s' because it is beeing used by the folowing layers: %s."
                                   % (s_name, layers_using))

        path = tools.get_style_path(s_name)
        try:
            os.remove(path)
        except OSError:
            mf = get_mapfile(map_name)
            if s_name in mf.iter_styles():
                raise webapp.NotImplemented(message="Deleting manually added styles is not implemented.")
            else:
                raise webapp.NotFound("style '%s' not found in mapfile '%s'." % (s_name, map_name))