Commit bc6d7af4 authored by Rashad Kanavath's avatar Rashad Kanavath

M-x flycheck-list-errors

parent 1b777212
......@@ -39,21 +39,19 @@ from processing.core.ProcessingConfig import ProcessingConfig, Setting
from otb import OTBUtils
from otb.OTBAlgorithm import OTBAlgorithm
pluginPath = os.path.split(os.path.dirname(__file__))[0]
def otb_exe_file(f):
if os.name == 'nt':
return f + '.exe'
else:
return f
return f
class OTBAlgorithmProvider(QgsProcessingProvider):
def __init__(self):
super().__init__()
self.algs = []
#!hack for 6.6!#
self.version = '6.6.0'
self.descriptionFile = ''
def canBeActivated(self):
if not self.isActive():
......@@ -72,10 +70,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if not 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)
otb_app_dirs = self.otb_app_dir_list(v)
if len(otb_app_dirs) < 1:
self.setActive(False)
raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
......@@ -95,9 +92,10 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
dfile = os.path.join(descr_folder, app_name + '.txt')
isValid = True
if not os.path.exists(dfile):
cmdlist = [os.path.join(folder,'bin', otb_exe_file('otbQgisDescriptor')),
app_name, app_dir,
descr_folder + '/' ]
cmdlist = [os.path.join(
folder, 'bin',
otb_exe_file('otbQgisDescriptor')),
app_name, app_dir, descr_folder + '/']
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
......@@ -118,11 +116,10 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if not v or not os.path.exists(v):
self.setActive(False)
raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
return
path = self.normalize_path(v)
if not os.path.exists(os.path.join(path,'bin', otb_exe_file('otbApplicationLauncherCommandLine'))):
if not os.path.exists(os.path.join(path, 'bin', otb_exe_file('otbApplicationLauncherCommandLine'))):
self.setActive(False)
raise ValueError(self.tr("Cannot find '{}'. OTB will be disabled".format(os.path.join(v,'bin', otb_exe_file('otbApplicationLauncherCommandLine')))))
raise ValueError(self.tr("Cannot find '{}'. OTB will be disabled".format(os.path.join(v, 'bin', otb_exe_file('otbApplicationLauncherCommandLine')))))
def write_otbcli_wrapper_script(self):
otb_folder = self.normalize_path(OTBUtils.otbFolder())
......@@ -135,8 +132,8 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
export_cmd = 'SET '
first_line = ':: Setup environment for OTB package. Generated by QGIS plugin'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine.exe')
gdal_data_dir = os.path.join(otb_folder, 'share' , 'data')
geotiff_csv_dir = os.path.join(otb_folder, 'share' , 'epsg_csv')
gdal_data_dir = os.path.join(otb_folder, 'share', 'data')
geotiff_csv_dir = os.path.join(otb_folder, 'share', 'epsg_csv')
else:
app_vargs = " $@"
export_cmd = 'export '
......@@ -176,32 +173,29 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def load(self):
group = self.name()
ProcessingConfig.settingIcons[group] = self.icon()
ProcessingConfig.addSetting(Setting(group, OTBUtils.ACTIVATE,
self.tr('Activate'),
True
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.ACTIVATE, self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(group, OTBUtils.FOLDER,
self.tr("OTB folder"),
OTBUtils.otbFolder(),
valuetype=Setting.FOLDER
,validator=self.check_otb_folder
))
self.tr("OTB folder"),
OTBUtils.otbFolder(),
valuetype=Setting.FOLDER,
validator=self.check_otb_folder
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.APP_FOLDER,
self.tr("OTB application folder"),
OTBUtils.appFolder()
,valuetype=Setting.MULTIPLE_FOLDERS
,validator=self.check_app_folder
))
self.tr("OTB application folder"),
OTBUtils.appFolder(),
valuetype=Setting.MULTIPLE_FOLDERS,
validator=self.check_app_folder
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.SRTM_FOLDER,
self.tr("SRTM tiles folder"),
OTBUtils.srtmFolder(),
valuetype=Setting.FOLDER
))
self.tr("SRTM tiles folder"),
OTBUtils.srtmFolder(),
valuetype=Setting.FOLDER
))
ProcessingConfig.addSetting(Setting(group, OTBUtils.GEOID_FILE,
self.tr("Geoid file"),
OTBUtils.geoidFile(),
valuetype=Setting.FOLDER
))
self.tr("Geoid file"),
OTBUtils.geoidFile(),
valuetype=Setting.FOLDER
))
ProcessingConfig.readSettings()
self.refreshAlgorithms()
......@@ -229,16 +223,16 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
line = lines.readline().strip('\n').strip()
while line != '' and not line.startswith('#'):
data = line.split('|')
descriptionFile = self.descrFile(folder, str(data[1]) + '.txt')
self.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))
algs.append(OTBAlgorithm(group, name, self.descriptionFile))
#avoid duplicate algorithms from algs.txt file (possible but rare)
alg_names.append(name)
line = lines.readline().strip('\n').strip()
except Exception as e:
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" + self.descriptionFile + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
return algs
......@@ -268,8 +262,8 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
cli_ext = ''
env_profile = os.path.join(folder, 'otbenv.profile')
if os.name == 'nt':
cli_ext = '.bat'
env_profile = os.path.join(folder, 'otbenv.bat')
cli_ext = '.bat'
env_profile = os.path.join(folder, 'otbenv.bat')
if os.path.exists(env_profile) and os.path.isfile(env_profile):
OTBUtils.OTB_CLI_FILE = os.path.join(QgsApplication.qgisSettingsDirPath(), 'processing', 'qgis_otb_cli' + cli_ext)
......@@ -296,7 +290,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def otb_app_dir_list(self, v):
#!hack needed for QGIS < 3.2!#
v = v.replace(';',os.pathsep)
v = v.replace(';', os.pathsep)
#!hack needed for QGIS < 3.2!#
folders = v.split(os.pathsep)
app_dirs = []
......@@ -304,7 +298,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if f is not None and os.path.exists(f):
app_dirs.append(self.normalize_path(f))
return app_dirs
def name(self):
return 'OTB'
......@@ -321,6 +315,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
return False
def icon(self):
pluginPath = os.path.split(os.path.dirname(__file__))[0]
return QIcon(os.path.join(pluginPath, 'otb', 'otb.png'))
def tr(self, string, context=''):
......
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