Skip to content

Commit ff5e1ee

Browse files
committed
[processing]fixed bug with wrong characters in output filenames
refactored to reuse string cleaning function
1 parent a7dfcaa commit ff5e1ee

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

python/plugins/processing/core/GeoAlgorithm.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing import interface
1920
__author__ = 'Victor Olaya'
2021
__date__ = 'August 2012'
2122
__copyright__ = '(C) 2012, Victor Olaya'
@@ -283,7 +284,7 @@ def setOutputCRS(self):
283284
if p is not None:
284285
self.crs = p.crs()
285286
return
286-
qgis = dataobjects.iface
287+
qgis = interface.iface
287288
self.crs = qgis.mapCanvas().mapRenderer().destinationCrs()
288289

289290
def checkInputCRS(self):
@@ -368,11 +369,9 @@ def __str__(self):
368369

369370
def commandLineName(self):
370371
name = self.provider.getName().lower() + ":" + self.name.lower()
371-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
372-
name = ''.join(c for c in name if c in validChars)
372+
name = removeInvalidChars(name)
373373
return name
374374

375-
376375
def removeOutputFromName(self, name):
377376
for out in self.outputs:
378377
if out.name == name:

python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.tools.general import removeInvalidChars
1920

2021

2122
__author__ = 'Victor Olaya'
@@ -228,8 +229,7 @@ def okPressed(self):
228229
QMessageBox.critical(self, "Unable to define parameter", "Invalid parameter name")
229230
return
230231
if self.param is None:
231-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
232-
safeName = ''.join(c for c in description if c in validChars)
232+
safeName = removeInvalidChars(description)
233233
name = self.paramType.upper().replace(" ","") + "_" + safeName.upper()
234234
else:
235235
name = self.param.name

python/plugins/processing/saga/SagaAlgorithm.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ def exportRasterLayer(self, source):
384384
filename = str(layer.name())
385385
else:
386386
filename = os.path.basename(source)
387-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
388-
filename = ''.join(c for c in filename if c in validChars)
387+
filename = removeInvalidChars(filename)
389388
if len(filename) == 0:
390389
filename = "layer"
391390
destFilename = getTempFilenameInTempFolder(filename + ".sgrd")

python/plugins/processing/saga/SplitRGBBands.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def processAlgorithm(self, progress):
5555
input = self.getParameterValue(SplitRGBBands.INPUT)
5656
temp = getTempFilename(None).replace('.','');
5757
basename = os.path.basename(temp)
58-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
59-
safeBasename = ''.join(c for c in basename if c in validChars)
58+
safeBasename = removeInvalidChars(basename)
6059
temp = os.path.join(os.path.dirname(temp), safeBasename)
6160

6261
r = self.getOutputValue(SplitRGBBands.R)

python/plugins/processing/tools/dataobjects.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,9 @@ def exportVectorLayer(layer):
219219
filename = filename[:idx]
220220

221221
filename = str(layer.name())
222-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
223-
filename = ''.join(c for c in filename if c in validChars)
222+
filename = removeInvalidChars(filename)
224223
if len(filename) == 0:
225-
filename = "layer"
224+
filename = "layer"
226225
output = getTempFilenameInTempFolder(filename + ".shp")
227226
provider = layer.dataProvider()
228227
useSelection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)

python/plugins/processing/tools/general.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,8 @@ def extent(layers):
9393
else:
9494
return str(xmin) + "," + str(xmax) + "," + str(ymin) + "," + str(ymax)
9595

96-
96+
def removeInvalidChars(string):
97+
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
98+
string = ''.join(c for c in string if c in validChars)
99+
return string
97100

python/plugins/processing/tools/help.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.tools.general import removeInvalidChars
1920

2021
__author__ = 'Victor Olaya'
2122
__date__ = 'March 2013'
@@ -32,8 +33,7 @@ def createBaseHelpFile(alg, folder):
3233
folder = os.path.join(folder, alg.provider.getName().lower())
3334
mkdir(folder)
3435
cmdLineName = alg.commandLineName()[alg.commandLineName().find(":") + 1:].lower()
35-
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
36-
safeFilename = ''.join(c for c in cmdLineName if c in validChars)
36+
safeFilename = removeInvalidChars(cmdLineName)
3737
filepath = os.path.join(folder, safeFilename + ".rst")
3838
file = open(filepath, "w")
3939
file.write(alg.name.upper())

python/plugins/processing/tools/system.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.tools.general import removeInvalidChars
1920

2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
@@ -68,6 +69,7 @@ def getTempFilenameInTempFolder(basename):
6869
path = tempFolder()
6970
path = os.path.join(path, str(uuid.uuid4()).replace("-",""))
7071
mkdir(path)
72+
basename = removeInvalidChars(basename)
7173
filename = os.path.join(path, basename)
7274
return filename
7375

0 commit comments

Comments
 (0)