Esempio n. 1
0
 def get_layergroup(self, name=None):
     try:
         group_url = url(self.service_url, ['layergroups', name + '.xml'])
         group = self.get_xml(group_url)
         return LayerGroup(self, group.find('name').text)
     except FailedRequestError:
         return None
Esempio n. 2
0
 def get_layergroup(self, name=None):
     try:
         group_url = url(self.service_url, ["layergroups", name + ".xml"])
         group = self.get_xml(group_url)
         return LayerGroup(self, group.find("name").text)
     except FailedRequestError:
         return None
Esempio n. 3
0
    def add_data_to_store(self, store, name, data, workspace=None, overwrite = False, charset = None):
        if isinstance(store, basestring):
            store = self.get_store(store, workspace=workspace)
        if workspace is not None:
            workspace = _name(workspace)
            assert store.workspace.name == workspace, "Specified store (%s) is not in specified workspace (%s)!" % (store, workspace)
        else:
            workspace = store.workspace.name
        store = store.name

        if isinstance(data, dict):
            bundle = prepare_upload_bundle(name, data)
        else:
            bundle = data

        params = dict()
        if overwrite:
            params["update"] = "overwrite"
        if charset is not None:
            params["charset"] = charset

        message = open(bundle)
        headers = { 'Content-Type': 'application/zip', 'Accept': 'application/xml' }
        upload_url = url(self.service_url,
            ["workspaces", workspace, "datastores", store, "file.shp"], params)

        try:
            headers, response = self.http.request(upload_url, "PUT", message, headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            unlink(bundle)
Esempio n. 4
0
 def get_style(self, name):
     try:
         style_url = url(self.service_url, ['styles', name + '.xml'])
         dom = self.get_xml(style_url)
         return Style(self, dom.find('name').text)
     except FailedRequestError:
         return None
Esempio n. 5
0
 def get_layergroup(self, name=None):
     try:
         group_url = url(self.service_url, ['layergroups', name + '.xml'])
         group = self.get_xml(group_url)
         return LayerGroup(self, group.find('name').text)
     except FailedRequestError:
         return None
Esempio n. 6
0
 def get_style(self, name):
     try:
         style_url = url(self.service_url, ['styles', name + '.xml'])
         dom = self.get_xml(style_url)
         return Style(self, dom.find('name').text)
     except FailedRequestError:
         return None
Esempio n. 7
0
 def get_style(self, name):
     try:
         style_url = url(self.service_url, ["styles", name + ".xml"])
         dom = self.get_xml(style_url)
         return Style(self, dom.find("name").text)
     except FailedRequestError:
         return None
Esempio n. 8
0
    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")]
Esempio n. 9
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'datastores',
         self.store.name,
         'featuretypes',
         self.name + '.xml',
     ])
Esempio n. 10
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'coveragestores',
         self.store.name,
         'coverages',
         self.name + '.xml',
     ])
Esempio n. 11
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'datastores',
         self.store.name,
         'featuretypes',
         self.name + '.xml',
         ])
Esempio n. 12
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'coveragestores',
         self.store.name,
         'coverages',
         self.name + '.xml',
         ])
Esempio n. 13
0
    def create_style(self, name, data, overwrite = False):
        if overwrite == False and self.get_style(name) is not None:
            raise ConflictingDataError("There is already a style named %s" % name)

        headers = {
            "Content-type": "application/vnd.ogc.sld+xml",
            "Accept": "application/xml"
        }

        if overwrite:
            style_url = url(self.service_url, ["styles", name + ".sld"])
            headers, response = self.http.request(style_url, "PUT", data, headers)
        else:
            style_url = url(self.service_url, ["styles"], dict(name=name))
            headers, response = self.http.request(style_url, "POST", data, headers)

        self._cache.clear()
        if headers.status < 200 or headers.status > 299: raise UploadError(response)
Esempio n. 14
0
 def get_layers(self, resource=None):
     if isinstance(resource, basestring):
         resource = self.get_resource(resource)
     layers_url = url(self.service_url, ["layers.xml"])
     description = self.get_xml(layers_url)
     lyrs = [Layer(self, l.find("name").text) for l in description.findall("layer")]
     if resource is not None:
         lyrs = [l for l in lyrs if l.resource.href == resource.href]
     # TODO: Filter by style
     return lyrs
Esempio n. 15
0
    def get_resources(self):
        res_url = url(self.catalog.service_url,
            ["workspaces", self.workspace.name, "coveragestores", self.name, "coverages.xml"])

        xml = self.catalog.get_xml(res_url)

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

        return [cov_from_node(node) for node in xml.findall("coverage")]
Esempio n. 16
0
    def create_style(self, name, data, overwrite=False):
        if not overwrite and self.get_style(name) is not None:
            raise ConflictingDataError('There is already a style named %s'
                                       % name)

        headers = {'Content-type': 'application/vnd.ogc.sld+xml',
                   'Accept': 'application/xml'}

        if overwrite:
            style_url = url(self.service_url, ['styles', name + '.sld'])
            (headers, response) = self.http.request(style_url, 'PUT', data,
                    headers)
        else:
            style_url = url(self.service_url, ['styles'], dict(name=name))
            (headers, response) = self.http.request(style_url, 'POST', data,
                    headers)

        self._cache.clear()
        if headers.status < 200 or headers.status > 299:
            raise UploadError(response)
Esempio n. 17
0
    def create_style(self, name, data, overwrite=False):
        if not overwrite and self.get_style(name) is not None:
            raise ConflictingDataError('There is already a style named %s'
                                       % name)

        headers = {'Content-type': 'application/vnd.ogc.sld+xml',
                   'Accept': 'application/xml'}

        if overwrite:
            style_url = url(self.service_url, ['styles', name + '.sld'])
            (headers, response) = self.http.request(style_url, 'PUT', data,
                    headers)
        else:
            style_url = url(self.service_url, ['styles'], dict(name=name))
            (headers, response) = self.http.request(style_url, 'POST', data,
                    headers)

        self._cache.clear()
        if headers.status < 200 or headers.status > 299:
            raise UploadError(response)
Esempio n. 18
0
    def get_layers(self, resource=None):
        if isinstance(resource, basestring):
            resource = self.get_resource(resource)
        layers_url = url(self.service_url, ['layers.xml'])
        description = self.get_xml(layers_url)
        lyrs = [Layer(self, l.find('name').text) for l in
                description.findall('layer')]
        if resource is not None:
            lyrs = [l for l in lyrs if l.resource.href == resource.href]

        # TODO: filter by style
        return lyrs
