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)

(cherry picked from commit 806ae86)
  • Loading branch information
jef-n committed Mar 24, 2019
1 parent e404656 commit f114ad8
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,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 @@ -154,6 +151,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 @@ -167,7 +182,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 @@ -204,15 +219,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 f114ad8

Please sign in to comment.