예제 #1
0
 def __init__(self, catalog, name, workspace=None):
     super(LayerGroup, self).__init__()
     assert isinstance(name, str)
     self.catalog = catalog
     self.name = name
     self.workspace = workspace
     # the XML format changed in 2.3.x - the element listing all the layers
     # and the entries themselves have changed
     if self.catalog.gsversion() == "2.2.x":
         parent, element, attributes = "layers", "layer", None
     else:
         parent = "publishables"
         element = "published"
         attributes = {'type': 'layer'}
     self._layer_parent = parent
     self._layer_element = element
     self._layer_attributes = attributes
     self.writers = {
         'name': write_string("name"),
         'styles': _write_styles,
         'layers':
         lambda b, l: _write_layers(b, l, parent, element, attributes),
         'bounds': write_bbox("bounds"),
         'workspace': write_string("workspace")
     }
예제 #2
0
class DataStore(ResourceInfo):

    resource_type = "dataStore"
    save_method = "PUT"

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

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

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

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

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

    @property
    def resource_url(self):
        url = build_url(self.catalog.service_url, [
            "workspaces", self.workspace.name, "datastores", self.name,
            "featuretypes.xml"
        ])
        return url

    def get_resources(self, name=None, available=False):
        res_url = self.resource_url
        if available:
            res_url += "?list=available"
        xml = self.catalog.get_xml(res_url)

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

        # if name passed, return only one FeatureType, otherwise return all FeatureTypes in store:
        if name is not None:
            for node in xml.findall("featureType"):
                if node.findtext("name") == name:
                    return ft_from_node(node)
            return None
        if available:
            return [str(node.text) for node in xml.findall("featureTypeName")]
        else:
            return [ft_from_node(node) for node in xml.findall("featureType")]
예제 #3
0
    def __init__(self, catalog, name, workspace=None):
        super(LayerGroup, self).__init__()

        assert isinstance(name, basestring)

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

        # the XML format changed in 2.3.x - the element listing all the layers
        # and the entries themselves have changed
        if self.catalog.gsversion() == "2.2.x":
            parent, element, attributes = "layers", "layer", None
        else:
            parent, element, attributes = "publishables", "published", {
                'type': 'layer'
            }

        self._layer_parent = parent
        self._layer_element = element
        self._layer_attributes = attributes
        self.writers = dict(name=write_string("name"),
                            styles=_write_styles,
                            layers=lambda b, l: _write_layers(
                                b, l, parent, element, attributes),
                            bounds=write_bbox("bounds"),
                            workspace=write_string("workspace"),
                            mode=write_string("mode"),
                            abstractTxt=write_string("abstractTxt"),
                            title=write_string("title"))
예제 #4
0
class DataStore(ResourceInfo):
    resource_type = "dataStore"
    save_method = settings.PUT

    def __init__(self, catalog, workspace, name):
        super(DataStore, self).__init__()
        assert isinstance(workspace, Workspace)
        assert isinstance(name, str)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        join_url = "workspaces/{}/datastores/{}.xml".format(
            self.workspace.name, self.name)
        return urljoin(self.catalog.service_url, join_url)

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

    writers = {
        "enabled": write_bool("enabled"),
        "name": write_string("name"),
        "type": write_string("type"),
        "connectionParameters": write_dict("connectionParameters"),
    }

    @property
    def resource_url(self):
        return urljoin(
            self.catalog.service_url,
            "workspaces/{}/datastores/{}/featuretypes.xml".format(
                self.workspace.name, self.name),
        )

    def get_resources(self, name=None, available=False):
        res_url = self.resource_url
        if available:
            res_url += "?list=available"
        xml = self.catalog.get_xml(res_url)

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

        # if name passed, return only one FeatureType,
        # otherwise return all FeatureTypes in store:
        if name is not None:
            for node in xml.findall("featureType"):
                if node.findtext("name") == name:
                    return ft_from_node(node)
            return None
        if available:
            return [str(node.text) for node in xml.findall("featureTypeName")]
        else:
            return [ft_from_node(node) for node in xml.findall("featureType")]
예제 #5
0
    def __init__(self, catalog, name):
        super(LayerGroup, self).__init__()

        assert isinstance(name, basestring)

        self.catalog = catalog
        self.name = name

        # the XML format changed in 2.3.x - the element listing all the layers
        # and the entries themselves have changed
        if self.catalog.gsversion() == "2.2.x":
            parent, element, attributes = "layers", "layer", None
        else:
            parent, element = "publishables", "published"
        self._layer_parent = parent
        self._layer_element = element
        self.writers = dict(
            name = write_string("name"),
            title = write_string("title"),
            abstract = write_string("abstractTxt"),
            mode = write_string("mode"),
            styles = _write_styles,
            layers = lambda b,l: _write_layers_mixed(b, l, parent, element),
            bounds = write_bbox("bounds")
        )
