Commit a5087c62 authored by Rashad Kanavath's avatar Rashad Kanavath

fixes #20 make otb-app-folder setting optional

default app path is added to app dir list which is
<prefix>/lib/otb/applications
parent b9d13f5a
......@@ -67,18 +67,11 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def check_app_folder(self, v):
if not self.isActive():
return
if not v or not os.path.exists(v):
self.setActive(False)
raise ValueError(self.tr('Cannot activate OTB provider'))
return
folder = OTBUtils.otbFolder()
otb_app_dirs = self.otb_app_dir_list(v)
if len(otb_app_dirs) < 1:
self.setActive(False)
raise ValueError(self.tr("Invalid path given for 'OTB application folder'. OTB provider will be disabled"))
folder = OTBUtils.otbFolder()
otb_app_dirs = self.otb_app_dir_list(v, folder)
if len(otb_app_dirs) == 1:
utils.iface.messageBar().pushInfo("OTB", "OTB applications folder set to default: '{}'".format(otb_app_dirs[0]))
#isValid is True if there is atleast one valid otb application is given path
isValid = False
......@@ -189,7 +182,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
,validator=self.check_otb_folder
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.APP_FOLDER,
self.tr("OTB application folder"),
self.tr("OTB application folder (optional)"),
OTBUtils.appFolder()
,valuetype=Setting.MULTIPLE_FOLDERS
,validator=self.check_app_folder
......@@ -294,12 +287,15 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def descrFile(self, d, f):
return os.path.join(self.descrFolder(d), f)
def otb_app_dir_list(self, v):
def otb_app_dir_list(self, v, otb_folder):
default_app_dir = os.path.join(otb_folder, 'lib', 'otb', 'applications')
folders = v.split(';')
app_dirs = []
for f in folders:
if f is not None and os.path.exists(f):
app_dirs.append(f)
if not default_app_dir in app_dirs:
app_dirs.append(default_app_dir)
return app_dirs
def name(self):
......
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