Skip to content
Permalink
Browse files
[sextante] made temporary filenames more descriptive and readable, re…
…using the original filename but using a temp folder
  • Loading branch information
volaya committed Mar 23, 2013
1 parent d5d2fe5 commit 9f6715b4f25d4b5b3438095ffc864aeb56af2d75
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import os.path

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -48,7 +49,8 @@ def exportVectorLayer(layer):
It also export to a new file if the original one contains non-ascii characters'''
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = SextanteUtils.getTempFilename("shp")
output = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(unicode(layer.source())) + ".shp")
#output = SextanteUtils.getTempFilename("shp")
provider = layer.dataProvider()
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
@@ -63,7 +63,7 @@ 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("-","");
uniqueSufix = str(uuid.uuid4()).replace("-","")
filename = SextanteUtils.tempFolder() + os.sep + safeCmdName + uniqueSufix + "." + ext
out.value = filename

@@ -76,6 +76,15 @@ def getTempFilename(ext):
filename = path + os.sep + str(time.time()) + str(SextanteUtils.getNumExportedLayers()) + "." + ext
return filename

@staticmethod
def getTempFilenameInTempFolder(basename):
'''returns a temporary filename for a given file, putting it into a temp folder but not changing its basename'''
path = SextanteUtils.tempFolder()
tempFolder = os.path.join(path, str(uuid.uuid4()).replace("-",""))
mkdir(tempFolder)
filename = os.path.join(tempFolder, basename)
return filename

@staticmethod
def getNumExportedLayers():
SextanteUtils.NUM_EXPORTED += 1
@@ -276,29 +276,14 @@ def processAlgorithm(self, progress):

for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)#filename = out.value
#===============================================================
# if not filename.endswith(".tif"):
# filename += ".tif"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
filename = SextanteUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputVector):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".shp"):
# filename += ".shp"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
command+=(" -" + out.name + " \"" + filename + "\"");
if isinstance(out, OutputTable):
filename = out.getCompatibleFileName(self)#out.value
#===============================================================
# if not filename.endswith(".dbf"):
# filename += ".dbf"
# out.value = filename
#===============================================================
filename = out.getCompatibleFileName(self)
command+=(" -" + out.name + " \"" + filename + "\"");

commands.append(command)
@@ -355,7 +340,7 @@ def resampleRasterLayer(self,layer):


def exportRasterLayer(self, layer):
destFilename = SextanteUtils.getTempFilename("sgrd")
destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
self.exportedLayers[layer]= destFilename
if SextanteUtils.isWindows():
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""

0 comments on commit 9f6715b

Please sign in to comment.