Skip to content
Permalink
Browse files

restructured admintools (was geoservertools)

  • Loading branch information
volaya committed Nov 7, 2012
1 parent 6a2fdf5 commit 3c5de39a2b28d5423d65264c116c53322369d46b
Showing with 839 additions and 110 deletions.
  1. +1 −1 python/plugins/sextante/CMakeLists.txt
  2. +16 −13 ...ante/{servertools/GeoServerToolsAlgorithmProvider.py → admintools/AdminToolsAlgorithmProvider.py}
  3. +1 −1 python/plugins/sextante/{servertools → admintools}/CMakeLists.txt
  4. 0 python/plugins/sextante/{servertools → admintools}/CreateMosaicDatastore.py
  5. +3 −3 python/plugins/sextante/{servertools/StyleGeoServerLayer.py → admintools/CreateStyleGeoServer.py}
  6. +2 −5 python/plugins/sextante/{servertools → admintools}/CreateWorkspace.py
  7. +1 −1 python/plugins/sextante/{servertools → admintools}/DeleteDatastore.py
  8. +1 −1 python/plugins/sextante/{servertools → admintools}/DeleteWorkspace.py
  9. +1 −1 python/plugins/sextante/{servertools → admintools}/GeoServerToolsAlgorithm.py
  10. +2 −2 python/plugins/sextante/{servertools → admintools}/ImportRasterIntoGeoServer.py
  11. +1 −1 python/plugins/sextante/{servertools → admintools}/ImportVectorIntoGeoServer.py
  12. +143 −0 python/plugins/sextante/admintools/PostGISExecuteSQL.py
  13. 0 python/plugins/sextante/{servertools → admintools}/__init__.py
  14. +3 −0 python/plugins/sextante/admintools/geoserver/CMakeLists.txt
  15. 0 python/plugins/sextante/{servertools → admintools}/geoserver/__init__.py
  16. +7 −7 python/plugins/sextante/{servertools → admintools}/geoserver/catalog.py
  17. +2 −2 python/plugins/sextante/{servertools → admintools}/geoserver/layer.py
  18. +1 −1 python/plugins/sextante/{servertools → admintools}/geoserver/layergroup.py
  19. 0 python/plugins/sextante/{servertools → admintools}/geoserver/namespace.py
  20. +1 −1 python/plugins/sextante/{servertools → admintools}/geoserver/resource.py
  21. +3 −3 python/plugins/sextante/{servertools → admintools}/geoserver/store.py
  22. +1 −1 python/plugins/sextante/{servertools → admintools}/geoserver/style.py
  23. 0 python/plugins/sextante/{servertools → admintools}/geoserver/support.py
  24. 0 python/plugins/sextante/{servertools → admintools}/geoserver/util.py
  25. +1 −1 python/plugins/sextante/{servertools → admintools}/geoserver/workspace.py
  26. +3 −0 python/plugins/sextante/admintools/httplib2/CMakeLists.txt
  27. 0 python/plugins/sextante/{servertools → admintools}/httplib2/__init__.py
  28. 0 python/plugins/sextante/{servertools → admintools}/httplib2/iri2uri.py
  29. 0 python/plugins/sextante/{servertools → admintools}/httplib2/socks.py
  30. +643 −0 python/plugins/sextante/admintools/postgis_utils.py
  31. +2 −2 python/plugins/sextante/core/Sextante.py
  32. +0 −57 python/plugins/sextante/database/DatabaseToolsAlgorithmProvider.py
  33. BIN python/plugins/sextante/images/postgis.png
  34. +0 −3 python/plugins/sextante/servertools/geoserver/CMakeLists.txt
  35. +0 −3 python/plugins/sextante/servertools/httplib2/CMakeLists.txt
@@ -1,5 +1,6 @@
SET (SEXTANTE_PLUGIN_DIR ${QGIS_DATA_DIR}/python/plugins/sextante)

ADD_SUBDIRECTORY(admintools)
ADD_SUBDIRECTORY(algs)
ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(ftools)
@@ -18,7 +19,6 @@ ADD_SUBDIRECTORY(pymorph)
ADD_SUBDIRECTORY(r)
ADD_SUBDIRECTORY(saga)
ADD_SUBDIRECTORY(script)
ADD_SUBDIRECTORY(servertools)
ADD_SUBDIRECTORY(taudem)
#ADD_SUBDIRECTORY(tests)

@@ -2,7 +2,7 @@

