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

        assert isinstance(name, string_types)

        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.get_version() == "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"),
            'mode': write_string("mode"),
            'abstractTxt': write_string("abstractTxt"),
            'title': write_string("title"),
            'enabled': write_bool("enabled"),
            'advertised': write_bool("advertised"),
        }
Exemple #2
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(name=write_string("name"),
                   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"))
Exemple #3
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"))
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")
    }
Exemple #5
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")
    }
Exemple #6
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")
           )
Exemple #7
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")]
Exemple #8
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")]
Exemple #9
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"])

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

    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)
Exemple #10
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)
            ]
Exemple #11
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"))
Exemple #12
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")]
Exemple #13
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")]
Exemple #14
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')
    }
Exemple #15
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")]
Exemple #16
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"),
    }
Exemple #17
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")
            )
Exemple #18
0
class Workspace(ResourceInfo):
    resource_type = "workspace"

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

    @property
    def catalog(self):
        return self._catalog

    @property
    def name(self):
        return self._name

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

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

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

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

    enabled = xml_property("enabled", lambda x: x.lower() == "true")
    writers = {"enabled": write_bool("enabled")}

    def __repr__(self):
        return "{} @ {}".format(self.name, self.href)
Exemple #19
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")]
Exemple #20
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")
    advertised = xml_property("advertised")

    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"),
                   advertised=write_bool("advertised"),
                   default_style=_write_default_style,
                   alternate_styles=_write_alternate_styles)
Exemple #21
0
class Layer(ResourceInfo):
    def __init__(self, catalog, name):
        super(Layer, self).__init__()
        self.catalog = catalog
        self.name = name

    resource_type = "layer"
    save_method = settings.PUT

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

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

    @property
    def queryable(self):
        if self.dom is None:
            self.fetch()
        queryableEl = self.dom.find("queryable")
        if queryableEl is None:
            return True
        else:
            return (queryableEl.text == "true")

    @queryable.setter
    def queryable(self, queryable):
        self.dirty["queryable"] = queryable

    @property
    def opaque(self):
        if self.dom is None:
            self.fetch()
        opaqueEl = self.dom.find("opaque")
        if opaqueEl is None:
            return True
        else:
            return (opaqueEl.text == "true")

    @opaque.setter
    def opaque(self, opaque):
        self.dirty["opaque"] = opaque

    @property
    def default_style(self):
        if 'default_style' in self.dirty:
            return self.dirty['default_style']
        if self.dom is None:
            self.fetch()
        element = self.dom.find("defaultStyle")
        # aborted data uploads can result in no default style
        return self._resolve_style(element) if element is not None else None

    @default_style.setter
    def default_style(self, style):
        if isinstance(style, Style):
            style = style.fqn
        self.dirty["default_style"] = style

    @property
    def styles(self):
        if "alternate_styles" in self.dirty:
            return self.dirty["alternate_styles"]
        if self.dom is None:
            self.fetch()
        styles_list = self.dom.findall("styles/style")
        return filter(None, [self._resolve_style(s) for s in styles_list])

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

    def _resolve_style(self, element):
        # instead of using name or the workspace element (which only appears
        # in >=2.4), just use the atom link href attribute
        atom_link = [n for n in element.getchildren() if 'href' in n.attrib]
        if atom_link:
            style_workspace_url = atom_link[0].attrib.get("href")
            return self.catalog.get_style_by_url(style_workspace_url)

    @property
    def attribution(self):
        return self.attribution_object.title

    @attribution.setter
    def attribution(self, text):
        self.dirty["attribution"] = _Attribution(
            text, self.attribution_object.width,
            self.attribution_object.height)
        assert self.attribution_object.title == text

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

    def _get_attr_attribution(self):
        return {
            'title': self.attribution_object.title,
            'width': self.attribution_object.width,
            'height': self.attribution_object.height,
            'href': self.attribution_object.href,
            'url': self.attribution_object.url,
            'type': self.attribution_object.logo_type
        }

    def _set_attr_attribution(self, attribution):
        self.dirty["attribution"] = _Attribution(
            attribution['title'], attribution['width'], attribution['height'],
            attribution['href'], attribution['url'], attribution['type'])

        assert self.attribution_object.title == attribution['title']
        assert self.attribution_object.width == attribution['width']
        assert self.attribution_object.height == attribution['height']
        assert self.attribution_object.href == attribution['href']
        assert self.attribution_object.url == attribution['url']
        assert self.attribution_object.logo_type == attribution['type']

    attribution = property(_get_attr_attribution, _set_attr_attribution)

    writers = {
        'attribution': _write_attribution,
        'enabled': write_bool("enabled"),
        'advertised': write_bool("advertised"),
        'default_style': _write_default_style,
        'alternate_styles': _write_alternate_styles,
        'queryable': write_bool("queryable"),
        'opaque': write_bool("opaque")
    }
Exemple #22
0
class Layer(ResourceInfo):
    def __init__(self, catalog, name):
        super(Layer, self).__init__()
        self.catalog = catalog
        self.name = name

    resource_type = "layer"
    save_method = settings.PUT

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

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

    @property
    def default_style(self):
        if "default_style" in self.dirty:
            return self.dirty["default_style"]
        if self.dom is None:
            self.fetch()
        element = self.dom.find("defaultStyle")
        # aborted data uploads can result in no default style
        return self._resolve_style(element) if element is not None else None

    @default_style.setter
    def default_style(self, style):
        if isinstance(style, Style):
            style = style.fqn
        self.dirty["default_style"] = style

    @property
    def styles(self):
        if "alternate_styles" in self.dirty:
            return self.dirty["alternate_styles"]
        if self.dom is None:
            self.fetch()
        styles_list = self.dom.findall("styles/style")
        return filter(None, [self._resolve_style(s) for s in styles_list])

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

    def _resolve_style(self, element):
        # instead of using name or the workspace element (which only appears
        # in >=2.4), just use the atom link href attribute
        atom_link = [n for n in element.getchildren() if "href" in n.attrib]
        if atom_link:
            style_workspace_url = atom_link[0].attrib.get("href")
            return self.catalog.get_style_by_url(style_workspace_url)

    @property
    def attribution(self):
        return self.attribution_object.title

    @attribution.setter
    def attribution(self, text):
        self.dirty["attribution"] = _Attribution(
            text, self.attribution_object.width,
            self.attribution_object.height)
        assert self.attribution_object.title == text

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

    def _get_attr_attribution(self):
        return {
            "title": self.attribution_object.title,
            "width": self.attribution_object.width,
            "height": self.attribution_object.height,
            "href": self.attribution_object.href,
            "url": self.attribution_object.url,
            "type": self.attribution_object.logo_type,
        }

    def _set_attr_attribution(self, attribution):
        self.dirty["attribution"] = _Attribution(
            attribution["title"],
            attribution["width"],
            attribution["height"],
            attribution["href"],
            attribution["url"],
            attribution["type"],
        )

        assert self.attribution_object.title == attribution["title"]
        assert self.attribution_object.width == attribution["width"]
        assert self.attribution_object.height == attribution["height"]
        assert self.attribution_object.href == attribution["href"]
        assert self.attribution_object.url == attribution["url"]
        assert self.attribution_object.logo_type == attribution["type"]

    attribution = property(_get_attr_attribution, _set_attr_attribution)

    writers = {
        "attribution": _write_attribution,
        "enabled": write_bool("enabled"),
        "advertised": write_bool("advertised"),
        "default_style": _write_default_style,
        "alternate_styles": _write_alternate_styles,
    }
Exemple #23
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)
            ]
Exemple #24
0
class Layer(ResourceInfo):
    def __init__(self, catalog: Catalog, name: str):
        super(Layer, self).__init__()
        # TODO:[-] 在所有实现类的构造函数中定义 catalog
        self.catalog = catalog
        self.name = name
        self.gs_version = self.catalog.get_short_version()

    resource_type = "layer"
    save_method = "PUT"

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

    @property
    def resource(self):
        '''
            TODO:[*] 何用? 我的理解layer里面没有msg,有reources
        '''
        if self.dom is None:
            self.fetch()
        name = self.dom.find("resource/name").text
        atom_link = [n for n in self.dom.find("resource").getchildren() if 'href' in n.attrib]
        ws_name = workspace_from_url(atom_link[0].get('href'))
        if self.gs_version >= "2.13":
            if ":" in name:
                ws_name, name = name.split(':')
        return self.catalog.get_resources(names=name, workspaces=ws_name)[0]

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

    def _resolve_style(self, element):
        if ":" in element.find('name').text:
            ws_name, style_name = element.find('name').text.split(':')
        else:
            style_name = element.find('name').text
            ws_name = None
        atom_link = [n for n in element.getchildren() if 'href' in n.attrib]
        if atom_link and ws_name is None:
            ws_name = workspace_from_url(atom_link[0].get("href"))
        return self.catalog.get_styles(names=style_name, workspaces=ws_name)[0]

    def _set_default_style(self, style):
        if isinstance(style, Style):
            style = style.fqn
        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_list = self.dom.findall("styles/style")
        return [self._resolve_style(s) for s in styles_list]

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

    # TODO:[*] 20-03-20 设置默认style
    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")
    advertised = xml_property("advertised", lambda x: x.text == "true", default=True)
    type = xml_property("type")

    def _get_attr_attribution(self):
        obj = {
            'title': self.attribution_object.title,
            'width': self.attribution_object.width,
            'height': self.attribution_object.height,
            'href': self.attribution_object.href,
            'url': self.attribution_object.url,
            'type': self.attribution_object.type
        }
        return obj

    def _set_attr_attribution(self, attribution):
        self.dirty["attribution"] = _attribution(
            attribution['title'],
            attribution['width'],
            attribution['height'],
            attribution['href'],
            attribution['url'],
            attribution['type']
        )

        assert self.attribution_object.title == attribution['title']
        assert self.attribution_object.width == attribution['width']
        assert self.attribution_object.height == attribution['height']
        assert self.attribution_object.href == attribution['href']
        assert self.attribution_object.url == attribution['url']
        assert self.attribution_object.type == attribution['type']

    attribution = property(_get_attr_attribution, _set_attr_attribution)

    writers = dict(
        attribution=_write_attribution,
        enabled=write_bool("enabled"),
        advertised=write_bool("advertised"),
        default_style=_write_default_style,
        alternate_styles=_write_alternate_styles
    )
