Exemplo n.º 1
0
class DataStore(ResourceInfo):
    resource_type = "dataStore"
    save_method = "PUT"

    def __init__(self, catalog, workspace, name):
        super(DataStore, self).__init__()

        assert isinstance(workspace, Workspace)
        assert isinstance(name, basestring)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
            ["workspaces", self.workspace.name, "datastores", self.name + ".xml"])

    enabled = xml_property("enabled", lambda x: x.text == "true")
    name = xml_property("name")
    connection_parameters = xml_property("connectionParameters", key_value_pairs)

    writers = dict(enabled = write_bool("enabled"),
                   name = write_string("name"),
                   connectionParameters = write_dict("connectionParameters"))


    def get_resources(self):
        res_url = url(self.catalog.service_url,
            ["workspaces", self.workspace.name, "datastores", self.name, "featuretypes.xml"])
        xml = self.catalog.get_xml(res_url)
        def ft_from_node(node):
            return featuretype_from_index(self.catalog, self.workspace, self, node)

        return [ft_from_node(node) for node in xml.findall("featureType")]
Exemplo n.º 2
0
class LayerGroup(ResourceInfo):
    """
    Represents a layer group in geoserver
    """

    resource_type = "layerGroup"
    save_method = "PUT"

    def __init__(self, catalog, name):
        super(LayerGroup, self).__init__()

        assert isinstance(name, basestring)

        self.catalog = catalog
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url, ["layergroups", self.name + ".xml"])

    styles = xml_property("styles", _style_list)
    layers = xml_property("layers", _layer_list)
    bounds = xml_property("bounds", bbox)

    writers = dict(
              name = write_string("name"),
              styles = _write_styles,
              layers = _write_layers,
              bounds = write_bbox("bounds")
            )

    def __str__(self):
        return "<LayerGroup %s>" % self.name

    __repr__ = __str__
Exemplo n.º 3
0
class LayerGroup(ResourceInfo):
    """Represents a layer group in geoserver.
    """

    resource_type = 'layerGroup'
    save_method = 'PUT'

    def __init__(self, catalog, name):
        super(LayerGroup, self).__init__()

        assert isinstance(name, basestring)

        self.catalog = catalog
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
                   ['layergroups', self.name + '.xml'])

    styles = xml_property('styles', _style_list)
    layers = xml_property('layers', _layer_list)
    bounds = xml_property('bounds', bbox)

    writers = dict(name=write_string('name'),
                   styles=_write_styles,
                   layers=_write_layers,
                   bounds=write_bbox('bounds'))

    def __str__(self):
        return '<LayerGroup %s>' % self.name

    __repr__ = __str__
Exemplo n.º 4
0
class FeatureType(ResourceInfo):

    resource_type = 'featureType'
    save_method = 'PUT'

    def __init__(self, catalog, workspace, store, name):
        super(FeatureType, self).__init__()

        assert isinstance(store, ResourceInfo)
        assert isinstance(name, basestring)

        self.catalog = catalog
        self.workspace = workspace
        self.store = store
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url, [
            'workspaces',
            self.workspace.name,
            'datastores',
            self.store.name,
            'featuretypes',
            self.name + '.xml',
        ])

    title = xml_property('title')
    abstract = xml_property('abstract')
    enabled = xml_property('enabled')
    native_bbox = xml_property('nativeBoundingBox', bbox)
    latlon_bbox = xml_property('latLonBoundingBox', bbox)
    projection = xml_property('srs')
    projection_policy = xml_property('projectionPolicy')
    keywords = xml_property('keywords', string_list)
    attributes = xml_property('attributes', attribute_list)
    metadata_links = xml_property('metadataLinks', metadata_link_list)

    writers = dict(
        title=write_string('title'),
        abstract=write_string('abstract'),
        enabled=write_bool('enabled'),
        nativeBoundingBox=write_bbox('nativeBoundingBox'),
        latLonBoundingBox=write_bbox('latLonBoundingBox'),
        srs=write_string('srs'),
        projectionPolicy=write_string('projectionPolicy'),
        keywords=write_string_list('keywords'),
        metadataLinks=write_metadata_link_list('metadataLinks'),
    )
Exemplo n.º 5
0
class Workspace(ResourceInfo):

    resource_type = 'workspace'

    def __init__(self, catalog, name):
        super(Workspace, self).__init__()
        self.catalog = catalog
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
                   ['workspaces', self.name + '.xml'])

    @property
    def coveragestore_url(self):
        return url(self.catalog.service_url,
                   ['workspaces', self.name, 'coveragestores.xml'])

    @property
    def datastore_url(self):
        return url(self.catalog.service_url,
                   ['workspaces', self.name, 'datastores.xml'])

    enabled = xml_property('enabled', lambda x: x.lower() == 'true')
    writers = dict(enabled=write_bool('enabled'))

    def __repr__(self):
        return '%s @ %s' % (self.name, self.href)
Exemplo n.º 6
0
class Workspace(ResourceInfo):
    resource_type = "workspace"

    def __init__(self, catalog, name):
        super(Workspace, self).__init__()
        self.catalog = catalog
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
                   ["workspaces", self.name + ".xml"])

    @property
    def coveragestore_url(self):
        return url(self.catalog.service_url,
                   ["workspaces", self.name, "coveragestores.xml"])

    @property
    def datastore_url(self):
        return url(self.catalog.service_url,
                   ["workspaces", self.name, "datastores.xml"])

    enabled = xml_property("enabled", lambda x: x.lower() == 'true')
    writers = dict(enabled=write_bool("enabled"))

    def __repr__(self):
        return "%s @ %s" % (self.name, self.href)
Exemplo n.º 7
0
class CoverageStore(ResourceInfo):

    resource_type = 'coverageStore'
    save_method = 'PUT'

    def __init__(self, catalog, workspace, name):
        super(CoverageStore, self).__init__()

        assert isinstance(workspace, Workspace)
        assert isinstance(name, basestring)

        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url, [
            'workspaces', self.workspace.name, 'coveragestores',
            self.name + '.xml'
        ])

    enabled = xml_property('enabled', lambda x: x.text == 'true')
    name = xml_property('name')
    url = xml_property('url')
    type = xml_property('type')

    writers = dict(enabled=write_bool('enabled'),
                   name=write_string('name'),
                   url=write_string('url'),
                   type=write_string('type'))

    def get_resources(self):
        res_url = url(self.catalog.service_url, [
            'workspaces', self.workspace.name, 'coveragestores', self.name,
            'coverages.xml'
        ])

        xml = self.catalog.get_xml(res_url)

        def cov_from_node(node):
            return coverage_from_index(self.catalog, self.workspace, self,
                                       node)

        return [cov_from_node(node) for node in xml.findall('coverage')]
Exemplo n.º 8
0
class FeatureType(ResourceInfo):
    resource_type = "featureType"
    save_method = "PUT"

    def __init__(self, catalog, workspace, store, name):
        super(FeatureType, self).__init__()

        assert isinstance(store, ResourceInfo)
        assert isinstance(name, basestring)

        self.catalog = catalog
        self.workspace = workspace
        self.store = store
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
            ["workspaces", self.workspace.name,
             "datastores", self.store.name,
             "featuretypes", self.name + ".xml"])

    title = xml_property("title")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    native_bbox = xml_property("nativeBoundingBox", bbox)
    latlon_bbox = xml_property("latLonBoundingBox", bbox)
    projection = xml_property("srs")
    projection_policy = xml_property("projectionPolicy")
    keywords = xml_property("keywords", string_list)
    attributes = xml_property("attributes", attribute_list)
    metadata_links = xml_property("metadataLinks", metadata_link_list)

    writers = dict(
                title = write_string("title"),
                abstract = write_string("abstract"),
                enabled = write_bool("enabled"),
                nativeBoundingBox = write_bbox("nativeBoundingBox"),
                latLonBoundingBox = write_bbox("latLonBoundingBox"),
                srs = write_string("srs"),
                projectionPolicy = write_string("projectionPolicy"),
                keywords = write_string_list("keywords"),
                metadataLinks = write_metadata_link_list("metadataLinks")
            )