예제 #6
0
class FeatureType(_ResourceBase):

    resource_type = "featureType"
    url_part_stores = 'datastores'
    url_part_types = 'featuretypes'

    title = xml_property("title")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    advertised = xml_property("advertised", default="true")
    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"),
                   advertised=write_bool("advertised"),
                   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"))
예제 #7
0
    def __init__(self, catalog, name, workspace=None):
        super(LayerGroup, self).__init__()

        assert isinstance(name, basestring)

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

        # the XML format changed in 2.3.x - the element listing all the layers
        # and the entries themselves have changed
        if self.catalog.gsversion() == "2.2.x":
            parent, element, attributes = "layers", "layer", None
        else:
            parent, element, attributes = "publishables", "published", {'type':'layer'}
        self._layer_parent = parent
        self._layer_element = element
        self._layer_attributes = attributes
        self.writers = dict(
            name = write_string("name"),
            styles = _write_styles,
            layers = lambda b,l: _write_layers(b, l, parent, element, attributes),
            bounds = write_bbox("bounds"),
            workspace = write_string("workspace")
        )
예제 #8
0
class Coverage(_ResourceBase):

    resource_type = "coverage"
    url_part_stores = 'coveragestores'
    url_part_types = 'coverages'

    title = xml_property("title")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    advertised = xml_property("advertised", default="true")
    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"),
                   advertised=write_bool("advertised"),
                   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"))
예제 #9
0
class WmsStore(ResourceInfo):
    resource_type = "wmsStore"
    save_method = "PUT"

    def __init__(self, catalog, workspace, name, user, password):
        super(WmsStore, self).__init__()
        self.catalog = catalog
        self.workspace = workspace
        self.name = name
        self.metadata = {}
        self.metadata['user'] = user
        self.metadata['password'] = password

    @property
    def href(self):
        return "%s/workspaces/%s/wmsstores/%s.xml" % (
            self.catalog.service_url, self.workspace.name, self.name)

    enabled = xml_property("enabled", lambda x: x.text == "true")
    name = xml_property("name")
    nativeName = xml_property("nativeName")
    capabilitiesURL = xml_property("capabilitiesURL")
    type = xml_property("type")
    metadata = xml_property("metadata", key_value_pairs)

    writers = dict(enabled=write_bool("enabled"),
                   name=write_string("name"),
                   capabilitiesURL=write_string("capabilitiesURL"),
                   type=write_string("type"),
                   metadata=write_dict("metadata"))

    def get_resources(self, name=None, available=False):
        res_url = "{}/workspaces/{}/wmsstores/{}/wmslayers.xml".format(
            self.catalog.service_url, self.workspace.name, self.name)
        layer_name_attr = "wmsLayer"

        if available:
            res_url += "?list=available"
            layer_name_attr += 'Name'

        xml = self.catalog.get_xml(res_url)

        def wl_from_node(node):
            return wmslayer_from_index(self.catalog, self.workspace, self,
                                       node)

        # if name passed, return only one layer, otherwise return all layers in store:
        if name is not None:
            for node in xml.findall(layer_name_attr):
                if node.findtext("name") == name:
                    return wl_from_node(node)
            return None

        if available:
            return [str(node.text) for node in xml.findall(layer_name_attr)]
        else:
            return [
                wl_from_node(node) for node in xml.findall(layer_name_attr)
            ]
예제 #10
0
class CoverageStore(ResourceInfo):
    resource_type = "coverageStore"
    save_method = settings.PUT

    def __init__(self, catalog, workspace, name):
        super(CoverageStore, self).__init__()
        assert isinstance(workspace, Workspace)
        assert isinstance(name, str)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return urljoin(
            self.catalog.service_url,
            "workspaces/{}/coveragestores/{}.xml".format(
                self.workspace.name, self.name),
        )

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

    writers = {
        "enabled": write_bool("enabled"),
        "name": write_string("name"),
        "url": write_string("url"),
        "type": write_string("type"),
        "workspace": write_string("workspace"),
    }

    def get_resources(self, name=None):
        res_url = urljoin(
            self.catalog.service_url,
            "workspaces/{}/coveragestores/{}/coverages.xml".format(
                self.workspace.name, self.name),
        )
        xml = self.catalog.get_xml(res_url)

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

        # if name passed, return only one Coverage,
        # otherwise return all Coverages in store:
        if name is not None:
            for node in xml.findall("coverage"):
                if node.findtext("name") == name:
                    return cov_from_node(node)
            return None
        return [cov_from_node(node) for node in xml.findall("coverage")]
