Skip to content

Commit

Permalink
[processing] Return log lines from GdalUtils.runGdal instead of storing
Browse files Browse the repository at this point in the history
in a class member

The previous approach was NOT thread safe, and it's easy to avoid
  • Loading branch information
nyalldawson committed Jan 8, 2021
1 parent 02f861c commit e79922b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -97,8 +97,7 @@ def runGdal(commands, feedback=None):
success = False
retry_count = 0
while not success:
loglines = []
loglines.append(GdalUtils.tr('GDAL execution console output'))
loglines = [GdalUtils.tr('GDAL execution console output')]
try:
with subprocess.Popen(
fused_command,
Expand All @@ -121,11 +120,7 @@ def runGdal(commands, feedback=None):
len(loglines), u'\n'.join(loglines[-10:])))

QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', Qgis.Info)
GdalUtils.consoleOutput = loglines

@staticmethod
def getConsoleOutput():
return GdalUtils.consoleOutput
return loglines

@staticmethod
def getSupportedRasters():
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/gdalinfo.py
Expand Up @@ -115,11 +115,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
console_output = GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
with open(output, 'w') as f:
f.write('<pre>')
for s in GdalUtils.getConsoleOutput()[1:]:
for s in console_output[1:]:
f.write(str(s))
f.write('</pre>')

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/ogrinfo.py
Expand Up @@ -85,11 +85,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
console_output = GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
with open(output, 'w') as f:
f.write('<pre>')
for s in GdalUtils.getConsoleOutput()[1:]:
for s in console_output[1:]:
f.write(str(s))
f.write('</pre>')

Expand Down

0 comments on commit e79922b

Please sign in to comment.