Exemple #1
0
    def create_pg_featuretype(self,
                              name,
                              store,
                              workspace=None,
                              srs="EPSG:4326"):

        if workspace is None:
            workspace = self.get_default_workspace()

        params = dict()
        workspace = util.name(workspace)
        store = util.name(store)
        ds_url = url(
            self.service_url,
            ["workspaces", workspace, "datastores", store, "featuretypes.xml"],
            params)

        #create the datastore
        headers = {"Content-type": "text/xml"}
        xml = ("<featureType>\n"
               "<enabled>true</enabled>\n"
               "<metadata />\n"
               "<keywords><string>KEYWORD</string></keywords>\n"
               "<projectionPolicy>REPROJECT_TO_DECLARED</projectionPolicy>\n"
               "<title>" + name + "</title>\n"
               "<name>" + name + "</name>\n"
               "<srs>" + srs + "</srs>"
               "</featureType>")

        headers, response = self.http.request(ds_url, "POST", xml, headers)

        if headers.status != 201 and headers.status != 200:
            raise UploadError(response)
    def create_pg_featuretype(self, name, store, workspace=None, srs = "EPSG:4326"):
        
        if workspace is None:
            workspace = self.get_default_workspace()
            
        params = dict()
        workspace = util.name(workspace)
        store = util.name(store)
        ds_url = url(self.service_url,
            ["workspaces", workspace, "datastores", store, "featuretypes.xml"], params)

        #create the datastore
        headers = {
            "Content-type": "text/xml"
        }
        xml = ("<featureType>\n" 
        "<enabled>true</enabled>\n" 
        "<metadata />\n" 
        "<keywords><string>KEYWORD</string></keywords>\n" 
        "<projectionPolicy>REPROJECT_TO_DECLARED</projectionPolicy>\n" 
        "<title>" + name + "</title>\n" 
        "<name>" + name +"</name>\n"         
        "<srs>" + srs +"</srs>" 
        "</featureType>")
        
        headers, response = self.http.request(ds_url, "POST", xml, headers)
               
        if headers.status != 201 and headers.status != 200:            
            raise UploadError(response)
    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 = util.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)
 def __init__(self, element, icon = None, text = None): 
     QtGui.QTreeWidgetItem.__init__(self) 
     self.element = element    
     self.setData(0, QtCore.Qt.UserRole, element)            
     text = text if text is not None else util.name(element)
     self.setText(0, text)      
     if icon is not None:
         self.setIcon(0, icon)   
     self.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)               
Exemple #5
0
 def __init__(self, element, icon=None, text=None):
     QtGui.QTreeWidgetItem.__init__(self)
     self.element = element
     self.setData(0, QtCore.Qt.UserRole, element)
     text = text if text is not None else util.name(element)
     self.setText(0, text)
     if icon is not None:
         self.setIcon(0, icon)
     self.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
Exemple #6
0
    def create_shp_featurestore(self,
                                name,
                                data,
                                workspace=None,
                                overwrite=False,
                                charset=None):
        '''creates a shapefile-based datastore'''
        if workspace is None:
            workspace = self.get_default_workspace()
        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

        workspace = util.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:
            try:
                unlink(archive)
            except WindowsError:
                #FIXME: handle this better
                pass
    def create_shp_featurestore(self, name, data, workspace=None, overwrite=False, charset=None):
        '''creates a shapefile-based datastore'''
        if workspace is None:
            workspace = self.get_default_workspace()
        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
        
        workspace = util.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:
            try:
                unlink(archive)
            except WindowsError:
                #FIXME: handle this better
                pass