Exemple #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")]
Exemple #26
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:
            style = self.catalog.get_style(name.text)
            # the default catalog.get_style may not return a valid style if it is stored in a workspace
            # in this case obtain the style be reading the style url directly:
            if style is not None:
                return style
            else:
                #atom_link = self.dom.find("defaultStyle/{atom}link[@rel]")
                #atom_link = self.dom.find("defaultStyle/link[@rel]")
                style_workspace_url = self.dom.find(
                    "defaultStyle").getchildren()[1].attrib.get("href")
                style = self.catalog.get_style_by_url(style_workspace_url)
                return style
        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_list = self.dom.findall("styles/style")
        #styles = self.dom.findall("styles/style/name")

        alternate_styles = []
        for s in styles_list:
            style = self.catalog.get_style(s.find("name").text)
            if style is not None:
                alternate_styles.append(style)
            else:
                style_workspace_url = s.getchildren()[1].attrib.get("href")
                style = self.catalog.get_style_by_url(style_workspace_url)
                alternate_styles.append(style)
        return alternate_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")
    advertised = xml_property("advertised",
                              lambda x: x.text == "true",
                              default=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"),
                   advertised=write_bool("advertised"),
                   default_style=_write_default_style,
                   alternate_styles=_write_alternate_styles)
Exemple #27
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()
        element = self.dom.find("defaultStyle")
        # aborted data uploads can result in no default style
        return self._resolve_style(element) if element is not None else None

    def _resolve_style(self, element):
        name_section = element.find('name')
        if name_section is not None:
            return self.catalog.get_style(name_section.text)
        else:
            return None

    def _set_default_style(self, style):
        if isinstance(style, Style):
            style = style.fqn
        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_list = self.dom.findall("styles/style")
        return filter(None, [self._resolve_style(s) for s in styles_list])

    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")
    advertised = xml_property("advertised",
                              lambda x: x.text == "true",
                              default=True)

    def _get_attr_attribution(self):
        return {
            'title': self.attribution_object.title,
            'width': self.attribution_object.width,
            'height': self.attribution_object.height,
            'href': self.attribution_object.href,
            'url': self.attribution_object.url,
            'type': self.attribution_object.type
        }

    def _set_attr_attribution(self, attribution):
        self.dirty["attribution"] = _attribution(
            attribution['title'], attribution['width'], attribution['height'],
            attribution['href'], attribution['url'], attribution['type'])

        assert self.attribution_object.title == attribution['title']
        assert self.attribution_object.width == attribution['width']
        assert self.attribution_object.height == attribution['height']
        assert self.attribution_object.href == attribution['href']
        assert self.attribution_object.url == attribution['url']
        assert self.attribution_object.type == attribution['type']

    attribution = property(_get_attr_attribution, _set_attr_attribution)

    writers = dict(attribution=_write_attribution,
                   enabled=write_bool("enabled"),
                   advertised=write_bool("advertised"),
                   default_style=_write_default_style,
                   alternate_styles=_write_alternate_styles)
Exemple #28
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()
        element = self.dom.find("defaultStyle")
        # aborted data uploads can result in no default style
        return self._resolve_style(element) if element is not None else None

    def _resolve_style(self, element):
        # instead of using name or the workspace element (which only appears
        # in >=2.4), just use the atom link href attribute
        atom_link = [n for n in element.getchildren() if 'href' in n.attrib]
        if atom_link:
            style_workspace_url = atom_link[0].attrib.get("href")
            return self.catalog.get_style_by_url(style_workspace_url)

    def _set_default_style(self, style):
        if isinstance(style, Style):
            style = style.fqn
        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_list = self.dom.findall("styles/style")
        return filter(None, [self._resolve_style(s) for s in styles_list])

    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")
    advertised = xml_property("advertised",
                              lambda x: x.text == "true",
                              default=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"),
                   advertised=write_bool("advertised"),
                   default_style=_write_default_style,
                   alternate_styles=_write_alternate_styles)