Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing]fixed bug with wrong characters in output filenames
refactored to reuse string cleaning function
  • Loading branch information
volaya committed Sep 14, 2013
1 parent a7dfcaa commit ff5e1ee
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
7 changes: 3 additions & 4 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing import interface
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand Down Expand Up @@ -283,7 +284,7 @@ def setOutputCRS(self):
if p is not None:
self.crs = p.crs()
return
qgis = dataobjects.iface
qgis = interface.iface
self.crs = qgis.mapCanvas().mapRenderer().destinationCrs()

def checkInputCRS(self):
Expand Down Expand Up @@ -368,11 +369,9 @@ def __str__(self):

def commandLineName(self):
name = self.provider.getName().lower() + ":" + self.name.lower()
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
name = ''.join(c for c in name if c in validChars)
name = removeInvalidChars(name)
return name


def removeOutputFromName(self, name):
for out in self.outputs:
if out.name == name:
Expand Down
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.tools.general import removeInvalidChars


__author__ = 'Victor Olaya'
Expand Down Expand Up @@ -228,8 +229,7 @@ def okPressed(self):
QMessageBox.critical(self, "Unable to define parameter", "Invalid parameter name")
return
if self.param is None:
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeName = ''.join(c for c in description if c in validChars)
safeName = removeInvalidChars(description)
name = self.paramType.upper().replace(" ","") + "_" + safeName.upper()
else:
name = self.param.name
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/saga/SagaAlgorithm.py
Expand Up @@ -384,8 +384,7 @@ def exportRasterLayer(self, source):
filename = str(layer.name())
else:
filename = os.path.basename(source)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
filename = ''.join(c for c in filename if c in validChars)
filename = removeInvalidChars(filename)
if len(filename) == 0:
filename = "layer"
destFilename = getTempFilenameInTempFolder(filename + ".sgrd")
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/saga/SplitRGBBands.py
Expand Up @@ -55,8 +55,7 @@ def processAlgorithm(self, progress):
input = self.getParameterValue(SplitRGBBands.INPUT)
temp = getTempFilename(None).replace('.','');
basename = os.path.basename(temp)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeBasename = ''.join(c for c in basename if c in validChars)
safeBasename = removeInvalidChars(basename)
temp = os.path.join(os.path.dirname(temp), safeBasename)

r = self.getOutputValue(SplitRGBBands.R)
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -219,10 +219,9 @@ def exportVectorLayer(layer):
filename = filename[:idx]

filename = str(layer.name())
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
filename = ''.join(c for c in filename if c in validChars)
filename = removeInvalidChars(filename)
if len(filename) == 0:
filename = "layer"
filename = "layer"
output = getTempFilenameInTempFolder(filename + ".shp")
provider = layer.dataProvider()
useSelection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/tools/general.py
Expand Up @@ -93,5 +93,8 @@ def extent(layers):
else:
return str(xmin) + "," + str(xmax) + "," + str(ymin) + "," + str(ymax)


def removeInvalidChars(string):
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
string = ''.join(c for c in string if c in validChars)
return string

4 changes: 2 additions & 2 deletions python/plugins/processing/tools/help.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.tools.general import removeInvalidChars

__author__ = 'Victor Olaya'
__date__ = 'March 2013'
Expand All @@ -32,8 +33,7 @@ def createBaseHelpFile(alg, folder):
folder = os.path.join(folder, alg.provider.getName().lower())
mkdir(folder)
cmdLineName = alg.commandLineName()[alg.commandLineName().find(":") + 1:].lower()
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeFilename = ''.join(c for c in cmdLineName if c in validChars)
safeFilename = removeInvalidChars(cmdLineName)
filepath = os.path.join(folder, safeFilename + ".rst")
file = open(filepath, "w")
file.write(alg.name.upper())
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/tools/system.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.tools.general import removeInvalidChars

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -68,6 +69,7 @@ def getTempFilenameInTempFolder(basename):
path = tempFolder()
path = os.path.join(path, str(uuid.uuid4()).replace("-",""))
mkdir(path)
basename = removeInvalidChars(basename)
filename = os.path.join(path, basename)
return filename

Expand Down

0 comments on commit ff5e1ee

Please sign in to comment.