Skip to content

Commit 3e7b262

Browse files
alexbruyvolaya
authored andcommittedDec 1, 2016
[processing] replace deprecated % operator with format()
1 parent 50a785b commit 3e7b262

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed
 

‎python/plugins/processing/algs/qgis/RasterCalculator.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,19 @@ def defineCharacteristics(self):
6161
class ParameterRasterCalculatorExpression(ParameterString):
6262

6363
def evaluateForModeler(self, value, model):
64-
# print value
6564
for i in list(model.inputs.values()):
6665
param = i.param
6766
if isinstance(param, ParameterRaster):
68-
new = "%s@" % os.path.basename(param.value)
69-
old = "%s@" % param.name
67+
new = "{}@".format(os.path.basename(param.value))
68+
old = "{}@".format(param.name)
7069
value = value.replace(old, new)
7170

7271
for alg in list(model.algs.values()):
7372
for out in alg.algorithm.outputs:
7473
if isinstance(out, OutputRaster):
7574
if out.value:
76-
new = "%s@" % os.path.basename(out.value)
77-
old = "%s:%s@" % (alg.name, out.name)
75+
new = "{}@".format(os.path.basename(out.value))
76+
old = "{}:{}@".format(alg.name, out.name)
7877
value = value.replace(old, new)
7978
return value
8079

@@ -106,7 +105,7 @@ def processAlgorithm(self, progress):
106105
for name, lyr in layersDict.items():
107106
for n in xrange(lyr.bandCount()):
108107
entry = QgsRasterCalculatorEntry()
109-
entry.ref = '%s@%i' % (name, n + 1)
108+
entry.ref = '{:s}@{:d}'.format(name, n + 1)
110109
entry.raster = lyr
111110
entry.bandNumber = n + 1
112111
entries.append(entry)
@@ -149,7 +148,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
149148
expression = algorithm.params[self.EXPRESSION]
150149
for i in list(model.inputs.values()):
151150
param = i.param
152-
if isinstance(param, ParameterRaster) and "%s@" % param.name in expression:
151+
if isinstance(param, ParameterRaster) and "{}@".format(param.name) in expression:
153152
values.append(ValueFromInput(param.name))
154153

155154
if algorithm.name:
@@ -160,7 +159,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
160159
if alg.name not in dependent:
161160
for out in alg.algorithm.outputs:
162161
if (isinstance(out, OutputRaster)
163-
and "%s:%s@" % (alg.name, out.name) in expression):
162+
and "{}:{}@".format(alg.name, out.name) in expression):
164163
values.append(ValueFromOutput(alg.name, out.name))
165164

166165
algorithm.params[self.LAYERS] = values

‎python/plugins/processing/algs/qgis/ui/RasterCalculatorWidgets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def doubleClicked(item):
2828

2929
def addButtonText(text):
3030
if any(c for c in text if c.islower()):
31-
self.text.insertPlainText(" %s()" % text)
31+
self.text.insertPlainText(" {}()".format(text))
3232
self.text.moveCursor(QTextCursor.PreviousCharacter, QTextCursor.MoveAnchor)
3333
else:
34-
self.text.insertPlainText(" %s " % text)
34+
self.text.insertPlainText(" {} ".format(text))
3535
buttons = [b for b in self.buttonsGroupBox.children()if isinstance(b, QPushButton)]
3636
for button in buttons:
3737
button.clicked.connect(partial(addButtonText, button.text()))
@@ -61,22 +61,22 @@ def createWidget(self):
6161
options = {}
6262
for lyr in layers:
6363
for n in xrange(lyr.bandCount()):
64-
name = '%s@%i' % (lyr.name(), n + 1)
64+
name = '{:s}@{:d}'.format(lyr.name(), n + 1)
6565
options[name] = name
6666
return self._panel(options)
6767
elif self.dialogType == DIALOG_BATCH:
6868
return QLineEdit()
6969
else:
7070
layers = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
71-
options = {self.dialog.resolveValueDescription(lyr): "%s@1" % lyr for lyr in layers}
71+
options = {self.dialog.resolveValueDescription(lyr): "{}@1".format(lyr) for lyr in layers}
7272
return self._panel(options)
7373

7474
def refresh(self):
7575
layers = dataobjects.getRasterLayers()
7676
options = {}
7777
for lyr in layers:
7878
for n in xrange(lyr.bandCount()):
79-
options[lyr.name()] = '%s@%i' % (lyr.name(), n + 1)
79+
options[lyr.name()] = '{:s}@{:d}'.format(lyr.name(), n + 1)
8080
self.widget.setList(options)
8181

8282
def setValue(self, value):

0 commit comments

Comments
 (0)
Please sign in to comment.