Exemple #8
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 = util.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)
    def create_pg_featurestore(self, name, workspace=None, overwrite=False, 
                               host="localhost", port = 5432 , database="db", schema="public", user="******", passwd=""):
        '''creates a postgis-based datastore'''
        
        if user == "" and passwd == "":
            raise Exception("Both username and password are empty strings. Use a different user/passwd combination")
        
        if workspace is None:
            workspace = self.get_default_workspace()
        try:
            store = self.get_store(name, workspace)
        except FailedRequestError:
            store = None
            
        if store is not None:              
            if overwrite:
                #if the existing store is the same we are trying to add, we do nothing
                params = store.connection_parameters                                
                if (str(params['port']) == str(port) and params['database'] == database and params['host'] == host
                        and params['user'] == user):
                    print "db connection already exists"
                    return
            else:                          
                msg = "There is already a store named " + name
                if workspace:
                    msg += " in " + str(workspace)
                raise ConflictingDataError(msg)            
            
        workspace = util.name(workspace)
        params = dict()
        

        #create the datastore
        headers = {
            "Content-type": "text/xml"
        }

        if user is None:
            raise Exception("Undefined user")
        
        xml = ("<dataStore>\n"
                "<name>" + name + "</name>\n"
                "<connectionParameters>"
                "<host>" + host + "</host>\n"
                "<port>" + str(port) + "</port>\n"
                "<database>" + database + "</database>\n"
                "<schema>" + schema + "</schema>\n"
                "<user>" + user + "</user>\n"
                "<passwd>" + passwd + "</passwd>\n"
                "<dbtype>postgis</dbtype>\n"
                "</connectionParameters>\n"
                "</dataStore>")
        
        if store is not None:
            ds_url = url(self.service_url,
                         ["workspaces", workspace, "datastores", name], params)
            headers, response = self.http.request(ds_url, "PUT", xml, headers)
        else:
            ds_url = url(self.service_url,
                         ["workspaces", workspace, "datastores.xml"], params)
            headers, response = self.http.request(ds_url, "POST", xml, headers)

        self._cache.clear()
        if headers.status != 201 and headers.status != 200:            
            raise UploadError(response)
Exemple #10
0
 def refresh(self):
     text = self._text if self._text is not None else util.name(
         self.element)
     self.setText(0, text)
Exemple #11
0
    def create_pg_featurestore(self,
                               name,
                               workspace=None,
                               overwrite=False,
                               host="localhost",
                               port=5432,
                               database="db",
                               schema="public",
                               user="******",
                               passwd=""):
        '''creates a postgis-based datastore'''

        if user == "" and passwd == "":
            raise Exception(
                "Both username and password are empty strings. Use a different user/passwd combination"
            )

        if workspace is None:
            workspace = self.get_default_workspace()
        try:
            store = self.get_store(name, workspace)
        except FailedRequestError:
            store = None

        if store is not None:
            if overwrite:
                #if the existing store is the same we are trying to add, we do nothing
                params = store.connection_parameters
                if (str(params['port']) == str(port)
                        and params['database'] == database
                        and params['host'] == host and params['user'] == user):
                    print "db connection already exists"
                    return
            else:
                msg = "There is already a store named " + name
                if workspace:
                    msg += " in " + str(workspace)
                raise ConflictingDataError(msg)

        workspace = util.name(workspace)
        params = dict()

        #create the datastore
        headers = {"Content-type": "text/xml"}

        if user is None:
            raise Exception("Undefined user")

        xml = ("<dataStore>\n"
               "<name>" + name + "</name>\n"
               "<connectionParameters>"
               "<host>" + host + "</host>\n"
               "<port>" + str(port) + "</port>\n"
               "<database>" + database + "</database>\n"
               "<schema>" + schema + "</schema>\n"
               "<user>" + user + "</user>\n"
               "<passwd>" + passwd + "</passwd>\n"
               "<dbtype>postgis</dbtype>\n"
               "</connectionParameters>\n"
               "</dataStore>")

        if store is not None:
            ds_url = url(self.service_url,
                         ["workspaces", workspace, "datastores", name], params)
            headers, response = self.http.request(ds_url, "PUT", xml, headers)
        else:
            ds_url = url(self.service_url,
                         ["workspaces", workspace, "datastores.xml"], params)
            headers, response = self.http.request(ds_url, "POST", xml, headers)

        self._cache.clear()
        if headers.status != 201 and headers.status != 200:
            raise UploadError(response)
 def refresh(self):
     text = self._text if self._text is not None else util.name(self.element)
     self.setText(0, text)