예제 #11
0
class CoverageStore(ResourceInfo):
    resource_type = 'coverageStore'
    save_method = "PUT"

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

        assert isinstance(workspace, ws.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"),
                   workspace=write_string("workspace"))

    def get_resources(self, name=None):
        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)

        # if name passed, return only one Coverage, otherwise return all Coverages in store:
        if name is not None:
            for node in xml.findall("coverage"):
                if node.findtext("name") == name:
                    return cov_from_node(node)
            return None
        return [cov_from_node(node) for node in xml.findall("coverage")]
예제 #12
0
class WmsStore(ResourceInfo):
    resource_type = "wmsStore"
    save_method = "PUT"

    def __init__(self, catalog, workspace, name, user, password):
        super(WmsStore, self).__init__()

        assert isinstance(workspace, ws.Workspace)
        assert isinstance(name, basestring)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name
        self.metadata = {}
        self.metadata['user'] = user
        self.metadata['password'] = password

    @property
    def href(self):
        return "%s/workspaces/%s/wmsstores/%s.xml" % (
            self.catalog.service_url, self.workspace.name, self.name)

    enabled = xml_property("enabled", lambda x: x.text == "true")
    name = xml_property("name")
    capabilitiesURL = xml_property("capabilitiesURL")
    type = xml_property("type")
    metadata = xml_property("metadata", key_value_pairs)

    writers = dict(enabled=write_bool("enabled"),
                   name=write_string("name"),
                   capabilitiesURL=write_string("capabilitiesURL"),
                   type=write_string("type"),
                   metadata=write_dict("metadata"))

    def get_resources(self, available=False):

        res_url = "%s/workspaces/%s/wmsstores/%s/wmslayers.xml" % (
            self.catalog.service_url, self.workspace.name, self.name)
        if available:
            res_url += "?list=available"

        xml = self.catalog.get_xml(res_url)

        def wl_from_node(node):
            return wmslayer_from_index(self.catalog, self.workspace, self,
                                       node)

        if available:
            return [str(node.text) for node in xml.findall("wmsLayerName")]
        else:
            return [wl_from_node(node) for node in xml.findall("wmsLayer")]
예제 #13
0
class WmsLayer(ResourceInfo):
    resource_type = "wmsLayer"
    save_method = settings.PUT

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

    @property
    def href(self):
        return urljoin(
            self.catalog.service_url,
            "workspaces/{}/wmsstores/{}/wmslayers/{}.xml".format(
                self.workspace.name,
                self.store.name,
                self.name
            )
        )

    title = xml_property("title")
    description = xml_property("description")
    abstract = xml_property("abstract")
    keywords = xml_property("keywords", string_list)
    # nativeCRS
    projection = xml_property("srs")
    native_bbox = xml_property("nativeBoundingBox", bbox)
    latlon_bbox = xml_property("latLonBoundingBox", bbox)
    projection_policy = xml_property("projectionPolicy")
    enabled = xml_property("enabled", lambda x: x.text == "true")
    advertised = xml_property("advertised", lambda x: x.text == "true",
                              default=True)
    metadata_links = xml_property("metadataLinks", metadata_link_list)

    writers = {
        'title': write_string("title"),
        'description': write_string("description"),
        'abstract': write_string("abstract"),
        'keywords': write_string_list("keywords"),
        # nativeCRS
        'srs': write_string("srs"),
        'nativeBoundingBox': write_bbox("nativeBoundingBox"),
        'latLonBoundingBox': write_bbox("latLonBoundingBox"),
        'projectionPolicy': write_string("projectionPolicy"),
        'enabled': write_bool("enabled"),
        'advertised': write_bool("advertised"),
        'metadataLinks': write_metadata_link_list("metadataLinks")
    }
