Skip to content
Permalink
Browse files

[processing] move spatialite and postgis utils into tools package

  • Loading branch information
alexbruy committed Jun 1, 2016
1 parent 6e13020 commit 57b16187e6ec9336983c4b8bc830b438368b996a
@@ -35,8 +35,7 @@
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterTableField
from processing.tools import dataobjects
from processing.algs.qgis import postgis_utils
from processing.tools import dataobjects, postgis


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

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

@@ -30,7 +30,7 @@
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterString
from processing.algs.qgis import postgis_utils
from processing.tools import postgis


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

sql = self.getParameterValue(self.SQL).replace('\n', ' ')
try:
self.db._exec_sql_and_commit(unicode(sql))
except postgis_utils.DbError as e:
except postgis.DbError as e:
raise GeoAlgorithmExecutionException(
self.tr('Error executing SQL:\n%s') % unicode(e))
@@ -31,8 +31,8 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QTreeWidgetItem, QMessageBox
from qgis.PyQt import uic
from processing.algs.qgis.postgis_utils import GeoDB
from qgis.core import QgsDataSourceURI, QgsCredentials
from processing.tools.postgis import GeoDB

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

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

"""
***************************************************************************
spatialite_utils.py
spatialite.py
---------------------
Date : November 2015
Copyright : (C) 2015 by René-Luc Dhont
@@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from processing.algs.qgis import postgis_utils
from processing.algs.qgis import spatialite_utils

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

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


GEOM_TYPE_MAP = {
@@ -581,16 +579,16 @@ def __init__(self, destination, encoding, fields, geometryType,
raise GeoAlgorithmExecutionException("Couldn't connect to database")
print uri.uri()
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)
except postgis_utils.DbError as e:
except postgis.DbError as e:
raise GeoAlgorithmExecutionException(
"Couldn't connect to database:\n%s" % e.message)

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

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

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

0 comments on commit 57b1618

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