Commit fce52241 authored by Rashad Kanavath's avatar Rashad Kanavath

moved descriptor folder to a permenant location

parent 3d6018d2
......@@ -123,6 +123,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
return False, None
def defineCharacteristicsFromFile(self):
line = None
try:
with open(self._descriptionfile) as lines:
line = lines.readline().strip('\n').strip()
......@@ -269,7 +270,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
command += ' -{} {}'.format(k, value)
QgsMessageLog.logMessage(self.tr('cmd={}'.format(command)), self.tr('Processing'), Qgis.Critical)
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):
import errno
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), otb_cli_file)
......
......@@ -52,9 +52,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
return False
folder = ProcessingConfig.getSetting(OTBUtils.FOLDER)
if folder and os.path.exists(folder):
if os.path.isfile(os.path.join(folder, 'descriptors', 'algs.txt')):
if os.path.isfile(self.algsFile(folder)):
return True
utils.iface.messageBar().pushWarning("OTB", "Cannot find '{}'. OTB provider will be disabled".format(os.path.join(folder, 'descriptors', 'algs.txt')))
utils.iface.messageBar().pushWarning("OTB", "Cannot find '{}'. OTB provider will be disabled".format(self.algsFile(folder)))
self.setActive(False)
return False
......@@ -68,24 +68,26 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
return
folder = OTBUtils.otbFolder()
otb_app_dirs = OTBUtils.otb_app_dir_list(v)
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"))
#isValid is True if there is atleast one valid otb application is given path
isValid = False
descr_folder = self.descrFolder(folder)
for app_dir in otb_app_dirs:
for otb_app in os.listdir(app_dir):
if not otb_app.startswith('otbapp_'):
continue
app_name = os.path.basename(otb_app).split('.')[0][7:]
dfile = os.path.join(folder, 'descriptors', app_name + '.txt')
dfile = os.path.join(descr_folder, app_name + '.txt')
isValid = True
if not os.path.exists(dfile):
cmdlist = [os.path.join(folder,'bin', 'otbQgisDescriptor'),
app_name, app_dir,
os.path.join(folder, 'descriptors/')]
descr_folder + '/' ]
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
......@@ -220,14 +222,14 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
try:
folder = OTBUtils.otbFolder()
alg_names = []
algs_txt = os.path.join(folder, 'descriptors', 'algs.txt')
algs_txt = self.algsFile(folder)
with open(algs_txt) as lines:
line = lines.readline().strip('\n').strip()
if line != '' and line.startswith('#'):
line = lines.readline().strip('\n').strip()
while line != '' and not line.startswith('#'):
data = line.split('|')
descriptionFile = os.path.join(folder,'descriptors', str(data[1]) + '.txt')
descriptionFile = self.descrFile(folder, str(data[1]) + '.txt')
group, name = str(data[0]), str(data[1])
if name not in alg_names:
algs.append(OTBAlgorithm(group, name, descriptionFile))
......@@ -264,6 +266,23 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
#print('Using OTBUtils.OTB_CLI_FILE=',OTBUtils.OTB_CLI_FILE)
def algsFile(self, d):
return os.path.join(d, 'share', 'otb', 'description', 'algs.txt')
def descrFolder(self, d):
return os.path.join(d, 'share', 'otb', 'description')
def descrFile(self, d, f):
return os.path.join(d, 'share', 'otb', 'description', f)
def otb_app_dir_list(self, v):
folders = v.split(';')
app_dirs = []
for f in folders:
if f is not None and os.path.exists(f):
app_dirs.append(f)
return app_dirs
def name(self):
return 'OTB'
......
......@@ -56,14 +56,6 @@ def version():
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 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
......
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