Commit a1762b73 authored by Rashad Kanavath's avatar Rashad Kanavath

respect naming conventions for qgis providers

parent 57fb661d
......@@ -23,11 +23,11 @@ __copyright__ = '(C) 2017 Boundless, http://boundlessgeo.com'
# This will get replaced with a git SHA1 when you do a git archive
from qgis.core import QgsApplication
from .OTBAlgorithmProvider import OTBAlgorithmProvider
from .OtbAlgorithmProvider import OtbAlgorithmProvider
class OTBPlugin:
def __init__(self):
self.provider = OTBAlgorithmProvider()
self.provider = OtbAlgorithmProvider()
def initGui(self):
QgsApplication.processingRegistry().addProvider(self.provider)
......
# -*- coding: utf-8 -*-
"""
***************************************************************************
OTBAlgorithm.py
OtbAlgorithm.py
---------------
Date : June 2017
Copyright : (C) 2017 by CS Systemes d'Information (CS SI)
......@@ -46,10 +46,10 @@ from qgis.core import (Qgis,
from processing.core.parameters import getParameterFromString
from otb.OTBChoiceWidget import OTBParameterChoice
from otb import OTBUtils
from otb.OtbChoiceWidget import OtbParameterChoice
from otb import OtbUtils
class OTBAlgorithm(QgsProcessingAlgorithm):
class OtbAlgorithm(QgsProcessingAlgorithm):
def __init__(self, group, name, descriptionfile, display_name='', groupId=''):
super().__init__()
self._name = name
......@@ -90,7 +90,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
return self.__class__(self._group, self._name, self._descriptionfile)
def tr(self, string):
return QCoreApplication.translate("OTBAlgorithm", string)
return QCoreApplication.translate("OtbAlgorithm", string)
def name(self):
return self._name
......@@ -110,7 +110,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
pass
#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):
return "https://www.orfeo-toolbox.org/CookBook/Applications/app_" + self.name() + ".html"
......@@ -123,14 +123,14 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
self.appkey = self._name
line = lines.readline().strip('\n').strip()
self.doc = line
self.i18n_doc = QCoreApplication.translate("OTBAlgorithm", self.doc)
self.i18n_doc = QCoreApplication.translate("OtbAlgorithm", self.doc)
#self._name = self._name #+ " - " + self.doc
self._display_name = self.tr(self._name)
self.i18n_name = QCoreApplication.translate("OTBAlgorithm", self._name)
self.i18n_name = QCoreApplication.translate("OtbAlgorithm", self._name)
line = lines.readline().strip('\n').strip()
self._group = line
self.i18n_group = QCoreApplication.translate("OTBAlgorithm", self._group)
self.i18n_group = QCoreApplication.translate("OtbAlgorithm", self._group)
line = lines.readline().strip('\n').strip()
while line != '':
line = line.strip('\n').strip()
......@@ -142,7 +142,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
tokens = line.split("|")
params = [t if str(t) != str(None) else None for t in tokens[1:]]
options = params[2].split(';')
param = OTBParameterChoice(params[0], params[1], options, params[3], params[4])
param = OtbParameterChoice(params[0], params[1], options, params[3], params[4])
else:
param = getParameterFromString(line)
......@@ -167,9 +167,9 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
#Future releases of OTB must follow this rule keep
#compatibility or update this checklist.
if name in ["elev.dem.path", "elev.dem"]:
param.setDefaultValue(OTBUtils.srtmFolder())
param.setDefaultValue(OtbUtils.srtmFolder())
if name in ["elev.dem.geoid", "elev.geoid"]:
param.setDefaultValue(OTBUtils.geoidFile())
param.setDefaultValue(OtbUtils.geoidFile())
self.addParameter(param)
#parameter is added now and we must move to next line
......@@ -226,8 +226,8 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
def processAlgorithm(self, parameters, context, feedback):
output_key = self.outputParameterName()
otb_cli_file = OTBUtils.cliPath()
command = '"{}" {} {}'.format(otb_cli_file, self.name(), OTBUtils.appFolder())
otb_cli_file = OtbUtils.cliPath()
command = '"{}" {} {}'.format(otb_cli_file, self.name(), OtbUtils.appFolder())
for k, v in parameters.items():
if k == 'outputpixeltype' or not v:
continue
......@@ -255,7 +255,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
import errno
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), otb_cli_file)
OTBUtils.executeOtb(command, feedback)
OtbUtils.executeOtb(command, feedback)
result = {}
for out in self.destinationParameterDefinitions():
......
......@@ -2,7 +2,7 @@
"""
/***************************************************************************
OTBAlgorithmProvider.py
OtbAlgorithmProvider.py
-----------------------
date : 2018-01-30
copyright : (C) 2018 by CNES
......@@ -36,9 +36,9 @@ from qgis import utils
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from otb import OTBUtils
from otb.OTBSettings import OTBSettings
from otb.OTBAlgorithm import OTBAlgorithm
from otb import OtbUtils
from otb.OtbSettings import OtbSettings
from otb.OtbAlgorithm import OtbAlgorithm
def otb_exe_file(f):
if os.name == 'nt':
......@@ -46,7 +46,7 @@ def otb_exe_file(f):
else:
return f
class OTBAlgorithmProvider(QgsProcessingProvider):
class OtbAlgorithmProvider(QgsProcessingProvider):
def __init__(self):
super().__init__()
self.algs = []
......@@ -57,37 +57,37 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def load(self):
group = self.name()
ProcessingConfig.settingIcons[group] = self.icon()
ProcessingConfig.addSetting(Setting(group, OTBSettings.ACTIVATE, self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(group, OTBSettings.FOLDER,
ProcessingConfig.addSetting(Setting(group, OtbSettings.ACTIVATE, self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(group, OtbSettings.FOLDER,
self.tr("OTB folder"),
OTBUtils.otbFolder(),
OtbUtils.otbFolder(),
valuetype=Setting.FOLDER,
validator=self.validateOtbFolder
))
ProcessingConfig.addSetting(Setting(group, OTBSettings.APP_FOLDER,
ProcessingConfig.addSetting(Setting(group, OtbSettings.APP_FOLDER,
self.tr("OTB application folder"),
OTBUtils.appFolder(),
OtbUtils.appFolder(),
valuetype=Setting.MULTIPLE_FOLDERS,
validator=self.validateAppFolders
))
ProcessingConfig.addSetting(Setting(group, OTBSettings.SRTM_FOLDER,
ProcessingConfig.addSetting(Setting(group, OtbSettings.SRTM_FOLDER,
self.tr("SRTM tiles folder"),
OTBUtils.srtmFolder(),
OtbUtils.srtmFolder(),
valuetype=Setting.FOLDER
))
ProcessingConfig.addSetting(Setting(group, OTBSettings.GEOID_FILE,
ProcessingConfig.addSetting(Setting(group, OtbSettings.GEOID_FILE,
self.tr("Geoid file"),
OTBUtils.geoidFile(),
OtbUtils.geoidFile(),
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"),
OTBUtils.maxRAMHint(),
OtbUtils.maxRAMHint(),
valuetype=Setting.STRING
))
ProcessingConfig.addSetting(Setting(group, OTBSettings.LOGGER_LEVEL,
ProcessingConfig.addSetting(Setting(group, OtbSettings.LOGGER_LEVEL,
self.tr("Logger level"),
OTBUtils.loggerLevel(),
OtbUtils.loggerLevel(),
valuetype=Setting.STRING,
validator=self.validateLoggerLevel
))
......@@ -96,19 +96,19 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
return True
def unload(self):
for setting in OTBSettings.keys():
for setting in OtbSettings.keys():
ProcessingConfig.removeSetting(setting)
def isActive(self):
return ProcessingConfig.getSetting(OTBSettings.ACTIVATE)
return ProcessingConfig.getSetting(OtbSettings.ACTIVATE)
def setActive(self, active):
ProcessingConfig.setSettingValue(OTBSettings.ACTIVATE, active)
ProcessingConfig.setSettingValue(OtbSettings.ACTIVATE, active)
def createAlgsList(self):
algs = []
try:
folder = OTBUtils.otbFolder()
folder = OtbUtils.otbFolder()
alg_names = []
algs_txt = self.algsFile(folder)
with open(algs_txt) as lines:
......@@ -120,7 +120,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
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, self.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()
......@@ -134,9 +134,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if not self.canBeActivated():
return
version_file = os.path.join(OTBUtils.otbFolder(), 'share', 'doc', 'otb', 'VERSION')
version_file = os.path.join(OtbUtils.otbFolder(), 'share', 'doc', 'otb', 'VERSION')
if not os.path.isfile(version_file):
version_file = os.path.join(OTBUtils.otbFolder(), 'VERSION')
version_file = os.path.join(OtbUtils.otbFolder(), 'VERSION')
if os.path.isfile(version_file):
with open(version_file) as vf:
......@@ -155,8 +155,8 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
self.create_otbcli()
def create_otbcli(self):
otb_folder = self.normalize_path(OTBUtils.otbFolder())
otb_app_path_env = os.pathsep.join(self.appDirs(OTBUtils.appFolder()))
otb_folder = self.normalize_path(OtbUtils.otbFolder())
otb_app_path_env = os.pathsep.join(self.appDirs(OtbUtils.appFolder()))
gdal_data_dir = None
geotiff_csv_dir = None
try:
......@@ -185,7 +185,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line.split("GEOTIFF_CSV=")[1]
otbcli_path = OTBUtils.cliPath()
otbcli_path = OtbUtils.cliPath()
with open(otbcli_path, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep)
......@@ -194,9 +194,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
otb_cli_file.write(export_cmd + "GDAL_DATA=" + "\"" + gdal_data_dir + "\"" + os.linesep)
if geotiff_csv_dir:
otb_cli_file.write(export_cmd + "GEOTIFF_CSV=" + "\"" + geotiff_csv_dir + "\"" + os.linesep)
if OTBUtils.loggerLevel():
otb_cli_file.write(export_cmd + "OTB_LOGGER_LEVEL=" + "\"" + OTBUtils.loggerLevel() + "\"" + os.linesep)
max_ram_hint = OTBUtils.maxRAMHint()
if OtbUtils.loggerLevel():
otb_cli_file.write(export_cmd + "OTB_LOGGER_LEVEL=" + "\"" + OtbUtils.loggerLevel() + "\"" + os.linesep)
max_ram_hint = OtbUtils.maxRAMHint()
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_APPLICATION_PATH=" + "\"" + otb_app_path_env + "\"" + os.linesep)
......@@ -215,7 +215,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def canBeActivated(self):
if not self.isActive():
return False
folder = OTBUtils.otbFolder()
folder = OtbUtils.otbFolder()
if folder and os.path.exists(folder):
if os.path.isfile(self.algsFile(folder)):
return True
......@@ -237,7 +237,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
self.setActive(False)
raise ValueError(self.tr('Cannot activate OTB provider'))
folder = OTBUtils.otbFolder()
folder = OtbUtils.otbFolder()
otb_app_dirs = self.appDirs(v)
if len(otb_app_dirs) < 1:
self.setActive(False)
......@@ -264,7 +264,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
app_name, app_dir, descr_folder + '/']
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
OtbUtils.executeOtb(commands, feedback=None)
if isValid:
utils.iface.messageBar().pushInfo("OTB", "OTB provider is activated from '{}'.".format(folder))
......@@ -332,7 +332,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def tr(self, string, context=''):
if context == '':
context = 'OTBAlgorithmProvider'
context = 'OtbAlgorithmProvider'
return QCoreApplication.translate(context, string)
def defaultVectorFileExtension(self, hasGeometry=True):
......
# -*- coding: utf-8 -*-
"""
***************************************************************************
OTBChoiceWidget.py
OtbChoiceWidget.py
------------------
Date : June 2017
Copyright : (C) 2017 by CS Systemes d'Information (CS SI)
......@@ -33,7 +33,7 @@ from processing.gui.wrappers import (WidgetWrapper,
DIALOG_BATCH,
DIALOG_MODELER)
class OTBChoiceWidgetWrapper(WidgetWrapper):
class OtbChoiceWidgetWrapper(WidgetWrapper):
def createWidget(self):
widget = QComboBox()
widget.addItems(self.param.options)
......@@ -125,7 +125,7 @@ class OTBChoiceWidgetWrapper(WidgetWrapper):
from qgis.core import QgsProcessingParameterDefinition
class OTBParameterChoice(QgsProcessingParameterDefinition):
class OtbParameterChoice(QgsProcessingParameterDefinition):
def __init__(self, name='', description='', options=[], default=None, isSource=False,
multiple=False, optional=False):
......@@ -134,7 +134,7 @@ class OTBParameterChoice(QgsProcessingParameterDefinition):
self.setMetadata({
'widget_wrapper': {
'class': 'otb.OTBChoiceWidget.OTBChoiceWidgetWrapper'}})
'class': 'otb.OtbChoiceWidget.OtbChoiceWidgetWrapper'}})
self.options = options
if default is not None:
......@@ -152,5 +152,6 @@ class OTBParameterChoice(QgsProcessingParameterDefinition):
return True
def type(self):
#This value is written by otbQgisDescriptor.
return 'OTBParameterChoice'
......@@ -18,9 +18,9 @@ __copyright__ = '(C) CNES 2019'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
class OTBSettings(object):
class OtbSettings(object):
"""
OTBSetting's key names
OtbSetting's key names
"""
# Checkbox to enable/disable otb provider (bool).
ACTIVATE = "OTB_ACTIVATE"
......@@ -50,11 +50,11 @@ class OTBSettings(object):
@staticmethod
def keys():
return [
OTBSettings.ACTIVATE,
OTBSettings.FOLDER,
OTBSettings.SRTM_FOLDER,
OTBSettings.GEOID_FILE,
OTBSettings.LOGGER_LEVEL,
OTBSettings.MAX_RAM_HINT
OtbSettings.ACTIVATE,
OtbSettings.FOLDER,
OtbSettings.SRTM_FOLDER,
OtbSettings.GEOID_FILE,
OtbSettings.LOGGER_LEVEL,
OtbSettings.MAX_RAM_HINT
]
......@@ -2,8 +2,8 @@
"""
***************************************************************************
OTBUtils.py
---------------------
OtbUtils.py
-----------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
(C) 2013 by CS Systemes d'information (CS SI)
......@@ -12,6 +12,7 @@
Contributors : Victor Olaya
Julien Malik, Oscar Picas (CS SI) - add functions to manage xml tree
Alexia Mondot (CS SI) - add a trick for OTBApplication SplitImages
Rashad Kanavath (CS SI) - re-integration of provider to QGIS
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -36,39 +37,39 @@ import subprocess
from processing.core.ProcessingConfig import ProcessingConfig
from qgis.core import (Qgis, QgsApplication, QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication
from otb.OTBSettings import OTBSettings
from otb.OtbSettings import OtbSettings
def cliPath():
cli_ext = '.bat' if os.name == 'nt' else ''
return os.path.normpath(os.path.join(QgsApplication.qgisSettingsDirPath(),
'processing', 'qgis_otb_cli' + cli_ext))
def version():
return ProcessingConfig.getSetting(OTBSettings.VERSION) or '0.0.0'
return ProcessingConfig.getSetting(OtbSettings.VERSION) or '0.0.0'
def loggerLevel():
return ProcessingConfig.getSetting(OTBSettings.LOGGER_LEVEL) or 'INFO'
return ProcessingConfig.getSetting(OtbSettings.LOGGER_LEVEL) or 'INFO'
def maxRAMHint():
return ProcessingConfig.getSetting(OTBSettings.MAX_RAM_HINT) or ''
return ProcessingConfig.getSetting(OtbSettings.MAX_RAM_HINT) or ''
def otbFolder():
if ProcessingConfig.getSetting(OTBSettings.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OTBSettings.FOLDER))))
if ProcessingConfig.getSetting(OtbSettings.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OtbSettings.FOLDER))))
else:
return None
def appFolder():
app_folder = ProcessingConfig.getSetting(OTBSettings.APP_FOLDER)
app_folder = ProcessingConfig.getSetting(OtbSettings.APP_FOLDER)
if app_folder:
return os.pathsep.join(app_folder.split(';'))
else:
return None
def srtmFolder():
return ProcessingConfig.getSetting(OTBSettings.SRTM_FOLDER) or ''
return ProcessingConfig.getSetting(OtbSettings.SRTM_FOLDER) or ''
def geoidFile():
return ProcessingConfig.getSetting(OTBSettings.GEOID_FILE) or ''
return ProcessingConfig.getSetting(OtbSettings.GEOID_FILE) or ''
def executeOtb(commands, feedback, addToLog=True):
loglines = []
......@@ -116,5 +117,5 @@ def executeOtb(commands, feedback, addToLog=True):
def tr(string, context=''):
if context == '':
context = 'OTBUtils'
context = 'OtbUtils'
return QCoreApplication.translate(context, string)
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