Skip to content

Commit

Permalink
[processing] move spatialite and postgis utils into tools package
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jun 1, 2016
1 parent 6e13020 commit 57b1618
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/ImportIntoPostGIS.py
Expand Up @@ -35,8 +35,7 @@
from processing.core.parameters import ParameterString from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterSelection from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterTableField from processing.core.parameters import ParameterTableField
from processing.tools import dataobjects from processing.tools import dataobjects, postgis
from processing.algs.qgis import postgis_utils




class ImportIntoPostGIS(GeoAlgorithm): class ImportIntoPostGIS(GeoAlgorithm):
Expand Down Expand Up @@ -117,9 +116,9 @@ def processAlgorithm(self, progress):
providerName = 'postgres' providerName = 'postgres'


try: try:
db = postgis_utils.GeoDB(host=host, port=port, dbname=database, db = postgis.GeoDB(host=host, port=port, dbname=database,
user=username, passwd=password) user=username, passwd=password)
except postgis_utils.DbError as e: except postgis.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr("Couldn't connect to database:\n%s") % unicode(e)) self.tr("Couldn't connect to database:\n%s") % unicode(e))


Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/qgis/PostGISExecuteSQL.py
Expand Up @@ -30,7 +30,7 @@
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterString from processing.core.parameters import ParameterString
from processing.algs.qgis import postgis_utils from processing.tools import postgis




class PostGISExecuteSQL(GeoAlgorithm): class PostGISExecuteSQL(GeoAlgorithm):
Expand Down Expand Up @@ -58,15 +58,15 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Wrong database connection name: %s' % connection)) self.tr('Wrong database connection name: %s' % connection))
try: try:
self.db = postgis_utils.GeoDB(host=host, port=port, self.db = postgis.GeoDB(host=host, port=port,
dbname=database, user=username, passwd=password) dbname=database, user=username, passwd=password)
except postgis_utils.DbError as e: except postgis.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr("Couldn't connect to database:\n%s") % unicode(e)) self.tr("Couldn't connect to database:\n%s") % unicode(e))


sql = self.getParameterValue(self.SQL).replace('\n', ' ') sql = self.getParameterValue(self.SQL).replace('\n', ' ')
try: try:
self.db._exec_sql_and_commit(unicode(sql)) self.db._exec_sql_and_commit(unicode(sql))
except postgis_utils.DbError as e: except postgis.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Error executing SQL:\n%s') % unicode(e)) self.tr('Error executing SQL:\n%s') % unicode(e))
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/PostgisTableSelector.py
Expand Up @@ -31,8 +31,8 @@
from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QTreeWidgetItem, QMessageBox from qgis.PyQt.QtWidgets import QTreeWidgetItem, QMessageBox
from qgis.PyQt import uic from qgis.PyQt import uic
from processing.algs.qgis.postgis_utils import GeoDB
from qgis.core import QgsDataSourceURI, QgsCredentials from qgis.core import QgsDataSourceURI, QgsCredentials
from processing.tools.postgis import GeoDB


pluginPath = os.path.split(os.path.dirname(__file__))[0] pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType( WIDGET, BASE = uic.loadUiType(
Expand Down
Expand Up @@ -2,7 +2,7 @@


""" """
*************************************************************************** ***************************************************************************
postgis_utils.py postgis.py
--------------------- ---------------------
Date : November 2012 Date : November 2012
Copyright : (C) 2012 by Martin Dobias Copyright : (C) 2012 by Martin Dobias
Expand Down
Expand Up @@ -2,7 +2,7 @@


""" """
*************************************************************************** ***************************************************************************
spatialite_utils.py spatialite.py
--------------------- ---------------------
Date : November 2015 Date : November 2015
Copyright : (C) 2015 by René-Luc Dhont Copyright : (C) 2015 by René-Luc Dhont
Expand Down
16 changes: 7 additions & 9 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -16,8 +16,6 @@
* * * *
*************************************************************************** ***************************************************************************
""" """
from processing.algs.qgis import postgis_utils
from processing.algs.qgis import spatialite_utils


__author__ = 'Victor Olaya' __author__ = 'Victor Olaya'
__date__ = 'February 2013' __date__ = 'February 2013'
Expand All @@ -43,7 +41,7 @@


from processing.core.ProcessingConfig import ProcessingConfig from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.tools import dataobjects from processing.tools import dataobjects, spatialite, postgis




GEOM_TYPE_MAP = { GEOM_TYPE_MAP = {
Expand Down Expand Up @@ -581,16 +579,16 @@ def __init__(self, destination, encoding, fields, geometryType,
raise GeoAlgorithmExecutionException("Couldn't connect to database") raise GeoAlgorithmExecutionException("Couldn't connect to database")
print uri.uri() print uri.uri()
try: try:
db = postgis_utils.GeoDB(host=uri.host(), port=int(uri.port()), db = postgis.GeoDB(host=uri.host(), port=int(uri.port()),
dbname=uri.database(), user=user, passwd=passwd) dbname=uri.database(), user=user, passwd=passwd)
except postgis_utils.DbError as e: except postgis.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
"Couldn't connect to database:\n%s" % e.message) "Couldn't connect to database:\n%s" % e.message)


def _runSQL(sql): def _runSQL(sql):
try: try:
db._exec_sql_and_commit(unicode(sql)) db._exec_sql_and_commit(unicode(sql))
except postgis_utils.DbError as e: except postgis.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
'Error creating output PostGIS table:\n%s' % e.message) 'Error creating output PostGIS table:\n%s' % e.message)


Expand All @@ -612,15 +610,15 @@ def _runSQL(sql):
uri = QgsDataSourceURI(self.destination[len(self.SPATIALITE_LAYER_PREFIX):]) uri = QgsDataSourceURI(self.destination[len(self.SPATIALITE_LAYER_PREFIX):])
print uri.uri() print uri.uri()
try: try:
db = spatialite_utils.GeoDB(uri=uri) db = spatialite.GeoDB(uri=uri)
except spatialite_utils.DbError as e: except spatialite.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
"Couldn't connect to database:\n%s" % e.message) "Couldn't connect to database:\n%s" % e.message)


def _runSQL(sql): def _runSQL(sql):
try: try:
db._exec_sql_and_commit(unicode(sql)) db._exec_sql_and_commit(unicode(sql))
except spatialite_utils.DbError as e: except spatialite.DbError as e:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
'Error creating output Spatialite table:\n%s' % unicode(e)) 'Error creating output Spatialite table:\n%s' % unicode(e))


Expand Down

0 comments on commit 57b1618

Please sign in to comment.