Skip to content
Permalink
Browse files

[processing] find grass >=7.0

  • Loading branch information
jef-n committed Jan 25, 2017
1 parent d8ed8f4 commit 099e7a77f2c32f469539f542a31df7b0d4b77dd3
Showing with 27 additions and 22 deletions.
  1. +27 −22 python/plugins/processing/algs/grass7/Grass7Utils.py
@@ -91,25 +91,30 @@ def installedVersion(run=False):

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
for command in ["grass73", "grass72", "grass71", "grass70", "grass"]:
with subprocess.Popen(
["{} -v".format(command)],
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:
line = line.split(" ")[-1].strip()
if line.startswith("7."):
Grass7Utils.version = line
Grass7Utils.command = command
return Grass7Utils.version
except:
pass

return None


@staticmethod
def grassPath():
@@ -269,13 +274,13 @@ def prepareGrass7Execution(commands):
if 'GISBASE' in env:
del env['GISBASE']
Grass7Utils.createGrass7BatchJobFileFromGrass7Commands(commands)
os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC
| stat.S_IREAD | stat.S_IWRITE)
os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
if isMac() and os.path.exists(os.path.join(Grass7Utils.grassPath(), 'grass.sh')):
command = os.path.join(Grass7Utils.grassPath(), 'grass.sh') + ' ' \
+ os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
else:
command = 'grass70 ' + os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
print("Grass {}".format(Grass7Utils.version))
command = Grass7Utils.command + ' ' + os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')

return command, env

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

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

0 comments on commit 099e7a7

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