diff --git a/python/plugins/processing/core/GeoAlgorithm.py b/python/plugins/processing/core/GeoAlgorithm.py index 5a04f9cce1b..ac94be4020e 100644 --- a/python/plugins/processing/core/GeoAlgorithm.py +++ b/python/plugins/processing/core/GeoAlgorithm.py @@ -16,6 +16,7 @@ * * *************************************************************************** """ +from processing import interface __author__ = 'Victor Olaya' __date__ = 'August 2012' __copyright__ = '(C) 2012, Victor Olaya' @@ -283,7 +284,7 @@ class GeoAlgorithm: 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): @@ -368,11 +369,9 @@ class GeoAlgorithm: 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: diff --git a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py index 9359e32b926..3cf32e4708c 100644 --- a/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py +++ b/python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py @@ -16,6 +16,7 @@ * * *************************************************************************** """ +from processing.tools.general import removeInvalidChars __author__ = 'Victor Olaya' @@ -228,8 +229,7 @@ class ModelerParameterDefinitionDialog(QtGui.QDialog): 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 diff --git a/python/plugins/processing/saga/SagaAlgorithm.py b/python/plugins/processing/saga/SagaAlgorithm.py index 451643d1790..5b652ae049f 100644 --- a/python/plugins/processing/saga/SagaAlgorithm.py +++ b/python/plugins/processing/saga/SagaAlgorithm.py @@ -384,8 +384,7 @@ class SagaAlgorithm(GeoAlgorithm): 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") diff --git a/python/plugins/processing/saga/SplitRGBBands.py b/python/plugins/processing/saga/SplitRGBBands.py index 162478fc576..e8945329519 100644 --- a/python/plugins/processing/saga/SplitRGBBands.py +++ b/python/plugins/processing/saga/SplitRGBBands.py @@ -55,8 +55,7 @@ class SplitRGBBands(GeoAlgorithm): 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) diff --git a/python/plugins/processing/tools/dataobjects.py b/python/plugins/processing/tools/dataobjects.py index ac01821fa46..7457aa6920c 100644 --- a/python/plugins/processing/tools/dataobjects.py +++ b/python/plugins/processing/tools/dataobjects.py @@ -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) diff --git a/python/plugins/processing/tools/general.py b/python/plugins/processing/tools/general.py index 585e3d07b1b..5b121496784 100644 --- a/python/plugins/processing/tools/general.py +++ b/python/plugins/processing/tools/general.py @@ -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 diff --git a/python/plugins/processing/tools/help.py b/python/plugins/processing/tools/help.py index 3204eb74e9a..f3ea17b0dcc 100644 --- a/python/plugins/processing/tools/help.py +++ b/python/plugins/processing/tools/help.py @@ -16,6 +16,7 @@ * * *************************************************************************** """ +from processing.tools.general import removeInvalidChars __author__ = 'Victor Olaya' __date__ = 'March 2013' @@ -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()) diff --git a/python/plugins/processing/tools/system.py b/python/plugins/processing/tools/system.py index 8ba83b7703f..4c04316941e 100644 --- a/python/plugins/processing/tools/system.py +++ b/python/plugins/processing/tools/system.py @@ -16,6 +16,7 @@ * * *************************************************************************** """ +from processing.tools.general import removeInvalidChars __author__ = 'Victor Olaya' __date__ = 'August 2012' @@ -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