コード例 #1
0
ファイル: geoserver.py プロジェクト: TesiFAO/p-geo
 def set_default_style(self, stylename, layername, enabled=True):
     """
     Method used to change the default style of a layer
     :param stylename: the name of the style to set ad default one
     :param layername: the name of the layer
     :param enabled: enable/disable the style
     :return:
     """
     # curl -v -u $GEOSERVER_PASSWORD -XPUT -H "Content-type: text/xml" -d "<layer><defaultStyle><name>$DEFAULT_STYLE</name></defaultStyle><enabled>$ENABLED</enabled></layer>" $GEOSERVER_URL/rest/layers/$GEOSERVER_WORKSPACE:$NAME
     headers = {
         "Content-type": "application/xml",
         "Accept": "application/xml"
     }
     print layername
     xml = "<layer><defaultStyle><name>{0}</name></defaultStyle><enabled>{1}</enabled></layer>".format(unicode(stylename).lower(),  unicode(str(enabled).upper()))
     cs_url = url(self.service_url, ["layers", layername])
     headers, response = self.http.request(cs_url, "PUT", xml, headers)
     print cs_url
     if headers.status == 200:
         # reload geoserver cluster
         self.reload_configuration_geoserver_slaves()
         return True
     else:
         print headers.status, " ", response
         return False
コード例 #2
0
ファイル: geoserver.py プロジェクト: TesiFAO/p-geo
 def check_if_coverage_exist(self, name, workspace=None):
     if workspace is None:
         workspace = self.get_default_workspace()
     cs_url = url(self.service_url, ["workspaces", workspace, "coveragestores", name])
     response, content = self.http.request(cs_url, "GET")
     if response.status == 200:
         return True
     elif response.status == 404:
         return False
     return False
コード例 #3
0
ファイル: geoserver.py プロジェクト: TesiFAO/p-geo
 def reload_configuration_geoserver_slaves(self, force_master_reload=False):
     geoserver_cluster = self.config.get("geoserver_slaves")
     if (force_master_reload is True): geoserver_cluster.append(self.config.get("geoserver_master"))
     for geoserver in geoserver_cluster:
         cs_url =  url(geoserver, ["reload?recurse=true"])
         headers, response = self.http.request(cs_url, "POST")
         self.logger.info(headers)
         if headers.status == 200:
             return True
         else:
             return False
コード例 #4
0
ファイル: geoserver.py プロジェクト: TesiFAO/p-geo
    def delete_coveragestore(self, layername, workspace=None,purge=True, recurse=True):
        if workspace is None:
            workspace = self.get_default_workspace()

        # TODO: it makes two, calls, so probably it's better just handle the delete code
        if self.check_if_coverage_exist(layername, workspace):
            cs_url = url(self.service_url, ["workspaces", workspace, "coveragestores", layername])
            self.logger.info(cs_url);
            #headers, response = self.http.request(cs_url, "DELETE")

            return self.delete(cs_url, purge, recurse)
        else:
            return "NO COVERAGE STORE AVAILABLE"
コード例 #5
0
ファイル: geoserver.py プロジェクト: TesiFAO/p-geo
 def publish_postgis_table(self, datastore, name):
     """
     :param datastore: datastore stored in geoserver
     :param name: name of the table in postgis
     :return:
     """
     #curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>buildings</name></featureType>"
     #http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
     headers = {
         "Content-type": "application/xml",
         "Accept": "application/xml"
     }
     xml = "<featureType><name>{0}</name></featureType>".format(unicode(name).lower())
     cs_url = url(self.service_url, ["workspaces", datastore['workspace'], "datastores", datastore['datastore'], 'featuretypes'])
     headers, response = self.http.request(cs_url, "POST", xml, headers)
     self.logger.info(headers)
     if headers.status == 201:
         # reload geoserver cluster
         self.reload_configuration_geoserver_slaves()
         return True
     else:
         return False