Commit 358ba3ac authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

upgdate to same code in qgis pr

parent dc71c82c
...@@ -33,22 +33,30 @@ from qgis.PyQt.QtCore import QCoreApplication ...@@ -33,22 +33,30 @@ from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtGui import QIcon
from qgis.core import (Qgis, from qgis.core import (Qgis,
QgsMessageLog, QgsMessageLog,
QgsRasterLayer, QgsMapLayer,
QgsMapLayer, QgsApplication,
QgsProcessingAlgorithm, QgsProcessingException,
QgsProcessingParameterMultipleLayers, QgsProcessingAlgorithm,
QgsProcessingParameterDefinition, QgsProcessingParameterMultipleLayers,
QgsProcessingOutputLayerDefinition, QgsProcessingParameterDefinition,
QgsProcessingParameterString, QgsProcessingOutputLayerDefinition,
QgsProcessingParameterNumber, QgsProcessingParameterCrs,
QgsProcessingParameterEnum) QgsProcessingParameterString,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterBoolean,
QgsProcessingParameterFile,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterVectorDestination,
QgsProcessingParameterEnum)
from processing.core.parameters import getParameterFromString from processing.core.parameters import getParameterFromString
from otb.OtbChoiceWidget import OtbParameterChoice from otb.OtbChoiceWidget import OtbParameterChoice
from otb import OtbUtils from otb import OtbUtils
class OtbAlgorithm(QgsProcessingAlgorithm): class OtbAlgorithm(QgsProcessingAlgorithm):
def __init__(self, group, name, descriptionfile, display_name='', groupId=''): def __init__(self, group, name, descriptionfile, display_name='', groupId=''):
super().__init__() super().__init__()
...@@ -61,30 +69,13 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -61,30 +69,13 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
if not groupId: if not groupId:
self._groupId = ''.join(c for c in self._group if c in validChars) self._groupId = ''.join(c for c in self._group if c in validChars)
self.pixelTypes = ['unit8','int','float','double'] self.pixelTypes = ['uint8', 'uint16', 'int16', 'uint32', 'int32',
'float', 'double', 'cint16', 'cint32', 'cfloat', 'cdouble']
self._descriptionfile = descriptionfile self._descriptionfile = descriptionfile
self.defineCharacteristicsFromFile() self.defineCharacteristicsFromFile()
# def canExecute( self, msg=None):
# if len(self.parameterDefinitions()) > 0:
# return True, None
# try:
# self.defineCharacteristicsFromFile()
# except BaseException as e:
# return False, None
# return True, None
# TODO: check if this method is really required.
def checkParameterValues(self, parameters, context):
for key, value in parameters.items():
param = self.parameterDefinition(key)
if not param.checkValueIsAcceptable(value, context):
return False, "Incorrect parameter value for {}".format(param.name())
return True, None
def icon(self): def icon(self):
return QIcon(os.path.join(pluginPath, 'otb', 'otb.png')) return QIcon(os.path.join(pluginPath, 'otb', 'providerOtb.svg'))
def createInstance(self): def createInstance(self):
return self.__class__(self._group, self._name, self._descriptionfile) return self.__class__(self._group, self._name, self._descriptionfile)
...@@ -112,7 +103,7 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -112,7 +103,7 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
#TODO: show version which is same as OtbAlgorithm rather than always latest. #TODO: show version which is same as OtbAlgorithm rather than always latest.
def helpUrl(self): def helpUrl(self):
return "https://www.orfeo-toolbox.org/CookBook/Applications/app_" + self.name() + ".html" return "https://www.orfeo-toolbox.org/CookBook/Applications/app_" + self.name() + ".html"
def defineCharacteristicsFromFile(self): def defineCharacteristicsFromFile(self):
line = None line = None
...@@ -158,7 +149,7 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -158,7 +149,7 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
group_value = name.split('.')[-2] group_value = name.split('.')[-2]
metadata = param.metadata() metadata = param.metadata()
metadata['group_key'] = group_key metadata['group_key'] = group_key
metadata['group_value'] = group_value metadata['group_value'] = group_value
param.setMetadata(metadata) param.setMetadata(metadata)
#'elev.dem.path', 'elev.dem', 'elev.dem.geoid', 'elev.geoid' are special! #'elev.dem.path', 'elev.dem', 'elev.dem.geoid', 'elev.geoid' are special!
...@@ -171,29 +162,31 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -171,29 +162,31 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
if name in ["elev.dem.geoid", "elev.geoid"]: if name in ["elev.dem.geoid", "elev.geoid"]:
param.setDefaultValue(OtbUtils.geoidFile()) param.setDefaultValue(OtbUtils.geoidFile())
# outputpixeltype is a special parameter associated with raster output
# reset list of options to 'self.pixelTypes'.
if name == 'outputpixeltype':
param.setOptions(self.pixelTypes)
param.setDefaultValue(self.pixelTypes.index('float'))
self.addParameter(param) self.addParameter(param)
#parameter is added now and we must move to next line #parameter is added now and we must move to next line
line = lines.readline().strip('\n').strip() line = lines.readline().strip('\n').strip()
except BaseException as e: except BaseException as e:
import traceback import traceback
errmsg = "Could not open OTB algorithm from file: \n" + self._descriptionfile + "\nline=" + line + "\nError:\n" + traceback.format_exc() errmsg = "Could not open OTB algorithm from file: \n" + self._descriptionfile + "\nline=" + line + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical) QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
raise e raise e
def preprocessParameters(self, parameters): def preprocessParameters(self, parameters):
valid_params = {} valid_params = {}
for k,v in parameters.items(): for k, v in parameters.items():
param = self.parameterDefinition(k) param = self.parameterDefinition(k)
#If parameterDefinition(k) return None, this is considered a invalid parameter. #If parameterDefinition(k) return None, this is considered a invalid parameter.
#just continue for loop #just continue for loop
if param is None: if param is None:
continue continue
#if name of parameter is 'pixtype',
#it is considered valid if it has value other than float
if k == 'outputpixeltype' and self.pixelTypes[int(v)] == 'float':
continue
# Any other valid parameters have: # Any other valid parameters have:
#- empty or no metadata #- empty or no metadata
#- metadata without a 'group_key' #- metadata without a 'group_key'
...@@ -206,49 +199,70 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -206,49 +199,70 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
return valid_params return valid_params
def get_value(self, v):
if isinstance(v, QgsMapLayer):
return v.source()
elif isinstance(v, QgsProcessingOutputLayerDefinition):
return v.sink.staticValue()
else:
return str(v)
def outputParameterName(self):
with open(self._descriptionfile) as df:
first_line = df.readline().strip()
tokens = first_line.split("|")
#params = [t if str(t) != str(None) else None for t in tokens[1:]]
if len(tokens) == 2:
return tokens[1]
else:
return ''
def processAlgorithm(self, parameters, context, feedback): def processAlgorithm(self, parameters, context, feedback):
output_key = self.outputParameterName() otb_cli_file = OtbUtils.cliPath()
otb_cli_file = OtbUtils.cliPath()
command = '"{}" {} {}'.format(otb_cli_file, self.name(), OtbUtils.appFolder()) command = '"{}" {} {}'.format(otb_cli_file, self.name(), OtbUtils.appFolder())
outputPixelType = None
for k, v in parameters.items(): for k, v in parameters.items():
if k == 'outputpixeltype' or not v: # if value is None for a parameter we don't have any businees with this key
if v is None:
continue
# for 'outputpixeltype' parameter we find the pixeltype string from self.pixelTypes
if k == 'outputpixeltype':
pixel_type = self.pixelTypes[int(parameters['outputpixeltype'])]
outputPixelType = None if pixel_type == 'float' else pixel_type
continue continue
if 'epsg' in k and v.startswith('EPSG:'): param = self.parameterDefinition(k)
v = v.split('EPSG:')[1] if param.isDestination():
continue
if isinstance(v, str) and '\n' in v: if isinstance(param, QgsProcessingParameterEnum):
v = v.split('\n') value = self.parameterAsEnum(parameters, param.name(), context)
if isinstance(v, list): elif isinstance(param, QgsProcessingParameterBoolean):
value = '' value = self.parameterAsBool(parameters, param.name(), context)
for i in list(filter(None, v)): elif isinstance(param, QgsProcessingParameterCrs):
value += '"{}" '.format(self.get_value(i)) crsValue = self.parameterAsCrs(parameters, param.name(), context)
authid = crsValue.authid()
if authid.startswith('EPSG:'):
value = authid.split('EPSG:')[1]
else:
raise QgsProcessingException(
self.tr("Incorrect value for parameter '{}'. No EPSG code found in '{}'".format(
param.name(),
authid)))
elif isinstance(param, QgsProcessingParameterFile):
value = self.parameterAsFile(parameters, param.name(), context)
elif isinstance(param, QgsProcessingParameterMultipleLayers):
layers = self.parameterAsLayerList(parameters, param.name(), context)
if layers is None or len(layers) == 0:
continue
value = ' '.join(['"{}"'.format(self.getLayerSource(param.name(), layer)) for layer in layers])
elif isinstance(param, QgsProcessingParameterNumber):
if param.dataType() == QgsProcessingParameterNumber.Integer:
value = self.parameterAsInt(parameters, param.name(), context)
else:
value = self.parameterAsDouble(parameters, param.name(), context)
elif isinstance(param, (QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer)):
value = '"{}"'.format(self.getLayerSource(param.name(), self.parameterAsLayer(parameters, param.name(), context)))
elif isinstance(param, QgsProcessingParameterString):
value = '"{}"'.format(self.parameterAsString(parameters, param.name(), context))
else: else:
value = '"{}"'.format(self.get_value(v)) # Use whatever is given
value = '"{}"'.format(parameters[param.name()])
if k == output_key and 'outputpixeltype' in parameters: # Check if value is set in above if elif ladder and update command string
output_pixel_type = self.pixelTypes[int(parameters['outputpixeltype'])] if value and value is not None:
value = '"{}" "{}"'.format(value, output_pixel_type) command += ' -{} {}'.format(k, value)
command += ' -{} {}'.format(k, value) output_files = {}
for out in self.destinationParameterDefinitions():
filePath = self.parameterAsOutputLayer(parameters, out.name(), context)
output_files[out.name()] = filePath
if outputPixelType is not None:
command += ' -{} "{}" "{}"'.format(out.name(), filePath, outputPixelType)
else:
command += ' -{} "{}"'.format(out.name(), filePath)
QgsMessageLog.logMessage(self.tr('cmd={}'.format(command)), self.tr('Processing'), Qgis.Info) QgsMessageLog.logMessage(self.tr('cmd={}'.format(command)), self.tr('Processing'), Qgis.Info)
if not os.path.exists(otb_cli_file) or not os.path.isfile(otb_cli_file): if not os.path.exists(otb_cli_file) or not os.path.isfile(otb_cli_file):
...@@ -258,7 +272,16 @@ class OtbAlgorithm(QgsProcessingAlgorithm): ...@@ -258,7 +272,16 @@ class OtbAlgorithm(QgsProcessingAlgorithm):
OtbUtils.executeOtb(command, feedback) OtbUtils.executeOtb(command, feedback)
result = {} result = {}
for out in self.destinationParameterDefinitions(): for o in self.outputDefinitions():
filePath = self.parameterAsOutputLayer(parameters, out.name(), context) if o.name() in output_files:
result[out.name()] = filePath result[o.name()] = output_files[o.name()]
return result return result
def getLayerSource(self, name, layer):
providerName = layer.dataProvider().name()
#TODO: add other provider support in OTB, eg: memory
if providerName in ['ogr', 'gdal']:
return layer.source()
else:
raise QgsProcessingException(
self.tr("OTB currently support only gdal and ogr provider. Parameter '{}' uses '{}' provider".format(name, providerName)))
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
""" """
/*************************************************************************** /***************************************************************************
OtbAlgorithmProvider.py OtbAlgorithmProvider.py
----------------------- -----------------------
date : 2018-01-30 Date : 2018-01-30
copyright : (C) 2018 by CNES Copyright : (C) 2018 by CNES
email : rkm Email : rashad dot kanavath at c-s fr
***************************************************************************/ ****************************************************************************/
/*************************************************************************** /***************************************************************************
* * * *
...@@ -31,28 +31,29 @@ import os ...@@ -31,28 +31,29 @@ import os
import re import re
from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QCoreApplication from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (Qgis, QgsApplication, QgsProcessingProvider, QgsMessageLog) from qgis.core import (Qgis, QgsProcessingProvider, QgsMessageLog)
from qgis import utils from qgis import utils
from processing.core.ProcessingConfig import ProcessingConfig, Setting from processing.core.ProcessingConfig import ProcessingConfig, Setting
from otb import OtbUtils from otb import OtbUtils
from otb.OtbSettings import OtbSettings from otb.OtbSettings import OtbSettings
from otb.OtbAlgorithm import OtbAlgorithm from otb.OtbAlgorithm import OtbAlgorithm
pluginPath = os.path.split(os.path.dirname(__file__))[0]
def otb_exe_file(f): def otb_exe_file(f):
if os.name == 'nt': if os.name == 'nt':
return f + '.exe' return f + '.exe'
else: else:
return f return f
class OtbAlgorithmProvider(QgsProcessingProvider): class OtbAlgorithmProvider(QgsProcessingProvider):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.algs = [] self.algs = []
#!hack for 6.6!# #!hack for 6.6!#
self.version = '6.6.0' self.version = '6.6.0'
self.descriptionFile = ''
def load(self): def load(self):
group = self.name() group = self.name()
...@@ -63,34 +64,34 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -63,34 +64,34 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
OtbUtils.otbFolder(), OtbUtils.otbFolder(),
valuetype=Setting.FOLDER, valuetype=Setting.FOLDER,
validator=self.validateOtbFolder validator=self.validateOtbFolder
)) ))
ProcessingConfig.addSetting(Setting(group, OtbSettings.APP_FOLDER, ProcessingConfig.addSetting(Setting(group, OtbSettings.APP_FOLDER,
self.tr("OTB application folder"), self.tr("OTB application folder"),
OtbUtils.appFolder(), OtbUtils.appFolder(),
valuetype=Setting.MULTIPLE_FOLDERS, valuetype=Setting.MULTIPLE_FOLDERS,
validator=self.validateAppFolders validator=self.validateAppFolders
)) ))
ProcessingConfig.addSetting(Setting(group, OtbSettings.SRTM_FOLDER, ProcessingConfig.addSetting(Setting(group, OtbSettings.SRTM_FOLDER,
self.tr("SRTM tiles folder"), self.tr("SRTM tiles folder"),
OtbUtils.srtmFolder(), OtbUtils.srtmFolder(),
valuetype=Setting.FOLDER valuetype=Setting.FOLDER
)) ))
ProcessingConfig.addSetting(Setting(group, OtbSettings.GEOID_FILE, ProcessingConfig.addSetting(Setting(group, OtbSettings.GEOID_FILE,
self.tr("Geoid file"), self.tr("Geoid file"),
OtbUtils.geoidFile(), OtbUtils.geoidFile(),
valuetype=Setting.FOLDER valuetype=Setting.FOLDER
)) ))
ProcessingConfig.addSetting(Setting(group, OtbSettings.MAX_RAM_HINT, ProcessingConfig.addSetting(Setting(group, OtbSettings.MAX_RAM_HINT,
self.tr("Maximum RAM to use"), self.tr("Maximum RAM to use"),
OtbUtils.maxRAMHint(), OtbUtils.maxRAMHint(),
valuetype=Setting.STRING valuetype=Setting.STRING
)) ))
ProcessingConfig.addSetting(Setting(group, OtbSettings.LOGGER_LEVEL, ProcessingConfig.addSetting(Setting(group, OtbSettings.LOGGER_LEVEL,
self.tr("Logger level"), self.tr("Logger level"),
OtbUtils.loggerLevel(), OtbUtils.loggerLevel(),
valuetype=Setting.STRING, valuetype=Setting.STRING,
validator=self.validateLoggerLevel validator=self.validateLoggerLevel
)) ))
ProcessingConfig.readSettings() ProcessingConfig.readSettings()
self.refreshAlgorithms() self.refreshAlgorithms()
return True return True
...@@ -117,16 +118,16 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -117,16 +118,16 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
line = lines.readline().strip('\n').strip() line = lines.readline().strip('\n').strip()
while line != '' and not line.startswith('#'): while line != '' and not line.startswith('#'):
data = line.split('|') data = line.split('|')
self.descriptionFile = self.descrFile(folder, str(data[1]) + '.txt') descriptionFile = self.descrFile(folder, str(data[1]) + '.txt')
group, name = str(data[0]), str(data[1]) group, name = str(data[0]), str(data[1])
if name not in alg_names: if name not in alg_names:
algs.append(OtbAlgorithm(group, name, self.descriptionFile)) algs.append(OtbAlgorithm(group, name, descriptionFile))
#avoid duplicate algorithms from algs.txt file (possible but rare) #avoid duplicate algorithms from algs.txt file (possible but rare)
alg_names.append(name) alg_names.append(name)
line = lines.readline().strip('\n').strip() line = lines.readline().strip('\n').strip()
except Exception as e: except Exception as e:
import traceback import traceback
errmsg = "Could not open OTB algorithm from file: \n" + self.descriptionFile + "\nError:\n" + traceback.format_exc() errmsg = "Could not open OTB algorithm from file: \n" + descriptionFile + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical) QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
return algs return algs
...@@ -152,13 +153,11 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -152,13 +153,11 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
self.addAlgorithm(a) self.addAlgorithm(a)
self.algs = [] self.algs = []
self.create_otbcli()
def create_otbcli(self):
otb_folder = self.normalize_path(OtbUtils.otbFolder()) otb_folder = self.normalize_path(OtbUtils.otbFolder())
otb_app_path_env = os.pathsep.join(self.appDirs(OtbUtils.appFolder())) otb_app_path_env = os.pathsep.join(self.appDirs(OtbUtils.appFolder()))
gdal_data_dir = None gdal_data_dir = None
geotiff_csv_dir = None geotiff_csv_dir = None
otbcli_path = OtbUtils.cliPath()
try: try:
if os.name == 'nt': if os.name == 'nt':
app_vargs = " %*" app_vargs = " %*"
...@@ -168,24 +167,23 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -168,24 +167,23 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
gdal_data_dir = os.path.join(otb_folder, 'share', 'data') gdal_data_dir = os.path.join(otb_folder, 'share', 'data')
geotiff_csv_dir = os.path.join(otb_folder, 'share', 'epsg_csv') geotiff_csv_dir = os.path.join(otb_folder, 'share', 'epsg_csv')
else: else:
app_vargs = " $@" app_vargs = " \"$@\""
export_cmd = 'export ' export_cmd = 'export '
first_line = '#!/bin/sh' first_line = '#!/bin/sh'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine') otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine')
lines = None lines = None
env_profile = os.path.join(otb_folder, 'otbenv.profile') env_profile = os.path.join(otb_folder, 'otbenv.profile')
with open(env_profile) as f: if os.path.exists(env_profile):
lines = f.readlines() with open(env_profile) as f:
lines = [x.strip() for x in lines] lines = f.readlines()
for line in lines: lines = [x.strip() for x in lines]
if not line or line.startswith('#'): for line in lines:
continue if not line or line.startswith('#'):
if 'GDAL_DATA=' in line: continue
gdal_data_dir = line.split("GDAL_DATA=")[1] if 'GDAL_DATA=' in line:
if 'GEOTIFF_CSV='in line: gdal_data_dir = line.split("GDAL_DATA=")[1]
geotiff_csv_dir = line.split("GEOTIFF_CSV=")[1] if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line.split("GEOTIFF_CSV=")[1]
otbcli_path = OtbUtils.cliPath()
with open(otbcli_path, 'w') as otb_cli_file: with open(otbcli_path, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep) otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep) otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep)
...@@ -195,19 +193,19 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -195,19 +193,19 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
if geotiff_csv_dir: if geotiff_csv_dir:
otb_cli_file.write(export_cmd + "GEOTIFF_CSV=" + "\"" + geotiff_csv_dir + "\"" + os.linesep) otb_cli_file.write(export_cmd + "GEOTIFF_CSV=" + "\"" + geotiff_csv_dir + "\"" + os.linesep)
if OtbUtils.loggerLevel(): if OtbUtils.loggerLevel():
otb_cli_file.write(export_cmd + "OTB_LOGGER_LEVEL=" + "\"" + OtbUtils.loggerLevel() + "\"" + os.linesep) otb_cli_file.write(export_cmd + "OTB_LOGGER_LEVEL=" + OtbUtils.loggerLevel() + os.linesep)
max_ram_hint = OtbUtils.maxRAMHint() max_ram_hint = OtbUtils.maxRAMHint()
if max_ram_hint and not int(max_ram_hint) == 128 : if max_ram_hint and not int(max_ram_hint) == 128:
otb_cli_file.write(export_cmd + "OTB_MAX_RAM_HINT=" + "\"" + max_ram_hint + "\"" + os.linesep) otb_cli_file.write(export_cmd + "OTB_MAX_RAM_HINT=" + max_ram_hint + os.linesep)
otb_cli_file.write(export_cmd + "OTB_APPLICATION_PATH=" + "\"" + otb_app_path_env + "\"" + os.linesep) otb_cli_file.write(export_cmd + "OTB_APPLICATION_PATH=" + "\"" + otb_app_path_env + "\"" + os.linesep)
otb_cli_file.write("\"" + otb_app_launcher + "\"" + app_vargs + os.linesep) otb_cli_file.write("\"" + otb_app_launcher + "\"" + app_vargs + os.linesep)
if not os.name == 'nt': if not os.name == 'nt':
os.chmod(otbcli_path, 0o744) os.chmod(otbcli_path, 0o744)
except BaseException as e: except BaseException as e:
import traceback import traceback
os.remove(otbcli_path) os.remove(otbcli_path)
errmsg = "Cannot write:" + otbcli_path + "\nError:\n" + traceback.format_exc() errmsg = "Cannot write:" + otbcli_path + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical) QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
raise e raise e
QgsMessageLog.logMessage(self.tr("Using otbcli: '{}'.".format(otbcli_path)), self.tr('Processing'), Qgis.Info) QgsMessageLog.logMessage(self.tr("Using otbcli: '{}'.".format(otbcli_path)), self.tr('Processing'), Qgis.Info)
...@@ -252,7 +250,7 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -252,7 +250,7 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
for otb_app in os.listdir(app_dir): for otb_app in os.listdir(app_dir):
if not otb_app.startswith('otbapp_') or \ if not otb_app.startswith('otbapp_') or \
'TestApplication' in otb_app or \ 'TestApplication' in otb_app or \
'ApplicationExample' in otb_app: 'ApplicationExample' in otb_app:
continue continue
app_name = os.path.basename(otb_app).split('.')[0][7:] app_name = os.path.basename(otb_app).split('.')[0][7:]
dfile = os.path.join(descr_folder, app_name + '.txt') dfile = os.path.join(descr_folder, app_name + '.txt')
...@@ -261,13 +259,15 @@ class OtbAlgorithmProvider(QgsProcessingProvider): ...@@ -261,13 +259,15 @@ class OtbAlgorithmProvider(QgsProcessingProvider):
cmdlist = [os.path.join( cmdlist = [os.path.join(
folder, 'bin', folder, 'bin'