Exemplo n.º 9
0
class DataStore(ResourceInfo):

    resource_type = 'dataStore'
    save_method = 'PUT'

    def __init__(self, catalog, workspace, name):
        super(DataStore, self).__init__()

        assert isinstance(workspace, Workspace)
        assert isinstance(name, basestring)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url, [
            'workspaces', self.workspace.name, 'datastores', self.name + '.xml'
        ])

    enabled = xml_property('enabled', lambda x: x.text == 'true')
    name = xml_property('name')
    connection_parameters = xml_property('connectionParameters',
                                         key_value_pairs)

    writers = dict(enabled=write_bool('enabled'),
                   name=write_string('name'),
                   connectionParameters=write_dict('connectionParameters'))

    def get_resources(self):
        res_url = url(self.catalog.service_url, [
            'workspaces', self.workspace.name, 'datastores', self.name,
            'featuretypes.xml'
        ])
        xml = self.catalog.get_xml(res_url)

        def ft_from_node(node):
            return featuretype_from_index(self.catalog, self.workspace, self,
                                          node)

        return [ft_from_node(node) for node in xml.findall('featureType')]
Exemplo n.º 10
0
class CoverageStore(ResourceInfo):
    resource_type = 'coverageStore'
    save_method = "PUT"

    def __init__(self, catalog, workspace, name):
        super(CoverageStore, self).__init__()

        assert isinstance(workspace, Workspace)
        assert isinstance(name, basestring)

        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
            ["workspaces", self.workspace.name, "coveragestores", self.name + ".xml"])

    enabled = xml_property("enabled", lambda x: x.text == "true")
    name = xml_property("name")
    url = xml_property("url")
    type = xml_property("type")

    writers = dict(enabled = write_bool("enabled"),
                   name = write_string("name"),
                   url = write_string("url"),
                   type = write_string("type"))


    def get_resources(self):
        res_url = url(self.catalog.service_url,
            ["workspaces", self.workspace.name, "coveragestores", self.name, "coverages.xml"])

        xml = self.catalog.get_xml(res_url)

        def cov_from_node(node):
            return coverage_from_index(self.catalog, self.workspace, self, node)

        return [cov_from_node(node) for node in xml.findall("coverage")]
Exemplo n.º 11
0
class Style(ResourceInfo):
    def __init__(self, catalog, name):
        super(Style, self).__init__()
        assert isinstance(name, basestring)

        self.catalog = catalog
        self.name = name
        self._sld_dom = None

    @property
    def href(self):
        return url(self.catalog.service_url, ["styles", self.name + ".xml"])

    def body_href(self):
        return url(self.catalog.service_url, ["styles", self.name + ".sld"])

    filename = xml_property("filename")

    def _get_sld_dom(self):
        if self._sld_dom is None:
            self._sld_dom = self.catalog.get_xml(self.body_href())
        return self._sld_dom

    @property
    def sld_title(self):
        user_style = self._get_sld_dom().find(
            "{http://www.opengis.net/sld}NamedLayer/{http://www.opengis.net/sld}UserStyle"
        )
        title_node = user_style.find("{http://www.opengis.net/sld}Title")
        return title_node.text if title_node is not None else None

    @property
    def sld_name(self):
        user_style = self._get_sld_dom().find(
            "{http://www.opengis.net/sld}NamedLayer/{http://www.opengis.net/sld}UserStyle"
        )
        name_node = user_style.find("{http://www.opengis.net/sld}Name")
        return name_node.text if name_node is not None else None

    @property
    def sld_body(self):
        content = self.catalog.http.request(self.body_href())[1]
        return content

    def update_body(self, body):
        headers = {"Content-Type": "application/vnd.ogc.sld+xml"}
        self.catalog.http.request(self.body_href(), "PUT", body, headers)
Exemplo n.º 12
0
class Layer(ResourceInfo):
    def __init__(self, catalog, name):
        super(Layer, self).__init__()
        self.catalog = catalog
        self.name = name

    resource_type = "layer"
    save_method = "PUT"

    @property
    def href(self):
        return url(self.catalog.service_url, ["layers", self.name + ".xml"])

    @property
    def resource(self):
        if self.dom is None:
            self.fetch()
        name = self.dom.find("resource/name").text
        return self.catalog.get_resource(name)

    def _get_default_style(self):
        if 'default_style' in self.dirty:
            return self.dirty['default_style']
        if self.dom is None:
            self.fetch()
        name = self.dom.find("defaultStyle/name")
        # aborted data uploads can result in no default style
        if name is not None:
            return self.catalog.get_style(name.text)
        else:
            return None

    def _set_default_style(self, style):
        if isinstance(style, Style):
            style = style.name
        self.dirty["default_style"] = style

    def _get_alternate_styles(self):
        if "alternate_styles" in self.dirty:
            return self.dirty["alternate_styles"]
        if self.dom is None:
            self.fetch()
        styles = self.dom.findall("styles/style/name")
        return [Style(self.catalog, s.text) for s in styles]

    def _set_alternate_styles(self, styles):
        self.dirty["alternate_styles"] = styles

    default_style = property(_get_default_style, _set_default_style)
    styles = property(_get_alternate_styles, _set_alternate_styles)

    attribution_object = xml_property("attribution", _read_attribution)
    enabled = xml_property("enabled", lambda x: x.text == "true")

    def _get_attr_text(self):
        return self.attribution_object.title

    def _set_attr_text(self, text):
        self.dirty["attribution"] = _attribution(
                    text,
                    self.attribution_object.width,
                    self.attribution_object.height
                    )
        assert self.attribution_object.title == text

    attribution = property(_get_attr_text, _set_attr_text)

    writers = dict(
            attribution = _write_attribution,
            enabled = write_bool("enabled"),
            default_style = _write_default_style,
            alternate_styles = _write_alternate_styles
            )
