From ce9c08f3f669de1910c497d19f9ffbe6ef12e9a4 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 29 Dec 2016 15:16:37 +0200 Subject: [PATCH] [processing] rename GdalOgr provider to Gdal provider Show version numbers in providers descriptions --- ...hmProvider.py => GdalAlgorithmProvider.py} | 7 +-- .../plugins/processing/algs/gdal/GdalUtils.py | 4 ++ .../algs/grass7/Grass7AlgorithmProvider.py | 5 ++- .../processing/algs/grass7/Grass7Utils.py | 43 ++++++++++++++++--- .../algs/otb/OTBAlgorithmProvider.py | 3 +- .../algs/qgis/QGISAlgorithmProvider.py | 2 +- .../algs/saga/SagaAlgorithmProvider.py | 6 +-- .../plugins/processing/algs/saga/SagaUtils.py | 2 +- python/plugins/processing/core/Processing.py | 2 +- .../processing/tests/AlgorithmsTestBase.py | 2 +- 10 files changed, 58 insertions(+), 18 deletions(-) rename python/plugins/processing/algs/gdal/{GdalOgrAlgorithmProvider.py => GdalAlgorithmProvider.py} (96%) diff --git a/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py b/python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py similarity index 96% rename from python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py rename to python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py index 20eb2fc836a..b6467636e37 100644 --- a/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py @@ -86,7 +86,7 @@ pluginPath = os.path.normpath(os.path.join( os.path.split(os.path.dirname(__file__))[0], os.pardir)) -class GdalOgrAlgorithmProvider(AlgorithmProvider): +class GdalAlgorithmProvider(AlgorithmProvider): """This provider incorporates GDAL-based algorithms into the Processing framework. @@ -100,10 +100,11 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider): self.createAlgsList() def getDescription(self): - return self.tr('GDAL/OGR') + version = GdalUtils.readableVersion() + return 'GDAL ({})'.format(version) def getName(self): - return 'gdalogr' + return 'gdal' def getIcon(self): return QIcon(os.path.join(pluginPath, 'images', 'gdal.svg')) diff --git a/python/plugins/processing/algs/gdal/GdalUtils.py b/python/plugins/processing/algs/gdal/GdalUtils.py index 162c8c81dcb..cda99638731 100644 --- a/python/plugins/processing/algs/gdal/GdalUtils.py +++ b/python/plugins/processing/algs/gdal/GdalUtils.py @@ -186,3 +186,7 @@ class GdalUtils(object): @staticmethod def version(): return int(gdal.VersionInfo('VERSION_NUM')) + + @staticmethod + def readableVersion(): + return gdal.VersionInfo('RELEASE_NAME') diff --git a/python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py b/python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py index c81537dc65b..01f3e3ed09c 100644 --- a/python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py +++ b/python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py @@ -92,10 +92,11 @@ class Grass7AlgorithmProvider(AlgorithmProvider): self.algs = self.preloadedAlgs def getDescription(self): - return self.tr('GRASS GIS 7 commands') + version = Grass7Utils.installedVersion() + return 'GRASS GIS ({})'.format(version) if version is not None else "GRASS GIS" def getName(self): - return 'grass70' + return 'grass7' def getIcon(self): return QIcon(os.path.join(pluginPath, 'images', 'grass.svg')) diff --git a/python/plugins/processing/algs/grass7/Grass7Utils.py b/python/plugins/processing/algs/grass7/Grass7Utils.py index b3eb2db5a40..20aef7f8647 100644 --- a/python/plugins/processing/algs/grass7/Grass7Utils.py +++ b/python/plugins/processing/algs/grass7/Grass7Utils.py @@ -35,6 +35,7 @@ from qgis.core import QgsApplication from qgis.PyQt.QtCore import QCoreApplication from processing.core.ProcessingConfig import ProcessingConfig from processing.core.ProcessingLog import ProcessingLog +from processing.core.SilentProgress import SilentProgress from processing.tools.system import userFolder, isWindows, isMac, tempFolder, mkdir from processing.tests.TestData import points @@ -56,6 +57,8 @@ class Grass7Utils(object): isGrass7Installed = False + version = None + @staticmethod def grassBatchJobFilename(): '''This is used in Linux. This is the batch job that we assign to @@ -74,11 +77,41 @@ class Grass7Utils(object): filename = os.path.join(userFolder(), filename) return filename + #~ @staticmethod + #~ def installedVersion(): + #~ out = Grass7Utils.executeGrass7("grass -v") + #~ # FIXME: I do not know if this should be removed or let the user enter it + #~ # or something like that... This is just a temporary thing + #~ return '7.0.0' + + @staticmethod - def getGrassVersion(): - # FIXME: I do not know if this should be removed or let the user enter it - # or something like that... This is just a temporary thing - return '7.0.0' + def installedVersion(run=False): + if Grass7Utils.isGrass7Installed and not run: + return Grass7Utils.version + + if Grass7Utils.grassPath() is None: + return None + commands = ["grass70 -v"] + with subprocess.Popen( + commands, + shell=True, + stdout=subprocess.PIPE, + stdin=subprocess.DEVNULL, + stderr=subprocess.STDOUT, + universal_newlines=True, + ) as proc: + try: + lines = proc.stdout.readlines() + for line in lines: + if "GRASS GIS " in line: + Grass7Utils.version = line.split(" ")[-1].strip() + break + except: + pass + + return Grass7Utils.version + @staticmethod def grassPath(): @@ -140,7 +173,7 @@ class Grass7Utils(object): output.write('if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%PATH%\n') output.write('if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\bin;%WINGISBASE%\\lib;%GRASS_ADDON_PATH%;%PATH%\n') output.write('\n') - output.write('set GRASS_VERSION=' + Grass7Utils.getGrassVersion() + '\n') + output.write('set GRASS_VERSION=' + Grass7Utils.installedVersion() + '\n') output.write('if not "%LANG%"=="" goto langset\n') output.write('FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\etc\\winlocale"`) DO @set LANG=%%i\n') output.write(':langset\n') diff --git a/python/plugins/processing/algs/otb/OTBAlgorithmProvider.py b/python/plugins/processing/algs/otb/OTBAlgorithmProvider.py index 5b33250fbbd..68e9073b783 100644 --- a/python/plugins/processing/algs/otb/OTBAlgorithmProvider.py +++ b/python/plugins/processing/algs/otb/OTBAlgorithmProvider.py @@ -48,7 +48,8 @@ class OTBAlgorithmProvider(AlgorithmProvider): self.activate = True def getDescription(self): - return self.tr("Orfeo Toolbox (Image analysis)") + version = OTBUtils.getInstalledVersion() + return "Orfeo ToolBox ({})".format(version) if version is not None else "Orfeo ToolBox" def getName(self): return "otb" diff --git a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py index 21876a2a331..470559e7cd6 100644 --- a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py +++ b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py @@ -300,7 +300,7 @@ class QGISAlgorithmProvider(AlgorithmProvider): return 'qgis' def getDescription(self): - return self.tr('QGIS geoalgorithms') + return 'QGIS' def getIcon(self): return self._icon diff --git a/python/plugins/processing/algs/saga/SagaAlgorithmProvider.py b/python/plugins/processing/algs/saga/SagaAlgorithmProvider.py index 43dc6e0c06b..931b268f2f5 100644 --- a/python/plugins/processing/algs/saga/SagaAlgorithmProvider.py +++ b/python/plugins/processing/algs/saga/SagaAlgorithmProvider.py @@ -86,7 +86,7 @@ class SagaAlgorithmProvider(AlgorithmProvider): def _loadAlgorithms(self): self.algs = [] - version = SagaUtils.getSagaInstalledVersion(True) + version = SagaUtils.getInstalledVersion(True) if version is None: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Problem with SAGA installation: SAGA was not found or is not correctly installed')) @@ -121,8 +121,8 @@ class SagaAlgorithmProvider(AlgorithmProvider): self.tr('Could not open SAGA algorithm: %s\n%s' % (descriptionFile, str(e)))) def getDescription(self): - version = SagaUtils.getSagaInstalledVersion() - return 'SAGA (%s)' % version if version is not None else 'SAGA' + version = SagaUtils.getInstalledVersion() + return 'SAGA ({})'.format(version) if version is not None else 'SAGA' def getName(self): return 'saga' diff --git a/python/plugins/processing/algs/saga/SagaUtils.py b/python/plugins/processing/algs/saga/SagaUtils.py index 26d4251d2fc..84f144e3881 100644 --- a/python/plugins/processing/algs/saga/SagaUtils.py +++ b/python/plugins/processing/algs/saga/SagaUtils.py @@ -112,7 +112,7 @@ _installedVersion = None _installedVersionFound = False -def getSagaInstalledVersion(runSaga=False): +def getInstalledVersion(runSaga=False): global _installedVersion global _installedVersionFound diff --git a/python/plugins/processing/core/Processing.py b/python/plugins/processing/core/Processing.py index def9b6bd599..f920b8eb33c 100644 --- a/python/plugins/processing/core/Processing.py +++ b/python/plugins/processing/core/Processing.py @@ -57,7 +57,7 @@ from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider from processing.algs.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider -from processing.algs.gdal.GdalOgrAlgorithmProvider import GdalOgrAlgorithmProvider +from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider from processing.algs.r.RAlgorithmProvider import RAlgorithmProvider from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider diff --git a/python/plugins/processing/tests/AlgorithmsTestBase.py b/python/plugins/processing/tests/AlgorithmsTestBase.py index 78325e7056a..bef0f235870 100644 --- a/python/plugins/processing/tests/AlgorithmsTestBase.py +++ b/python/plugins/processing/tests/AlgorithmsTestBase.py @@ -47,7 +47,7 @@ from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider from processing.algs.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider -from processing.algs.gdal.GdalOgrAlgorithmProvider import GdalOgrAlgorithmProvider +from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider from processing.algs.r.RAlgorithmProvider import RAlgorithmProvider from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider