Example #1
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
Example #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
Example #3
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')
     ]
Example #4
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)
Example #5
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
Example #6
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
Example #7
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
Example #8
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
Example #9
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'datastores',
         self.store.name,
         'featuretypes',
         self.name + '.xml',
         ])
Example #10
0
 def href(self):
     return url(self.catalog.service_url, [
         'workspaces',
         self.workspace.name,
         'coveragestores',
         self.store.name,
         'coverages',
         self.name + '.xml',
         ])
Example #11
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)
Example #12
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
Example #13
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)
Example #14
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)
Example #15
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')]
Example #16
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')]
Example #17
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
Example #18
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)
Example #19
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)
Example #20
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)
Example #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
        #print name
        #print workspace.name
        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)
Example #22
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)
Example #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)
Example #24
0
 def body_href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.sld'])
Example #25
0
 def datastore_url(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name, 'datastores.xml'])
Example #26
0
 def reload(self):
     reload_url = url(self.service_url, ['reload'])
     response = self.http.request(reload_url, 'POST')
     self._cache.clear()
     return response
Example #27
0
 def body_href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.sld'])
Example #28
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")]
Example #29
0
 def reload(self):
     reload_url = url(self.service_url, ['reload'])
     response = self.http.request(reload_url, "POST")
     self._cache.clear()
     return response
Example #30
0
 def coveragestore_url(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name, 'coveragestores.xml'])
Example #31
0
 def coveragestore_url(self):
     return url(self.catalog.service_url, ['workspaces', self.name,
                'coveragestores.xml'])
Example #32
0
 def href(self):
     return url(self.catalog.service_url, ['styles', self.name + '.xml'])
Example #33
0
 def datastore_url(self):
     return url(self.catalog.service_url, ['workspaces', self.name,
                'datastores.xml'])
Example #34
0
 def href(self):
     return url(self.catalog.service_url, ['layergroups', self.name + '.xml'
                ])
Example #35
0
 def href(self):
     return url(self.catalog.service_url, ['layers', self.name + '.xml'])
Example #36
0
 def href(self):
     return url(self.catalog.service_url, ['workspaces',
                self.workspace.name, 'coveragestores'],
                dict(name=self.name))
Example #37
0
 def href(self):
     return url(self.catalog.service_url, ['workspaces', self.name + '.xml'
                ])
Example #38
0
 def href(self):
     path = ['workspaces', self.workspace.name, 'datastores']
     query = dict(name=self.name)
     return url(self.catalog.service_url, path, query)
Example #39
0
 def href(self):
     return url(self.catalog.service_url,
                ['workspaces', self.name + '.xml'])