Unverified Commit a38c2c06 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Avoid crash in case output directory is not set by the user.

parent 0aa41dc1
...@@ -109,23 +109,30 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -109,23 +109,30 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
) )
# list output dir # list output dir
outdir = parameters['output_dir'] if 'output_dir' in parameters:
outraster_matches = glob(os.path.join(outdir, '*', '*SPECTRAL_IMAGE.GEOTIFF')) outdir = parameters['output_dir']
outraster = outraster_matches[0] if len(outraster_matches) > 0 else None outraster_matches = glob(os.path.join(outdir, '*', '*SPECTRAL_IMAGE.GEOTIFF'))
outraster = outraster_matches[0] if len(outraster_matches) > 0 else None
feedback.pushInfo("The output folder '%s' contains:\n" % outdir)
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(outdir)]) + '\n') feedback.pushInfo("The output folder '%s' contains:\n" % outdir)
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(outdir)]) + '\n')
if outraster:
subdir = os.path.dirname(outraster_matches[0]) if outraster:
feedback.pushInfo("...where the folder '%s' contains:\n" % os.path.dirname(subdir)) subdir = os.path.dirname(outraster_matches[0])
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(subdir)]) + '\n') feedback.pushInfo("...where the folder '%s' contains:\n" % os.path.dirname(subdir))
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(subdir)]) + '\n')
# return outputs
return { # return outputs
'success': True, return {
self.P_OUTPUT_RASTER: outraster, 'success': True,
# self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER], self.P_OUTPUT_RASTER: outraster,
# self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER], # self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER],
self.P_OUTPUT_FOLDER: outdir # self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER],
} self.P_OUTPUT_FOLDER: outdir
}
else:
feedback.pushInfo('The output was skipped according to user setting.')
# return outputs
return {'success': True}
...@@ -195,23 +195,30 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -195,23 +195,30 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm):
env=enpt_env) env=enpt_env)
# list output dir # list output dir
outdir = parameters['output_dir'] if 'output_dir' in parameters:
outraster_matches = glob(os.path.join(outdir, '*', '*SPECTRAL_IMAGE.GEOTIFF')) outdir = parameters['output_dir']
outraster = outraster_matches[0] if len(outraster_matches) > 0 else None outraster_matches = glob(os.path.join(outdir, '*', '*SPECTRAL_IMAGE.GEOTIFF'))
outraster = outraster_matches[0] if len(outraster_matches) > 0 else None
feedback.pushInfo("The output folder '%s' contains:\n" % outdir)
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(outdir)]) + '\n') feedback.pushInfo("The output folder '%s' contains:\n" % outdir)
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(outdir)]) + '\n')
if outraster:
subdir = os.path.dirname(outraster_matches[0]) if outraster:
feedback.pushInfo("...where the folder '%s' contains:\n" % os.path.dirname(subdir)) subdir = os.path.dirname(outraster_matches[0])
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(subdir)]) + '\n') feedback.pushInfo("...where the folder '%s' contains:\n" % os.path.dirname(subdir))
feedback.pushCommandInfo('\n'.join([os.path.basename(f) for f in os.listdir(subdir)]) + '\n')
# return outputs
return { # return outputs
'success': True, return {
self.P_OUTPUT_RASTER: outraster, 'success': True,
# self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER], self.P_OUTPUT_RASTER: outraster,
# self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER], # self.P_OUTPUT_VECTOR: parameters[self.P_OUTPUT_RASTER],
self.P_OUTPUT_FOLDER: outdir # self.P_OUTPUT_FILE: parameters[self.P_OUTPUT_RASTER],
} self.P_OUTPUT_FOLDER: outdir
}
else:
feedback.pushInfo('The output was skipped according to user setting.')
# return outputs
return {'success': True}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment