Commit d257860a authored by Rashad Kanavath's avatar Rashad Kanavath

try to handle version using hidden config setting

parent 29d09b15
......@@ -54,6 +54,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if folder and os.path.exists(folder):
if os.path.isfile(os.path.join(folder, 'descriptors', 'algs.txt')):
return True
utils.iface.messageBar().pushWarning("OTB", "Cannot find '{}'. OTB provider will be disabled".format(os.path.join(folder, 'descriptors', 'algs.txt')))
self.setActive(False)
return False
......@@ -86,6 +87,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
app_name, app_dir,
os.path.join(folder, 'descriptors')]
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
if isValid:
......@@ -158,6 +160,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
else:
otb_cli_file.write(otb_app_launcher + " $@" + os.linesep)
if not os.name == 'nt':
os.chmod(cli_filepath, 0o744)
# if OTBUtils.appFolder() is None:
# ProcessingConfig.setSettingValue(OTBUtils.APP_FOLDER, os.path.join(v, 'lib', 'otb', 'applications'))
......@@ -190,6 +195,12 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
OTBUtils.geoidFile(),
valuetype=Setting.FOLDER
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.VERSION,
self.tr("version"),
OTBUtils.version(),
valuetype=str,
hidden=True
))
ProcessingConfig.readSettings()
self.refreshAlgorithms()
return True
......@@ -213,8 +224,6 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
with open(algs_txt) as lines:
line = lines.readline().strip('\n').strip()
if line != '' and line.startswith('#'):
self.version = line[1:]
QgsMessageLog.logMessage(self.tr("Loading OTB '{}'.".format(self.version)), self.tr('Processing'), Qgis.Info)
line = lines.readline().strip('\n').strip()
while line != '' and not line.startswith('#'):
data = line.split('|')
......@@ -234,6 +243,11 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def loadAlgorithms(self):
if not self.canBeActivated():
return
if self.version is None:
self.version = OTBUtils.version()
QgsMessageLog.logMessage(self.tr("Loading OTB '{}'.".format(self.version)), self.tr('Processing'), Qgis.Info)
self.algs = self.createAlgsList()
for a in self.algs:
self.addAlgorithm(a)
......
......@@ -43,25 +43,28 @@ from qgis.PyQt.QtCore import QCoreApplication
ACTIVATE = "OTB_ACTIVATE"
FOLDER = "OTB_FOLDER"
APP_FOLDER = "OTB_APP_FOLDER"
VERSION = "OTB_VERSION"
SRTM_FOLDER = "OTB_SRTM_FOLDER"
GEOID_FILE = "OTB_GEOID_FILE"
DOWNLOAD_URL = "https://orfeo-toolbox.org/packages/archives/OTB/"
DEFAULT_RAM_VALUE = 128
OTB_CLI_FILE = ''
def version():
return ProcessingConfig.getSetting(VERSION) or '0.0.0'
def otbFolder():
return ProcessingConfig.getSetting(FOLDER) or None
def otb_app_dir_list(v):
folders = v.split(';')
app_dirs = []
for f in folders:
if f and os.path.exists(f):
folders.append(f)
return folders
if f is not None and os.path.exists(f):
app_dirs.append(f)
return app_dirs
def appFolder():
if os.name == 'nt':
return ProcessingConfig.getSetting(APP_FOLDER) or None
else:
......
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