Skip to content

Commit

Permalink
osgeo4w: rely on GRASS' GISBASE environment variable instead of
Browse files Browse the repository at this point in the history
detecting the path (ie. use the same version for processing as the
version that the grass plugin uses)
  • Loading branch information
jef-n committed Jan 29, 2019
1 parent 532d1dd commit 806ae86
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -132,9 +132,6 @@ def grassBin():
Find GRASS binary path on the operating system.
Sets global variable Grass7Utils.command
"""
cmdList = ["grass76", "grass74", "grass72", "grass70", "grass",
"grass76.sh", "grass74.sh", "grass72.sh", "grass70.sh", "grass.sh"]

def searchFolder(folder):
"""
Inline function to search for grass binaries into a folder
Expand All @@ -153,6 +150,24 @@ def searchFolder(folder):
path = Grass7Utils.grassPath()
command = None

vn = os.path.join(path, "etc", "VERSIONNUMBER")
if os.path.isfile(vn):
with open(vn, "r") as f:
major, minor, patch = f.readlines()[0].split(' ')[0].split('.')
if patch != 'svn':
patch = ''
cmdList = [
"grass{}{}{}".format(major, minor, patch),
"grass",
"grass{}{}{}.sh".format(major, minor, patch),
"grass.sh"
]
else:
cmdList = [
"grass76", "grass74", "grass72", "grass70", "grass",
"grass76.sh", "grass74.sh", "grass72.sh", "grass70.sh", "grass.sh"
]

# For MS-Windows there is a difference between GRASS Path and GRASS binary
if isWindows():
# If nothing found, use OSGEO4W or QgsPrefix:
Expand All @@ -166,7 +181,7 @@ def searchFolder(folder):
# Search in grassPath
command = searchFolder(path)

# Under GNU/Linux or if everything has failed, use shutil
# If everything has failed, use shutil
if not command:
for cmd in cmdList:
testBin = shutil.which(cmd)
Expand Down Expand Up @@ -203,15 +218,14 @@ def grassPath():
if folder is None:
# Under MS-Windows, we use OSGEO4W or QGIS Path for folder
if isWindows():
if "OSGEO4W_ROOT" in os.environ:
testfolder = os.path.join(str(os.environ['OSGEO4W_ROOT']), "apps")
if "GISBASE" in os.environ:
folder = os.environ["GISBASE"]
else:
testfolder = str(QgsApplication.prefixPath())
testfolder = os.path.join(testfolder, 'grass')
if os.path.isdir(testfolder):
grassfolders = sorted([f for f in os.listdir(testfolder) if f.startswith("grass-7.") and os.path.isdir(os.path.join(testfolder, f))], reverse=True, key=lambda x: [int(v) for v in x[len("grass-"):].split('.') if v != 'svn'])
if grassfolders:
folder = os.path.join(testfolder, grassfolders[0])
testfolder = os.path.join(str(QgsApplication.prefixPath()), 'grass')
if os.path.isdir(testfolder):
grassfolders = sorted([f for f in os.listdir(testfolder) if f.startswith("grass-7.") and os.path.isdir(os.path.join(testfolder, f))], reverse=True, key=lambda x: [int(v) for v in x[len("grass-"):].split('.') if v != 'svn'])
if grassfolders:
folder = os.path.join(testfolder, grassfolders[0])
elif isMac():
# For MacOSX, we scan some well-known directories
# Start with QGIS bundle
Expand Down

0 comments on commit 806ae86

Please sign in to comment.