"""
***************************************************************************
GeoServerToolsAlgorithmProvider.py
AdminToolsAlgorithmProvider.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.admintools.PostGISExecuteSQL import PostGISExecuteSQL

__author__ = 'Victor Olaya'
__date__ = 'October 2012'
@@ -25,22 +26,22 @@


import os
from sextante.servertools.CreateWorkspace import CreateWorkspace
from sextante.servertools.ImportVectorIntoGeoServer import ImportVectorIntoGeoServer
from sextante.servertools.ImportRasterIntoGeoServer import ImportRasterIntoGeoServer
from sextante.servertools.DeleteWorkspace import DeleteWorkspace
from sextante.servertools.DeleteDatastore import DeleteDatastore
from sextante.servertools.StyleGeoServerLayer import StyleGeoServerLayer
from sextante.admintools.ImportVectorIntoGeoServer import ImportVectorIntoGeoServer
from sextante.admintools.CreateWorkspace import CreateWorkspace
from sextante.admintools.ImportRasterIntoGeoServer import ImportRasterIntoGeoServer
from sextante.admintools.DeleteWorkspace import DeleteWorkspace
from sextante.admintools.DeleteDatastore import DeleteDatastore
from sextante.admintools.CreateStyleGeoServer import CreateStyleGeoServer
from sextante.core.AlgorithmProvider import AlgorithmProvider
from PyQt4 import QtGui

class GeoServerToolsAlgorithmProvider(AlgorithmProvider):
class AdminToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.alglist = [ImportVectorIntoGeoServer(), ImportRasterIntoGeoServer(),
CreateWorkspace(), DeleteWorkspace(), DeleteDatastore(),
StyleGeoServerLayer()]#, TruncateSeedGWC()]
CreateStyleGeoServer(), PostGISExecuteSQL()]#, TruncateSeedGWC()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -51,13 +52,15 @@ def unload(self):


def getName(self):
return "geoserver"
return "admintools"

def getDescription(self):
return "Geoserver management tools"
return "Administration tools"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/geoserver.png")
#===========================================================================
# def getIcon(self):
# return QtGui.QIcon(os.path.dirname(__file__) + "/../images/geoserver.png")
#===========================================================================

def _loadAlgorithms(self):
self.algs = self.alglist
@@ -3,4 +3,4 @@ FILE(GLOB PY_FILES *.py)
ADD_SUBDIRECTORY(geoserver)
ADD_SUBDIRECTORY(httplib2)

PLUGIN_INSTALL(sextante servertools ${PY_FILES})
PLUGIN_INSTALL(sextante admintools ${PY_FILES})
@@ -2,7 +2,7 @@

"""
***************************************************************************
DeleteDatastore.py
CreateStyleGeoServer.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya
@@ -25,12 +25,12 @@

from qgis.core import *
from sextante.parameters.ParameterString import ParameterString
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.parameters.ParameterFile import ParameterFile
from sextante.parameters.ParameterBoolean import ParameterBoolean


class StyleGeoServerLayer(GeoServerToolsAlgorithm):
class CreateStyleGeoServer(GeoServerToolsAlgorithm):

STYLE = "STYLE"
OVERWRITE = "OVERWRITE"
@@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.outputs.OutputString import OutputString

__author__ = 'Victor Olaya'
__date__ = 'October 2012'
@@ -29,15 +27,14 @@
from qgis.core import *
from PyQt4 import QtGui
from sextante.parameters.ParameterString import ParameterString
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.outputs.OutputString import OutputString

class CreateWorkspace(GeoServerToolsAlgorithm):

WORKSPACE = "WORKSPACE"
WORKSPACEURI = "WORKSPACEURI"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/geoserver.png")

def processAlgorithm(self, progress):
self.createCatalog()
workspaceName = self.getParameterValue(self.WORKSPACE)
@@ -25,7 +25,7 @@

from qgis.core import *
from sextante.parameters.ParameterString import ParameterString
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm

class DeleteDatastore(GeoServerToolsAlgorithm):

@@ -16,7 +16,6 @@
* *
***************************************************************************
"""
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm

__author__ = 'Victor Olaya'
__date__ = 'October 2012'
@@ -26,6 +25,7 @@

from qgis.core import *
from sextante.parameters.ParameterString import ParameterString
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm

class DeleteWorkspace(GeoServerToolsAlgorithm):

@@ -17,7 +17,7 @@
***************************************************************************
"""
from sextante.parameters.ParameterString import ParameterString
from sextante.servertools.geoserver.catalog import Catalog
from sextante.admintools.geoserver.catalog import Catalog

__author__ = 'Victor Olaya'
__date__ = 'October 2012'
@@ -25,7 +25,7 @@

