Skip to content

Commit

Permalink
[processing] more improvements for storing db data in log
Browse files Browse the repository at this point in the history
This allows reusing commands that use a db-based layer.

It disables parameter validity checks for layers. Those checks should now be performed at the algorithm level before executing (not yet implemented)
  • Loading branch information
volaya committed Jun 23, 2015
1 parent 6e4113f commit 6ce2333
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
30 changes: 4 additions & 26 deletions python/plugins/processing/core/parameters.py
Expand Up @@ -18,7 +18,6 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand Down Expand Up @@ -149,16 +148,9 @@ def getValueAsCommandLineParameter(self):
if self.value is None:
return unicode(None)
else:
s = unicode(self.value)
if isWindows():
s = s.replace('\\', '\\\\')
s = s.replace('"', "'")
s = dataobjects.normalizeLayerSource(unicode(self.value))
s = '"%s"' % s

s = re.sub("'user.*?'", "", s)
s = re.sub("'password.*?'", "", s)

return s
return s

class ParameterExtent(Parameter):

Expand Down Expand Up @@ -523,16 +515,7 @@ def setValue(self, obj):
return True
else:
self.value = unicode(obj)
layers = dataobjects.getRasterLayers()
for layer in layers:
if layer.name() == self.value:
self.value = unicode(layer.dataProvider().dataSourceUri())
return True
if os.path.exists(self.value) or QgsRasterLayer(self.value).isValid():
return True
else:
# Layer could not be found
return False
return True


def getFileFilter(self):
Expand Down Expand Up @@ -744,12 +727,7 @@ def setValue(self, obj):
return True
else:
self.value = unicode(obj)
layers = dataobjects.getVectorLayers(self.shapetype)
for layer in layers:
if layer.name() == self.value or layer.source() == self.value:
self.value = unicode(layer.source())
return True
return os.path.exists(self.value)
return True


def getSafeExportedLayer(self):
Expand Down
28 changes: 21 additions & 7 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -17,6 +17,7 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -33,7 +34,7 @@
from qgis.utils import iface
from processing.core.ProcessingConfig import ProcessingConfig
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename, isWindows

ALL_TYPES = [-1]

Expand Down Expand Up @@ -208,9 +209,16 @@ def getObject(uriorname):
ret = getObjectFromUri(uriorname)
return ret

def normalizeLayerSource(source):
if isWindows():
s = source.replace('\\', '/')
s = s.replace('"', "'")
s = re.sub("user=.*?", "", s)
s = re.sub("password=.*?", "", s)
return s

def getObjectFromUri(uri, forceLoad=True):
"""Returns an object (layer/table) given a file location.
"""Returns an object (layer/table) given a source definition.
if forceLoad is true, it tries to load it if it is not currently open
Otherwise, it will return the object only if it is loaded in QGIS.
Expand All @@ -222,15 +230,15 @@ def getObjectFromUri(uri, forceLoad=True):
return _loadedLayers[uri]
layers = getRasterLayers()
for layer in layers:
if layer.source() == uri:
if normalizeLayerSource(layer.source()) == normalizeLayerSource(uri):
return layer
layers = getVectorLayers()
for layer in layers:
if layer.source() == uri:
if normalizeLayerSource(layer.source()) == normalizeLayerSource(uri):
return layer
tables = getTables()
for table in tables:
if table.source() == uri:
if normalizeLayerSource(table.source()) == normalizeLayerSource(uri):
return table
if forceLoad:
settings = QSettings()
Expand All @@ -242,13 +250,19 @@ def getObjectFromUri(uri, forceLoad=True):
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[layer.source()] = layer
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
layer = QgsVectorLayer(uri, uri, 'postgres')
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
layer = QgsRasterLayer(uri, uri)
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[layer.source()] = layer
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
Expand Down

0 comments on commit 6ce2333

Please sign in to comment.