Skip to content
Permalink
Browse files

Remove OtbSettings class and put constants for key names in OtbUtils

  • Loading branch information
rkanavath authored and nyalldawson committed Mar 20, 2019
1 parent 07d17a0 commit d3a1c6536814979d8542e9920f248368e226fdcc
@@ -36,7 +36,6 @@

from processing.core.ProcessingConfig import ProcessingConfig, Setting
from processing.algs.otb.OtbUtils import OtbUtils
from processing.algs.otb.OtbSettings import OtbSettings
from processing.algs.otb.OtbAlgorithm import OtbAlgorithm

class OtbAlgorithmProvider(QgsProcessingProvider):
@@ -50,35 +49,35 @@ def __init__(self):
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, OtbUtils.ACTIVATE, self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(group, OtbUtils.FOLDER,
self.tr("OTB folder"),
OtbUtils.otbFolder(),
valuetype=Setting.FOLDER,
validator=self.validateOtbFolder
))
ProcessingConfig.addSetting(Setting(group, OtbSettings.APP_FOLDER,
ProcessingConfig.addSetting(Setting(group, OtbUtils.APP_FOLDER,
self.tr("OTB application folder"),
OtbUtils.appFolder(),
valuetype=Setting.MULTIPLE_FOLDERS,
validator=self.validateAppFolders
))
ProcessingConfig.addSetting(Setting(group, OtbSettings.SRTM_FOLDER,
ProcessingConfig.addSetting(Setting(group, OtbUtils.SRTM_FOLDER,
self.tr("SRTM tiles folder"),
OtbUtils.srtmFolder(),
valuetype=Setting.FOLDER
))
ProcessingConfig.addSetting(Setting(group, OtbSettings.GEOID_FILE,
ProcessingConfig.addSetting(Setting(group, OtbUtils.GEOID_FILE,
self.tr("Geoid file"),
OtbUtils.geoidFile(),
valuetype=Setting.FOLDER
))
ProcessingConfig.addSetting(Setting(group, OtbSettings.MAX_RAM_HINT,
ProcessingConfig.addSetting(Setting(group, OtbUtils.MAX_RAM_HINT,
self.tr("Maximum RAM to use"),
OtbUtils.maxRAMHint(),
valuetype=Setting.STRING
))
ProcessingConfig.addSetting(Setting(group, OtbSettings.LOGGER_LEVEL,
ProcessingConfig.addSetting(Setting(group, OtbUtils.LOGGER_LEVEL,
self.tr("Logger level"),
OtbUtils.loggerLevel(),
valuetype=Setting.STRING,
@@ -89,14 +88,14 @@ def load(self):
return True

def unload(self):
for setting in OtbSettings.keys():
for setting in OtbUtils.settingNames():
ProcessingConfig.removeSetting(setting)

def isActive(self):
return ProcessingConfig.getSetting(OtbSettings.ACTIVATE)
return ProcessingConfig.getSetting(OtbUtils.ACTIVATE)

def setActive(self, active):
ProcessingConfig.setSettingValue(OtbSettings.ACTIVATE, active)
ProcessingConfig.setSettingValue(OtbUtils.ACTIVATE, active)

def createAlgsList(self):
algs = []

This file was deleted.

@@ -31,51 +31,85 @@
__revision__ = '$Format:%H$'

import os
import sys
import re
import subprocess

from processing.core.ProcessingConfig import ProcessingConfig
from qgis.core import (Qgis, QgsApplication, QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication
from processing.algs.otb.OtbSettings import OtbSettings


class OtbUtils:
# Checkbox to enable/disable otb provider (bool).
ACTIVATE = "OTB_ACTIVATE"

# Path to otb installation folder (string, directory).
FOLDER = "OTB_FOLDER"

# Path to otb application folder. multiple paths are supported (string, directory).
APP_FOLDER = "OTB_APP_FOLDER"

# A string to hold current version number. Useful for bug reporting.
VERSION = "OTB_VERSION"

# Default directory were DEM tiles are stored. It should only contain ```.hgt`` or or georeferenced ``.tif`` files. Empty if not set (no directory set).
SRTM_FOLDER = "OTB_SRTM_FOLDER"

# Default path to the geoid file that will be used to retrieve height of DEM above ellipsoid. Empty if not set (no geoid set).
GEOID_FILE = "OTB_GEOID_FILE"

# Default maximum memory that OTB should use for processing, in MB. If not set, default value is 128 MB.
# This is set through environment variable ``OTB_MAX_RAM_HINT``
MAX_RAM_HINT = 'OTB_MAX_RAM_HINT'

# ``OTB_LOGGER_LEVEL``: Default level of logging for OTB. Should be one of ``DEBUG``, ``INFO``, ``WARNING``, ``CRITICAL`` or ``FATAL``, by increasing order of priority. Only messages with a higher priority than the level of logging will be displayed. If not set, default level is ``INFO``.
LOGGER_LEVEL = 'OTB_LOGGER_LEVEL'

@staticmethod
def settingNames():
return [
OtbUtils.ACTIVATE,
OtbUtils.FOLDER,
OtbUtils.SRTM_FOLDER,
OtbUtils.GEOID_FILE,
OtbUtils.LOGGER_LEVEL,
OtbUtils.MAX_RAM_HINT
]

@staticmethod
def version():
return ProcessingConfig.getSetting(OtbSettings.VERSION) or '0.0.0'
return ProcessingConfig.getSetting(OtbUtils.VERSION) or '0.0.0'

@staticmethod
def loggerLevel():
return ProcessingConfig.getSetting(OtbSettings.LOGGER_LEVEL) or 'INFO'
return ProcessingConfig.getSetting(OtbUtils.LOGGER_LEVEL) or 'INFO'

@staticmethod
def maxRAMHint():
return ProcessingConfig.getSetting(OtbSettings.MAX_RAM_HINT) or ''
return ProcessingConfig.getSetting(OtbUtils.MAX_RAM_HINT) or ''

@staticmethod
def otbFolder():
if ProcessingConfig.getSetting(OtbSettings.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OtbSettings.FOLDER))))
if ProcessingConfig.getSetting(OtbUtils.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OtbUtils.FOLDER))))
else:
return None

@staticmethod
def appFolder():
app_folder = ProcessingConfig.getSetting(OtbSettings.APP_FOLDER)
app_folder = ProcessingConfig.getSetting(OtbUtils.APP_FOLDER)
if app_folder:
return os.pathsep.join(app_folder.split(';'))
else:
return None

@staticmethod
def srtmFolder():
return ProcessingConfig.getSetting(OtbSettings.SRTM_FOLDER) or ''
return ProcessingConfig.getSetting(OtbUtils.SRTM_FOLDER) or ''

@staticmethod
def geoidFile():
return ProcessingConfig.getSetting(OtbSettings.GEOID_FILE) or ''
return ProcessingConfig.getSetting(OtbUtils.GEOID_FILE) or ''

@staticmethod
def getExecutableInPath(path, exe):
@@ -48,7 +48,7 @@
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
from processing.algs.otb.OtbAlgorithm import OtbAlgorithm
from processing.algs.otb.OtbAlgorithmProvider import OtbAlgorithmProvider
from processing.algs.otb.OtbSettings import OtbSettings
from processing.algs.otb.OtbUtils import OtbUtils
from processing.algs.otb.OtbChoiceWidget import OtbParameterChoice, OtbChoiceWidgetWrapper
import AlgorithmsTestBase

@@ -165,8 +165,8 @@ def setUpClass(cls):
from processing.core.Processing import Processing
Processing.initialize()
ProcessingConfig.setSettingValue("OTB_ACTIVATE", True)
ProcessingConfig.setSettingValue(OtbSettings.FOLDER, OTB_INSTALL_DIR)
ProcessingConfig.setSettingValue(OtbSettings.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications'))
ProcessingConfig.setSettingValue(OtbUtils.FOLDER, OTB_INSTALL_DIR)
ProcessingConfig.setSettingValue(OtbUtils.APP_FOLDER, os.path.join(OTB_INSTALL_DIR, 'lib', 'otb', 'applications'))
ProcessingConfig.readSettings()
# Refresh OTB Algorithms after settings are changed.
for p in QgsApplication.processingRegistry().providers():

0 comments on commit d3a1c65

Please sign in to comment.
You can’t perform that action at this time.