Esempio n. 19
0
    def create_coveragestore(self, name, data, workspace=None, overwrite=False):
        if not overwrite:
            try:
                store = self.get_store(name, workspace)
                msg = "There is already a store named " + name
                if workspace:
                    msg += " in " + str(workspace)
                raise ConflictingDataError(msg)
            except FailedRequestError:
                # we don't really expect that every layer name will be taken
                pass

        if workspace is None:
            workspace = self.get_default_workspace()
        headers = {
            "Content-type": "image/tiff",
            "Accept": "application/xml"
        }

        archive = None
        ext = "geotiff"

        if isinstance(data, dict):
            archive = prepare_upload_bundle(name, data)
            message = open(archive)
            if "tfw" in data:
                headers['Content-type'] = 'application/archive'
                ext = "worldimage"
        elif isinstance(data, basestring):
            message = open(data)
        else:
            message = data

        cs_url = url(self.service_url,
            ["workspaces", workspace.name, "coveragestores", name, "file." + ext])

        try:
            headers, response = self.http.request(cs_url, "PUT", message, headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            if archive is not None:
                unlink(archive)
Esempio n. 20
0
    def create_coveragestore(self, name, data, workspace=None,
                             overwrite=False):
        if not overwrite:
            try:
                store = self.get_store(name, workspace)
                msg = 'There is already a store named ' + name
                if workspace:
                    msg += ' in ' + str(workspace)
                raise ConflictingDataError(msg)
            except FailedRequestError:
                # We don't really expect that every layer name will be taken
                pass

        if workspace is None:
            workspace = self.get_default_workspace()
        headers = {'Content-type': 'image/tiff', 'Accept': 'application/xml'}

        archive = None
        ext = 'geotiff'

        if isinstance(data, dict):
            archive = prepare_upload_bundle(name, data)
            message = open(archive)
            if 'tfw' in data:
                headers['Content-type'] = 'application/archive'
                ext = 'worldimage'
        elif isinstance(data, basestring):
            message = open(data)
        else:
            message = data

        cs_url = url(self.service_url, ['workspaces', workspace.name,
                     'coveragestores', name, 'file.' + ext])

        try:
            (headers, response) = self.http.request(cs_url, 'PUT', message,
                    headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            if archive is not None:
                unlink(archive)
Esempio n. 21
0
    def create_coveragestore(self, name, data, workspace=None,
                             overwrite=False):
        if not overwrite:
            try:
                store = self.get_store(name, workspace)
                msg = 'There is already a store named ' + name
                if workspace:
                    msg += ' in ' + str(workspace)
                raise ConflictingDataError(msg)
            except FailedRequestError:
                # We don't really expect that every layer name will be taken
                pass

        if workspace is None:
            workspace = self.get_default_workspace()
        headers = {'Content-type': 'image/tiff', 'Accept': 'application/xml'}

        archive = None
        ext = 'geotiff'

        if isinstance(data, dict):
            archive = prepare_upload_bundle(name, data)
            message = open(archive)
            if 'tfw' in data:
                headers['Content-type'] = 'application/archive'
                ext = 'worldimage'
        elif isinstance(data, basestring):
            message = open(data)
        else:
            message = data

        cs_url = url(self.service_url, ['workspaces', workspace.name,
                     'coveragestores', name, 'file.' + ext])

        try:
            (headers, response) = self.http.request(cs_url, 'PUT', message,
                    headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            if archive is not None:
                unlink(archive)
Esempio n. 22
0
    def create_featurestore(self, name, data, workspace=None, overwrite=False,
                            charset=None):
        if not overwrite:
            try:
                store = self.get_store(name, workspace)
                msg = 'There is already a store named ' + name
                if workspace:
                    msg += ' in ' + str(workspace)
                raise ConflictingDataError(msg)
            except FailedRequestError:
                # We don't really expect that every layer name will be taken
                pass

        if workspace is None:
            workspace = self.get_default_workspace()
        workspace = _name(workspace)
        params = dict()
        if charset is not None:
            params['charset'] = charset
        ds_url = url(self.service_url, ['workspaces', workspace, 'datastores',
                     name, 'file.shp'], params)

        # PUT /workspaces/<ws>/datastores/<ds>/file.shp
        headers = {'Content-type': 'application/zip',
                   'Accept': 'application/xml'}
        if isinstance(data, dict):
            logger.debug('Data is NOT a zipfile')
            archive = prepare_upload_bundle(name, data)
        else:
            logger.debug('Data is a zipfile')
            archive = data
        message = open(archive)
        try:
            (headers, response) = self.http.request(ds_url, 'PUT', message,
                    headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            unlink(archive)
Esempio n. 23
0
    def create_featurestore(self, name, data, workspace=None, overwrite=False,
                            charset=None):
        if not overwrite:
            try:
                store = self.get_store(name, workspace)
                msg = 'There is already a store named ' + name
                if workspace:
                    msg += ' in ' + str(workspace)
                raise ConflictingDataError(msg)
            except FailedRequestError:
                # We don't really expect that every layer name will be taken
                pass

        if workspace is None:
            workspace = self.get_default_workspace()
        workspace = _name(workspace)
        params = dict()
        if charset is not None:
            params['charset'] = charset
        ds_url = url(self.service_url, ['workspaces', workspace, 'datastores',
                     name, 'file.shp'], params)

        # PUT /workspaces/<ws>/datastores/<ds>/file.shp
        headers = {'Content-type': 'application/zip',
                   'Accept': 'application/xml'}
        if isinstance(data, dict):
            logger.debug('Data is NOT a zipfile')
            archive = prepare_upload_bundle(name, data)
        else:
            logger.debug('Data is a zipfile')
            archive = data
        message = open(archive)
        try:
            (headers, response) = self.http.request(ds_url, 'PUT', message,
                    headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            unlink(archive)
Esempio n. 24
0
    def add_data_to_store(self, store, name, data, workspace=None,
                          overwrite=False, charset=None):
        if isinstance(store, basestring):
            store = self.get_store(store, workspace=workspace)
        if workspace is not None:
            workspace = _name(workspace)
            assert store.workspace.name == workspace, \
                'Specified store (%s) is not in specified workspace (%s)!' \
                % (store, workspace)
        else:
            workspace = store.workspace.name
        store = store.name

        if isinstance(data, dict):
            bundle = prepare_upload_bundle(name, data)
        else:
            bundle = data

        params = dict()
        if overwrite:
            params['update'] = 'overwrite'
        if charset is not None:
            params['charset'] = charset

        message = open(bundle)
        headers = {'Content-Type': 'application/zip',
                   'Accept': 'application/xml'}
        upload_url = url(self.service_url, ['workspaces', workspace,
                         'datastores', store, 'file.shp'], params)

        try:
            (headers, response) = self.http.request(upload_url, 'PUT',
                    message, headers)
            self._cache.clear()
            if headers.status != 201:
                raise UploadError(response)
        finally:
            unlink(bundle)
Esempio n. 25
0
 def reload(self):
     reload_url = url(self.service_url, ['reload'])
     response = self.http.request(reload_url, 'POST')
     self._cache.clear()
     return response
Esempio n. 26
0
 def href(self):
     return url(self.catalog.service_url,
         ["workspaces", self.workspace.name, "coveragestores"], dict(name=self.name))
Esempio n. 27
0
 def href(self):
     return url(self.catalog.service_url,
         ["workspaces", self.workspace.name, "datastores", self.name + ".xml"])
Esempio n. 28
0
 def coveragestore_url(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name, 'coveragestores.xml'])
Esempio n. 29
0
 def body_href(self):
     return url(self.catalog.service_url, ["styles", self.name + ".sld"])
Esempio n. 30
0
 def datastore_url(self):
     return url(self.catalog.service_url, ["workspaces", self.name, "datastores.xml"])
Esempio n. 31
0
 def href(self):
     return url(self.catalog.service_url, ['layers', self.name + '.xml'])
Esempio n. 32
0
 def coveragestore_url(self):
     return url(self.catalog.service_url, ['workspaces', self.name,
                'coveragestores.xml'])
Esempio n. 33
0
 def body_href(self):
     return url(self.catalog.service_url, ["styles", self.name + ".sld"])
Esempio n. 34
0
 def reload(self):
     reload_url = url(self.service_url, ['reload'])
     response = self.http.request(reload_url, 'POST')
     self._cache.clear()
     return response
Esempio n. 35
0
 def datastore_url(self):
     return url(self.catalog.service_url, ['workspaces', self.name,
                'datastores.xml'])
Esempio n. 36
0
 def href(self):
     return url(self.catalog.service_url, ["layers", self.name + ".xml"])
Esempio n. 37
0
 def coveragestore_url(self):
     return url(self.catalog.service_url, ["workspaces", self.name, "coveragestores.xml"])
Esempio n. 38
0
 def datastore_url(self):
     return url(self.catalog.service_url,
                ["workspaces", self.name, "datastores.xml"])
Esempio n. 39
0
 def href(self):
     path = [ "workspaces",
              self.workspace.name, "datastores"]
     query = dict(name=self.name)
     return url(self.catalog.service_url, path, query)
Esempio n. 40
0
 def body_href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.sld'])
Esempio n. 41
0
 def href(self):
     return url(self.catalog.service_url, ["styles", self.name + ".xml"])
Esempio n. 42
0
 def href(self):
     return url(self.catalog.service_url,
                ['layergroups', self.name + '.xml'])
Esempio n. 43
0
 def href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.xml'])
Esempio n. 44
0
 def get_styles(self):
     styles_url = url(self.service_url, ['styles.xml'])
     description = self.get_xml(styles_url)
     return [Style(self, s.find('name').text) for s in
             description.findall('style')]
Esempio n. 45
0
 def href(self):
     return url(self.catalog.service_url, ["layergroups", self.name + ".xml"])
Esempio n. 46
0
 def href(self):
     return url(self.catalog.service_url, ['workspaces', self.name + '.xml'
                ])
Esempio n. 47
0
 def href(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name + '.xml'])
Esempio n. 48
0
 def href(self):
     return url(self.catalog.service_url,
                ['workspaces', self.workspace.name, 'coveragestores'],
                dict(name=self.name))
Esempio n. 49
0
 def datastore_url(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name, 'datastores.xml'])
Esempio n. 50
0
 def body_href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.sld'])
Esempio n. 51
0
 def coveragestore_url(self):
     return url(self.catalog.service_url,
                ["workspaces", self.name, "coveragestores.xml"])
Esempio n. 52
0
 def get_styles(self):
     styles_url = url(self.service_url, ['styles.xml'])
     description = self.get_xml(styles_url)
     return [Style(self, s.find('name').text) for s in
             description.findall('style')]