예제 #14
0
class WmsLayer(ResourceInfo):
    resource_type = "wmsLayer"
    save_method = "PUT"

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

    @property
    def href(self):
        return "%s/workspaces/%s/wmsstores/%s/wmslayers/%s.xml" % (
                self.catalog.service_url,
                self.workspace.name,
                self.store.name,
                self.name
                )


    title = xml_property("title")
    description = xml_property("description")
    abstract = xml_property("abstract")
    keywords = xml_property("keywords", string_list)
    # nativeCRS
    projection = xml_property("srs")
    native_bbox = xml_property("nativeBoundingBox", bbox)
    latlon_bbox = xml_property("latLonBoundingBox", bbox)
    projection_policy = xml_property("projectionPolicy")
    enabled = xml_property("enabled", lambda x: x.text == "true")
    advertised = xml_property("advertised", lambda x: x.text == "true", default=True)
    metadata_links = xml_property("metadataLinks", metadata_link_list)

    writers = dict(
                title = write_string("title"),
                description = write_string("description"),
                abstract = write_string("abstract"),
                keywords = write_string_list("keywords"),
                # nativeCRS
                projection = write_string("srs"),
                nativeBoundingBox = write_bbox("nativeBoundingBox"),
                latLonBoundingBox = write_bbox("latLonBoundingBox"),
                projection_policy = write_string("projectionPolicy"),
                enabled = write_bool("enabled"),
                advertised = write_bool("advertised"),
                metadataLinks = write_metadata_link_list("metadataLinks")
           )
예제 #15
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__
예제 #16
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")
            )
예제 #17
0
class Coverage(_ResourceBase):

    resource_type = "coverage"
    url_part_stores = 'coveragestores'
    url_part_types = 'coverages'

    title = xml_property("title")
    native_name = xml_property("nativeName")
    native_format = xml_property("nativeFormat")
    native_crs = xml_property("nativeCRS")
    default_interpolation_method = xml_property("defaultInterpolationMethod")
    abstract = xml_property("abstract")
    description = xml_property("description")
    enabled = xml_property("enabled")
    advertised = xml_property("advertised", default="true")
    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)
    metadata = xml_property("metadata", metadata)
    interpolation_methods = xml_property("interpolationMethods", string_list)

    writers = {
        'title': write_string("title"),
        'native_name': write_string("nativeName"),
        'native_format': write_string("nativeFormat"),
        'native_crs': write_string("nativeCRS"),
        'default_interpolation_method':
        write_string("defaultInterpolationMethod"),
        'description': write_string("description"),
        'abstract': write_string("abstract"),
        'enabled': write_bool("enabled"),
        'advertised': write_bool("advertised"),
        '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"),
        'interpolation_methods': write_string_list("interpolationMethods"),
        'metadata': write_metadata("metadata")
    }
예제 #18
0
    def __init__(self, catalog: Catalog, name: str, nativeName: str, title: str, nativeCVoverageName: str):
        super().__init__(catalog, name)
        self.nativeName = nativeName
        self.title = title
        self.nativeCVoverageName = nativeCVoverageName
        root_node = (
            {'key': 'name', 'val': self.name}
        )
        # 更新 dirty

        self.dirty.update(dict(
            name=write_string("name"),
            title=write_string("type"),
            nativeCoverageName=write_string("nativeCoverageName"),
            nativeName=write_string("nativeName"),
            # metadata=
        ))
        pass
예제 #19
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")
    advertised = xml_property("advertised")
    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"),
                   advertised=write_bool("advertised"),
                   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"))
예제 #20
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)
    bounds = xml_property("bounds", bbox)

    def _layers_getter(self):
        if self.catalog.gsversion() == "2.2.x":
            path, converter = "layers", _layer_list
        else:
            path, converter = "publishables", _publishable_list
        if path in self.dirty:
            return self.dirty[path]
        else:
            if self.dom is None:
                self.fetch()
            node = self.dom.find(path)
            return converter(self.dom.find(path)) if node is not None else None

    def _layers_setter(self, value):
        self.dirty["layers"] = value

    def _layers_delete(self):
        self.dirty["layers"] = None

    layers = property(_layers_getter, _layers_setter, _layers_delete)

    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__
예제 #21
0
class FeatureType(_ResourceBase):

    resource_type = "featureType"
    url_part_stores = 'datastores'
    url_part_types = 'featuretypes'

    title = xml_property("title")
    native_name = xml_property("nativeName")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    advertised = xml_property("advertised", default="true")
    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)
    metadata = xml_property("metadata", metadata)
    cqlFilter = xml_property("cqlFilter")

    writers = {
        'name': write_string("name"),
        'nativeName': write_string("nativeName"),
        'title': write_string("title"),
        'abstract': write_string("abstract"),
        'enabled': write_bool("enabled"),
        'advertised': write_bool("advertised"),
        'nativeBoundingBox': write_bbox("nativeBoundingBox"),
        'latLonBoundingBox': write_bbox("latLonBoundingBox"),
        'srs': write_string("srs"),
        'nativeCRS': write_string("nativeCRS"),
        'projectionPolicy': write_string("projectionPolicy"),
        'keywords': write_string_list("keywords"),
        'metadataLinks': write_metadata_link_list("metadataLinks"),
        'metadata': write_metadata("metadata"),
        'cqlFilter': write_string('cqlFilter')
    }
