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
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))

Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/qgis/PostGISExecuteSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/PostgisTableSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

__author__ = 'Victor Olaya'
__date__ = 'February 2013'
Expand All @@ -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 = {
Expand Down Expand Up @@ -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)

Expand All @@ -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))

Expand Down

0 comments on commit 57b1618

Please sign in to comment.