Skip to content

Commit 099e7a7

Browse files
committed
[processing] find grass >=7.0
1 parent d8ed8f4 commit 099e7a7

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

python/plugins/processing/algs/grass7/Grass7Utils.py

+27-22
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,30 @@ def installedVersion(run=False):
9191

9292
if Grass7Utils.grassPath() is None:
9393
return None
94-
commands = ["grass70 -v"]
95-
with subprocess.Popen(
96-
commands,
97-
shell=True,
98-
stdout=subprocess.PIPE,
99-
stdin=subprocess.DEVNULL,
100-
stderr=subprocess.STDOUT,
101-
universal_newlines=True,
102-
) as proc:
103-
try:
104-
lines = proc.stdout.readlines()
105-
for line in lines:
106-
if "GRASS GIS " in line:
107-
Grass7Utils.version = line.split(" ")[-1].strip()
108-
break
109-
except:
110-
pass
11194

112-
return Grass7Utils.version
95+
for command in ["grass73", "grass72", "grass71", "grass70", "grass"]:
96+
with subprocess.Popen(
97+
["{} -v".format(command)],
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+
line = line.split(" ")[-1].strip()
109+
if line.startswith("7."):
110+
Grass7Utils.version = line
111+
Grass7Utils.command = command
112+
return Grass7Utils.version
113+
except:
114+
pass
115+
116+
return None
117+
113118

114119
@staticmethod
115120
def grassPath():
@@ -269,13 +274,13 @@ def prepareGrass7Execution(commands):
269274
if 'GISBASE' in env:
270275
del env['GISBASE']
271276
Grass7Utils.createGrass7BatchJobFileFromGrass7Commands(commands)
272-
os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC
273-
| stat.S_IREAD | stat.S_IWRITE)
277+
os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
274278
if isMac() and os.path.exists(os.path.join(Grass7Utils.grassPath(), 'grass.sh')):
275279
command = os.path.join(Grass7Utils.grassPath(), 'grass.sh') + ' ' \
276280
+ os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
277281
else:
278-
command = 'grass70 ' + os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
282+
print("Grass {}".format(Grass7Utils.version))
283+
command = Grass7Utils.command + ' ' + os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
279284

280285
return command, env
281286

@@ -449,4 +454,4 @@ def grassHelpPath():
449454
helpPath = os.path.abspath(path)
450455
break
451456

452-
return helpPath if helpPath is not None else 'http://grass.osgeo.org/grass70/manuals/'
457+
return helpPath if helpPath is not None else 'http://grass.osgeo.org/{}/manuals/'.format(Grass7Utils.command)

0 commit comments

Comments
 (0)