예제 #22
0
class DataStore(ResourceInfo):
    resource_type = "dataStore"
    save_method = "PUT"

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

        assert isinstance(workspace, ws.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")]
예제 #23
0
class FeatureType(_ResourceBase):

    resource_type = "featureType"
    url_part_stores = "datastores"
    url_part_types = "featuretypes"

    title = xml_property("title")
    native_name = xml_property("nativeName")
    abstract = xml_property("abstract")
    enabled = xml_property("enabled")
    advertised = xml_property("advertised", default="true")
    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)
    metadata = xml_property("metadata", metadata)

    writers = {
        "name": write_string("name"),
        "nativeName": write_string("nativeName"),
        "title": write_string("title"),
        "abstract": write_string("abstract"),
        "enabled": write_bool("enabled"),
        "advertised": write_bool("advertised"),
        "nativeBoundingBox": write_bbox("nativeBoundingBox"),
        "latLonBoundingBox": write_bbox("latLonBoundingBox"),
        "srs": write_string("srs"),
        "nativeCRS": write_string("nativeCRS"),
        "projectionPolicy": write_string("projectionPolicy"),
        "keywords": write_string_list("keywords"),
        "metadataLinks": write_metadata_link_list("metadataLinks"),
        "metadata": write_metadata("metadata"),
    }
예제 #24
0
class WmsStore(ResourceInfo):
    resource_type = "wmsStore"
    save_method = settings.PUT

    def __init__(self, catalog, workspace, name):
        super(WmsStore, self).__init__()
        assert isinstance(workspace, Workspace)
        assert isinstance(name, str)
        self.catalog = catalog
        self.workspace = workspace
        self.name = name

    @property
    def href(self):
        return urljoin(
            self.catalog.service_url,
            "workspaces/{}/wmsstores/{}.xml".format(self.workspace.name,
                                                    self.name),
        )

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

    writers = {
        "enabled": write_bool("enabled"),
        "name": write_string("name"),
        "capabilitiesURL": write_string("capabilitiesURL"),
        "type": write_string("type"),
    }

    def get_resources(self, name=None, available=False):
        res_url = urljoin(
            self.catalog.service_url,
            "workspaces/{}/wmsstores/{}/wmslayers.xml".format(
                self.workspace.name, self.name),
        )
        layer_name_attr = "wmsLayer"
        if available:
            res_url += "?list=available"
            layer_name_attr += "Name"
        xml = self.catalog.get_xml(res_url)

        def wl_from_node(node):
            return wmslayer_from_index(self.catalog, self.workspace, self,
                                       node)

        # if name passed, return only one layer,
        # otherwise return all layers in store:
        if name is not None:
            for node in xml.findall(layer_name_attr):
                if node.findtext("name") == name:
                    return wl_from_node(node)
            return None

        if available:
            return [str(node.text) for node in xml.findall(layer_name_attr)]
        else:
            return [
                wl_from_node(node) for node in xml.findall(layer_name_attr)
            ]
예제 #25
0
class CoverageStore(ResourceInfo, IStore):
    # TODO:[-] 由于继承自ResourceInfo,由继承子类声明一个类变量,用来生成xml时的tag name时使用
    resource_type = 'coverageStore'
    save_method = "PUT"

    def __init__(self, catalog: Catalog, workspace: str, name: str):
        '''
            父类中定义了一个字典属性  self.dirty
        '''
        # ResourceInfo 构造函数中只声明了 dom 与 dirty(dict)
        super(CoverageStore, self).__init__()

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

    @property
    def href(self):
        '''
            TODO:[-] 所有的ResourceInfo 实现类均需实现 href 属性方法(此处建议还是加入接口)
        '''
        url = build_url(
            self.catalog.service_url,
            [
                "workspaces",
                self.workspace.name,
                "coveragestores",
                "{}.xml".format(self.name)
            ]
        )
        return url

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

    # TODO:[-] 主要为继承的 ResourceInfo 父类中的 def message -> def serialize 中调用
    writers = dict(
        enabled=write_bool("enabled"),
        name=write_string("name"),
        url=write_string("url"),
        type=write_string("type"),
        workspace=write_string("workspace")
    )

    def get_resources(self, name=None):
        '''
            TODO:[*] ? 何用?
        '''
        res_url = build_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)

        # if name passed, return only one Coverage, otherwise return all Coverages in store:
        if name is not None:
            for node in xml.findall("coverage"):
                if node.findtext("name") == name:
                    return cov_from_node(node)
            return None
        return [cov_from_node(node) for node in xml.findall("coverage")]