Skip to content

Commit

Permalink
processing/gdal: use batch files instead of modules on windows
Browse files Browse the repository at this point in the history
(cherry picked from commit 570972b)
  • Loading branch information
jef-n committed Feb 21, 2021
1 parent 8068b5c commit 1f78665
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 109 deletions.
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/AssignProjection.py
Expand Up @@ -71,7 +71,7 @@ def groupId(self):
return 'rasterprojections'

def commandName(self):
return 'gdal_edit'
return 'gdal_edit.bat' if isWindows() else 'gdal_edit.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand All @@ -88,16 +88,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

arguments.append(fileName)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

self.setOutputValue(self.OUTPUT, fileName)

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def postProcessAlgorithm(self, context, feedback):
# get output value
Expand Down
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/fillnodata.py
Expand Up @@ -109,7 +109,7 @@ def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdal_fillnodata'
return 'gdal_fillnodata.bat' if isWindows() else 'gdal_fillnodata.py'

def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagDisplayNameIsLiteral
Expand Down Expand Up @@ -155,11 +155,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(raster.source())
arguments.append(out)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/gdal2tiles.py
Expand Up @@ -150,7 +150,7 @@ def groupId(self):
return 'rastermiscellaneous'

def commandName(self):
return 'gdal2tiles'
return 'gdal2tiles.bat' if isWindows() else 'gdal2tiles.py'

def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagDisplayNameIsLiteral
Expand Down Expand Up @@ -223,11 +223,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(self.parameterAsString(parameters, self.OUTPUT, context))

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/gdal2xyz.py
Expand Up @@ -69,7 +69,7 @@ def groupId(self):
return 'rasterconversion'

def commandName(self):
return 'gdal2xyz'
return 'gdal2xyz.bat' if isWindows() else 'gdal2xyz.py'

def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagDisplayNameIsLiteral
Expand All @@ -89,11 +89,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(raster.source())
arguments.append(self.parameterAsFileOutput(parameters, self.OUTPUT, context))

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdalcalc.py
Expand Up @@ -179,7 +179,7 @@ def groupId(self):
return 'rastermiscellaneous'

def commandName(self):
return 'gdal_calc' if isWindows() else 'gdal_calc.py'
return 'gdal_calc.bat' if isWindows() else 'gdal_calc'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
Expand Down
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/merge.py
Expand Up @@ -127,7 +127,7 @@ def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'merge.png'))

def commandName(self):
return 'gdal_merge'
return 'gdal_merge.bat' is isWindows() else 'gdal_merge.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
Expand Down Expand Up @@ -173,11 +173,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('--optfile')
arguments.append(list_file)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/pansharp.py
Expand Up @@ -104,7 +104,7 @@ def groupId(self):
return 'rastermiscellaneous'

def commandName(self):
return 'gdal_pansharpen'
return 'gdal_pansharpen.bat' if isWindows() else 'gdal_pansharpen.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
spectral = self.parameterAsRasterLayer(parameters, self.SPECTRAL, context)
Expand Down Expand Up @@ -136,11 +136,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
extra = self.parameterAsString(parameters, self.EXTRA, context)
arguments.append(extra)

if isWindows():
commands = ['python3', '-m', self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/pct2rgb.py
Expand Up @@ -74,7 +74,7 @@ def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', '8-to-24-bits.png'))

def commandName(self):
return 'pct2rgb'
return 'pct2rgb.bat' if isWindows() else 'pct2rgb.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
Expand All @@ -97,11 +97,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBoolean(parameters, self.RGBA, context):
arguments.append('-rgba')

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/polygonize.py
Expand Up @@ -91,7 +91,7 @@ def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'polygonize.png'))

def commandName(self):
return 'gdal_polygonize'
return 'gdal_polygonize.bat' if isWindows() else 'gdal_polygonize.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
Expand Down Expand Up @@ -124,11 +124,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(layerName)
arguments.append(self.parameterAsString(parameters, self.FIELD, context))

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/proximity.py
Expand Up @@ -139,7 +139,7 @@ def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdal_proximity'
return 'gdal_proximity.bat' if isWindows() else 'gdal_proximity.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down Expand Up @@ -196,11 +196,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(out)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/retile.py
Expand Up @@ -159,7 +159,7 @@ def groupId(self):
return 'rastermiscellaneous'

def commandName(self):
return "gdal_retile"
return "gdal_retile.bat" if isWindows() else "gdal_retile.py"

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
Expand Down Expand Up @@ -214,11 +214,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
layers = [l.source() for l in self.parameterAsLayerList(parameters, self.INPUT, context)]
arguments.extend(layers)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/rgb2pct.py
Expand Up @@ -72,7 +72,7 @@ def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', '24-to-8-bits.png'))

def commandName(self):
return 'rgb2pct'
return 'rgb2pct.bat' if isWindows() else 'rgb2pct.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
Expand All @@ -90,11 +90,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(raster.source())
arguments.append(out)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
11 changes: 2 additions & 9 deletions python/plugins/processing/algs/gdal/sieve.py
Expand Up @@ -94,7 +94,7 @@ def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'sieve.png'))

def commandName(self):
return 'gdal_sieve'
return 'gdal_sieve.bat' if isWindows() else 'gdal_sieve.py'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
Expand Down Expand Up @@ -130,11 +130,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(raster.source())
arguments.append(out)

if isWindows():
commands = ["python3", "-m", self.commandName()]
else:
commands = [self.commandName() + '.py']

commands.append(GdalUtils.escapeAndJoin(arguments))

return commands
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

0 comments on commit 1f78665

Please sign in to comment.