[processing] improved handling of output files and file naming

This commit is contained in:
Victor Olaya 2013-09-02 00:54:25 +02:00
parent 979d87632f
commit 6607cedf1e
6 changed files with 21 additions and 15 deletions

View File

@ -29,7 +29,6 @@ from processing.core.ProcessingUtils import ProcessingUtils
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.gdal.GdalUtils import GdalUtils
class LayerExporter():

View File

@ -61,11 +61,7 @@ class ProcessingUtils:
@staticmethod
def setTempOutput(out, alg):
ext = out.getDefaultFileExtension(alg)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeCmdName = ''.join(c for c in alg.commandLineName() if c in validChars)
uniqueSufix = str(uuid.uuid4()).replace("-","")
filename = ProcessingUtils.tempFolder() + os.sep + safeCmdName + uniqueSufix + "." + ext
out.value = filename
out.value = ProcessingUtils.getTempFilenameInTempFolder(out.name + "." + ext)
@staticmethod
def getTempFilename(ext):

View File

@ -49,6 +49,6 @@ class OutputRaster(Output):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;

View File

@ -52,7 +52,7 @@ class OutputTable(Output):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;
def getTableWriter(self, fields):

View File

@ -55,7 +55,7 @@ class OutputVector(Output):
return self.value
else:
if self.compatible is None:
self.compatible = ProcessingUtils.getTempFilename(self.getDefaultFileExtension(alg))
self.compatible = ProcessingUtils.getTempFilenameInTempFolder(self.name + "." + self.getDefaultFileExtension(alg))
return self.compatible;

View File

@ -206,7 +206,7 @@ class SagaAlgorithm(GeoAlgorithm):
filename = LayerExporter.exportVectorLayer(layer)
self.exportedLayers[param.value]=filename
elif not param.value.endswith("shp"):
raise GeoAlgorithmExecutionException("Unsupported file format")
raise GeoAlgorithmExecutionException("Unsupported file format")
if isinstance(param, ParameterTable):
if param.value == None:
continue
@ -378,14 +378,25 @@ class SagaAlgorithm(GeoAlgorithm):
return s
def exportRasterLayer(self, layer):
destFilename = ProcessingUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
self.exportedLayers[layer]= destFilename
def exportRasterLayer(self, source):
layer = QGisLayers.getObjectFromUri(source, False)
if layer:
filename = str(layer.name())
else:
filename = source.rstrip(".sgrd")
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
filename = ''.join(c for c in filename if c in validChars)
if len(filename) == 0:
filename = "layer"
destFilename = ProcessingUtils.getTempFilenameInTempFolder(filename + ".sgrd")
self.exportedLayers[source]= destFilename
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source+"\""
else:
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + source + "\""
def checkBeforeOpeningParametersDialog(self):