Exemplo n.º 13
0
class Coverage(ResourceInfo):
    def __init__(self, catalog, workspace, store, name):
        super(Coverage, self).__init__()
        self.catalog = catalog
        self.workspace = workspace
        self.store = store
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url,
            ["workspaces", self.workspace.name,
             "coveragestores", self.store.name,
             "coverages", self.name + ".xml"])

    resource_type = "coverage"
    save_method = "PUT"

    title = xml_property("title")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    native_bbox = xml_property("nativeBoundingBox", bbox)
    latlon_bbox = xml_property("latLonBoundingBox", bbox)
    projection = xml_property("srs")
    projection_policy = xml_property("projectionPolicy")
    keywords = xml_property("keywords", string_list)
    request_srs_list = xml_property("requestSRS", string_list)
    response_srs_list = xml_property("responseSRS", string_list)
    supported_formats = xml_property("supportedFormats", string_list)
    metadata_links = xml_property("metadataLinks", metadata_link_list)

    writers = dict(
                title = write_string("title"),
                abstract = write_string("abstract"),
                enabled = write_bool("enabled"),
                nativeBoundingBox = write_bbox("nativeBoundingBox"),
                latLonBoundingBox = write_bbox("latLonBoundingBox"),
                srs = write_string("srs"),
                projection_policy = write_string("projectionPolicy"),
                keywords = write_string_list("keywords"),
                metadataLinks = write_metadata_link_list("metadataLinks"),
                requestSRS = write_string_list("requestSRS"),
                responseSRS = write_string_list("responseSRS"),
                supportedFormats = write_string_list("supportedFormats")
            )
Exemplo n.º 14
0
class Coverage(ResourceInfo):
    def __init__(self, catalog, workspace, store, name):
        super(Coverage, self).__init__()
        self.catalog = catalog
        self.workspace = workspace
        self.store = store
        self.name = name

    @property
    def href(self):
        return url(self.catalog.service_url, [
            'workspaces',
            self.workspace.name,
            'coveragestores',
            self.store.name,
            'coverages',
            self.name + '.xml',
        ])

    resource_type = 'coverage'
    save_method = 'PUT'

    title = xml_property('title')
    abstract = xml_property('abstract')
    enabled = xml_property('enabled')
    native_bbox = xml_property('nativeBoundingBox', bbox)
    latlon_bbox = xml_property('latLonBoundingBox', bbox)
    projection = xml_property('srs')
    projection_policy = xml_property('projectionPolicy')
    keywords = xml_property('keywords', string_list)
    request_srs_list = xml_property('requestSRS', string_list)
    response_srs_list = xml_property('responseSRS', string_list)
    supported_formats = xml_property('supportedFormats', string_list)
    metadata_links = xml_property('metadataLinks', metadata_link_list)

    writers = dict(
        title=write_string('title'),
        abstract=write_string('abstract'),
        enabled=write_bool('enabled'),
        nativeBoundingBox=write_bbox('nativeBoundingBox'),
        latLonBoundingBox=write_bbox('latLonBoundingBox'),
        srs=write_string('srs'),
        projection_policy=write_string('projectionPolicy'),
        keywords=write_string_list('keywords'),
        metadataLinks=write_metadata_link_list('metadataLinks'),
        requestSRS=write_string_list('requestSRS'),
        responseSRS=write_string_list('responseSRS'),
        supportedFormats=write_string_list('supportedFormats'),
    )