3535from qgis .PyQt .QtCore import QCoreApplication
3636from processing .core .ProcessingConfig import ProcessingConfig
3737from processing .core .ProcessingLog import ProcessingLog
38+ from processing .core .SilentProgress import SilentProgress
3839from processing .tools .system import userFolder , isWindows , isMac , tempFolder , mkdir
3940from processing .tests .TestData import points
4041
@@ -56,6 +57,8 @@ class Grass7Utils(object):
5657
5758 isGrass7Installed = False
5859
60+ version = None
61+
5962 @staticmethod
6063 def grassBatchJobFilename ():
6164 '''This is used in Linux. This is the batch job that we assign to
@@ -74,11 +77,41 @@ def grassScriptFilename():
7477 filename = os .path .join (userFolder (), filename )
7578 return filename
7679
80+ #~ @staticmethod
81+ #~ def installedVersion():
82+ #~ out = Grass7Utils.executeGrass7("grass -v")
83+ #~ # FIXME: I do not know if this should be removed or let the user enter it
84+ #~ # or something like that... This is just a temporary thing
85+ #~ return '7.0.0'
86+
87+
7788 @staticmethod
78- def getGrassVersion ():
79- # FIXME: I do not know if this should be removed or let the user enter it
80- # or something like that... This is just a temporary thing
81- return '7.0.0'
89+ def installedVersion (run = False ):
90+ if Grass7Utils .isGrass7Installed and not run :
91+ return Grass7Utils .version
92+
93+ if Grass7Utils .grassPath () is None :
94+ return None
95+ commands = ["grass70 -v" ]
96+ with subprocess .Popen (
97+ commands ,
98+ shell = True ,
99+ stdout = subprocess .PIPE ,
100+ stdin = subprocess .DEVNULL ,
101+ stderr = subprocess .STDOUT ,
102+ universal_newlines = True ,
103+ ) as proc :
104+ try :
105+ lines = proc .stdout .readlines ()
106+ for line in lines :
107+ if "GRASS GIS " in line :
108+ Grass7Utils .version = line .split (" " )[- 1 ].strip ()
109+ break
110+ except :
111+ pass
112+
113+ return Grass7Utils .version
114+
82115
83116 @staticmethod
84117 def grassPath ():
@@ -140,7 +173,7 @@ def createGrass7Script(commands):
140173 output .write ('if "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\ bin;%WINGISBASE%\\ lib;%PATH%\n ' )
141174 output .write ('if not "%GRASS_ADDON_PATH%"=="" set PATH=%WINGISBASE%\\ bin;%WINGISBASE%\\ lib;%GRASS_ADDON_PATH%;%PATH%\n ' )
142175 output .write ('\n ' )
143- output .write ('set GRASS_VERSION=' + Grass7Utils .getGrassVersion () + '\n ' )
176+ output .write ('set GRASS_VERSION=' + Grass7Utils .installedVersion () + '\n ' )
144177 output .write ('if not "%LANG%"=="" goto langset\n ' )
145178 output .write ('FOR /F "usebackq delims==" %%i IN (`"%WINGISBASE%\\ etc\\ winlocale"`) DO @set LANG=%%i\n ' )
146179 output .write (':langset\n ' )
0 commit comments