Unverified Commit 294377be authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Improved connection of the QGIS feedback object to EnPT STDOUT and STDERR stream.

parent b1de8503
Pipeline #24500 failed with stage
in 1 minute and 18 seconds
...@@ -472,6 +472,9 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm): ...@@ -472,6 +472,9 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
Thread(target=reader, args=[process.stdout, q]).start() Thread(target=reader, args=[process.stdout, q]).start()
Thread(target=reader, args=[process.stderr, q]).start() Thread(target=reader, args=[process.stderr, q]).start()
stdout_qname = None
stderr_qname = None
# for _ in range(2): # for _ in range(2):
for source, line in iter(q.get, None): for source, line in iter(q.get, None):
if qgis_feedback.isCanceled(): if qgis_feedback.isCanceled():
...@@ -486,9 +489,16 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm): ...@@ -486,9 +489,16 @@ class _EnPTBaseAlgorithm(QgsProcessingAlgorithm):
linestr = line.decode('latin-1').rstrip() linestr = line.decode('latin-1').rstrip()
# print("%s: %s" % (source, linestr)) # print("%s: %s" % (source, linestr))
if source.name == 3:
# source name seems to be platfor/environment specific, so grab it from dummy STDOUT/STDERR messages.
if linestr == 'Connecting to EnPT STDOUT stream.':
stdout_qname = source.name
if linestr == 'Connecting to EnPT STDERR stream.':
stderr_qname = source.name
if source.name == stdout_qname:
qgis_feedback.pushInfo(linestr) qgis_feedback.pushInfo(linestr)
if source.name == 4: if source.name == stderr_qname:
qgis_feedback.reportError(linestr) qgis_feedback.reportError(linestr)
exitcode = process.poll() exitcode = process.poll()
......
...@@ -41,6 +41,7 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -41,6 +41,7 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
@staticmethod @staticmethod
def _prepare_enpt_environment() -> dict: def _prepare_enpt_environment() -> dict:
os.environ['PYTHONUNBUFFERED'] = '1' os.environ['PYTHONUNBUFFERED'] = '1'
os.environ['IS_ENPT_GUI_CALL'] = '1'
enpt_env = os.environ.copy() enpt_env = os.environ.copy()
enpt_env["PATH"] = ';'.join([i for i in enpt_env["PATH"].split(';') if 'OSGEO' not in i]) # actually not needed enpt_env["PATH"] = ';'.join([i for i in enpt_env["PATH"].split(';') if 'OSGEO' not in i]) # actually not needed
...@@ -75,7 +76,7 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -75,7 +76,7 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
raise ImportError("enpt", "EnPT must be installed into the QGIS Python environment " raise ImportError("enpt", "EnPT must be installed into the QGIS Python environment "
"when calling 'EnPTAlgorithm'.") "when calling 'EnPTAlgorithm'.")
# replace Enum parameters with corresponding strings # replace Enum parameters with corresponding strings (not needed in case of unittest)
for n, opts in [ for n, opts in [
('output_format', {0: 'GTiff', 1: 'ENVI'}), ('output_format', {0: 'GTiff', 1: 'ENVI'}),
('mode_ac', {0: 'land', 1: 'water', 2: 'combined'}), ('mode_ac', {0: 'land', 1: 'water', 2: 'combined'}),
...@@ -86,7 +87,8 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -86,7 +87,8 @@ class EnPTAlgorithm(_EnPTBaseAlgorithm):
('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}), ('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}),
('target_projection_type', {0: 'UTM', 1: 'Geographic'}), ('target_projection_type', {0: 'UTM', 1: 'Geographic'}),
]: ]:
parameters[n] = opts[parameters[n]] if isinstance(parameters[n], int):
parameters[n] = opts[parameters[n]]
# remove all parameters not to be forwarded to the EnPT CLI # remove all parameters not to be forwarded to the EnPT CLI
parameters = {k: v for k, v in parameters.items() parameters = {k: v for k, v in parameters.items()
......
...@@ -118,6 +118,7 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -118,6 +118,7 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm):
@staticmethod @staticmethod
def _prepare_enpt_environment() -> dict: def _prepare_enpt_environment() -> dict:
os.environ['PYTHONUNBUFFERED'] = '1' os.environ['PYTHONUNBUFFERED'] = '1'
os.environ['IS_ENPT_GUI_CALL'] = '1'
enpt_env = os.environ.copy() enpt_env = os.environ.copy()
enpt_env["PATH"] = ';'.join([i for i in enpt_env["PATH"].split(';') if 'OSGEO' not in i]) # actually not needed enpt_env["PATH"] = ';'.join([i for i in enpt_env["PATH"].split(';') if 'OSGEO' not in i]) # actually not needed
...@@ -181,7 +182,8 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm): ...@@ -181,7 +182,8 @@ class ExternalEnPTAlgorithm(_EnPTBaseAlgorithm):
('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}), ('vswir_overlap_algorithm', {0: 'order_by_wvl', 1: 'average', 2: 'vnir_only', 3: 'swir_only'}),
('target_projection_type', {0: 'UTM', 1: 'Geographic'}), ('target_projection_type', {0: 'UTM', 1: 'Geographic'}),
]: ]:
parameters[n] = opts[parameters[n]] if isinstance(parameters[n], int):
parameters[n] = opts[parameters[n]]
# print parameters and console call to log # print parameters and console call to log
# for key in sorted(parameters): # for key in sorted(parameters):
......
...@@ -61,6 +61,7 @@ enpt_test_parameters = dict( ...@@ -61,6 +61,7 @@ enpt_test_parameters = dict(
enable_vnir_swir_coreg=False, enable_vnir_swir_coreg=False,
json_config=None, json_config=None,
n_lines_to_append=NULL, n_lines_to_append=NULL,
mode_ac='combined',
ortho_resampAlg='bilinear', ortho_resampAlg='bilinear',
vswir_overlap_algorithm='vnir_only', vswir_overlap_algorithm='vnir_only',
output_dir='TEMPORARY_OUTPUT', output_dir='TEMPORARY_OUTPUT',
...@@ -76,6 +77,7 @@ enpt_test_parameters = dict( ...@@ -76,6 +77,7 @@ enpt_test_parameters = dict(
scale_factor_boa_ref=10000, scale_factor_boa_ref=10000,
scale_factor_toa_ref=10000, scale_factor_toa_ref=10000,
sicor_cache_dir=None, sicor_cache_dir=None,
target_projection_type='UTM',
working_dir=None) working_dir=None)
......
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