from qgis.core import *
from sextante.parameters.ParameterString import ParameterString
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.parameters.ParameterRaster import ParameterRaster


@@ -44,7 +44,7 @@ def processAlgorithm(self, progress):
name = self.getParameterValue(self.NAME)
workspaceName = self.getParameterValue(self.WORKSPACE)
filename = self.exportRasterLayer(inputFilename)
workspace = self.catalog.get_workspace(workspaceName)
workspace = self.catalog.get_workspace(workspaceName)
ds = self.catalog.create_coveragestore2(name, workspace)
ds.data_url = "file:" + filename;
self.catalog.save(ds)
@@ -29,7 +29,7 @@
from sextante.core.QGisLayers import QGisLayers
from sextante.core.LayerExporter import LayerExporter
from sextante.parameters.ParameterString import ParameterString
from sextante.servertools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm

class ImportVectorIntoGeoServer(GeoServerToolsAlgorithm):

@@ -0,0 +1,143 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
PostGISExecuteSQL.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from sextante.admintools import postgis_utils
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
import PyQt4

__author__ = 'Victor Olaya'
__date__ = 'October 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.parameters.ParameterString import ParameterString
from sextante.admintools.GeoServerToolsAlgorithm import GeoServerToolsAlgorithm

class PostGISExecuteSQL(GeoServerToolsAlgorithm):

DATABASE = "DATABASE"
SQL = "SQL"
TABLENAME = "TABLENAME"

def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/../images/postgis.png")

def processAlgorithm(self, progress):

connection = self.getParameterValue(self.DATABASE)
settings = QSettings()
mySettings = "/PostgreSQL/connections/"+ connection
database = settings.value(mySettings+"/database").toString()
username = settings.value(mySettings+"/username").toString()
host = settings.value(mySettings+"/host").toString()
port = settings.value(mySettings+"/port").toString()
password = settings.value(mySettings+"/password").toString()

# connect to DB
try:
self.db = postgis_utils.GeoDB(host=host, port=port, dbname=database, user=username, passwd=password)
except postgis_utils.DbError, e:
raise GeoAlgorithmExecutionException("Couldn't connect to database:\n"+e.message)

## Set up sql statement for geoprocess
newTbl = self.getParameterValue(self.TABLENAME);
newTbl.replace(" ", "")
sqlNewTbl = str("CREATE TABLE ") + str(newTbl) + " as "
txtSQL = self.getParameterValue(self.SQL)
txtSQL = sqlNewTbl + txtSQL
sqlArray = txtSQL.split("\n")
sqlString = ""
for i in range(0,sqlArray.count()):
sqlString = sqlString + sqlArray[i] + " "

## Run query
try:
self.db._exec_sql_and_commit(str(sqlString))
except postgis_utils.DbError, e:
raise GeoAlgorithmExecutionException("Couldn't connect to database:\n"+e.message)

try: #first try
dbGeoTbls = self.db.list_geotables(self.cmbSchema.currentText())
except postgis_utils.DbError, e:
raise GeoAlgorithmExecutionException("Couldn't connect to database:\n"+e.message)

for i in range(0,len(dbGeoTbls)):
if dbGeoTbls[i][0]==newTbl:
if dbGeoTbls[i][7]=="geometry":
geocol = str(dbGeoTbls[i][6])

schName = self.cmbSchema.currentText()

## Update the geometry_columns table
geocolSQL = "SELECT ST_Dimension(" + geocol + "), ST_SRID(" + geocol + "), GeometryType(" + geocol + ") FROM " + newTbl + ";"
c = self.db.con.cursor()
self.db._exec_sql(c, str(geocolSQL))
geomPar = c.fetchone()

## Setup sql statement to update geometry_columns
geocolupdate = "INSERT INTO geometry_columns "
geocolupdate = geocolupdate + "(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, type) VALUES"
geocolupdate = geocolupdate + "('', 'public', '" + newTbl + "', '" + geocol + "', '" + str(geomPar[0]) + "', '" + str(geomPar[1]) + "', '" + str(geomPar[2])
geocolupdate = geocolupdate + "');"
self.db._exec_sql_and_commit(str(geocolupdate))

## Add remaining constraints for dimension, geometry type and srid
pkeySQL = "ALTER TABLE " + schName + "." + newTbl + " ADD CONSTRAINT " + newTbl + "_pkey PRIMARY KEY(pgid);"
dimSQL = "ALTER TABLE " + schName + "." + newTbl + " ADD CONSTRAINT enforce_dims_" + geocol + " CHECK (ndims(" + geocol + ") = " + str(geomPar[0]) + ");"
gtypSQL = "ALTER TABLE " + schName + "." + newTbl + " ADD CONSTRAINT enforce_geotype_" + geocol + " CHECK (geometrytype(" + geocol + ") = '" + str(geomPar[2]) + "'::text OR " + geocol + " IS NULL);"
sridSQL = "ALTER TABLE " + schName + "." + newTbl + " ADD CONSTRAINT enforce_srid_" + geocol + " CHECK (srid(" + geocol + ") = " + str(geomPar[1]) + ");"

try: #second try
self.db._exec_sql_and_commit(str(pkeySQL))
self.db._exec_sql_and_commit(str(dimSQL))
self.db._exec_sql_and_commit(str(gtypSQL))
self.db._exec_sql_and_commit(str(sridSQL))
except postgis_utils.DbError, e:
QMessageBox.critical(self, "error", "Couldn't connect to database:\n"+e.message)
return

#=======================================================================
# ## ## Add resulting data set if Add layer checkbox is selected
# if self.actionAddData.isChecked():
# ## Set up data source and add to QGIS view
# uri = QgsDataSourceURI()
# uri.setConnection(str(self.db.host), str(self.db.port), str(self.db.dbname), str(self.db.user), str(self.db.passwd))
# uri.setDataSource(schName, newTbl, geocol)
# dbSchemas = self.db.list_schemas()
# for s in range(0,len(dbSchemas)):
# dbSchema = dbSchemas[s][1]
# if dbSchema==schName:
# dbOwner = dbSchemas[s][2]
# self.iface.addVectorLayer(uri.uri(), newTbl, dbOwner)
#=======================================================================

def defineCharacteristics(self):
self.addBaseParameters()
self.name = "PostGIS execute SQL"
self.group = "PostGIS management tools"
self.addParameter(ParameterString(self.DATABASE, "Database"))
self.addParameter(ParameterString(self.TABLENAME, "Name for new table"))
self.addParameter(ParameterString(self.SQL, "SQL query"))



@@ -0,0 +1,3 @@
FILE(GLOB PY_FILES *.py)

PLUGIN_INSTALL(sextante admintools/geoserver ${PY_FILES})
@@ -1,17 +1,17 @@
from datetime import datetime, timedelta
import logging
from sextante.servertools.geoserver.layer import Layer
from sextante.servertools.geoserver.store import coveragestore_from_index, datastore_from_index, \
from sextante.admintools.geoserver.layer import Layer
from sextante.admintools.geoserver.store import coveragestore_from_index, datastore_from_index, \
UnsavedDataStore, UnsavedCoverageStore
from sextante.servertools.geoserver.style import Style
from sextante.servertools.geoserver.support import prepare_upload_bundle, url
from sextante.servertools.geoserver.layergroup import LayerGroup, UnsavedLayerGroup
from sextante.servertools.geoserver.workspace import workspace_from_index, Workspace
from sextante.admintools.geoserver.style import Style
from sextante.admintools.geoserver.support import prepare_upload_bundle, url
from sextante.admintools.geoserver.layergroup import LayerGroup, UnsavedLayerGroup
from sextante.admintools.geoserver.workspace import workspace_from_index, Workspace
from os import unlink
from xml.etree.ElementTree import XML
from xml.parsers.expat import ExpatError
from urlparse import urlparse
from sextante.servertools import httplib2
from sextante.admintools import httplib2

logger = logging.getLogger("gsconfig.catalog")

@@ -1,5 +1,5 @@
from sextante.servertools.geoserver.support import ResourceInfo, xml_property, write_bool, url
from sextante.servertools.geoserver.style import Style
from sextante.admintools.geoserver.support import ResourceInfo, xml_property, write_bool, url
from sextante.admintools.geoserver.style import Style

class _attribution(object):
def __init__(self, title, width, height):
@@ -1,4 +1,4 @@
from sextante.servertools.geoserver.support import ResourceInfo, bbox, write_bbox, \
from sextante.admintools.geoserver.support import ResourceInfo, bbox, write_bbox, \
write_string, xml_property, url

def _maybe_text(n):
@@ -1,4 +1,4 @@
from sextante.servertools.geoserver.support import ResourceInfo, xml_property, write_string, bbox, \
from sextante.admintools.geoserver.support import ResourceInfo, xml_property, write_string, bbox, \
write_bbox, string_list, write_string_list, attribute_list, write_bool, url

def md_link(node):

0 comments on commit 3c5de39

Please sign in to comment.
You can’t perform that action at this time.