Skip to content

Commit 09cfc03

Browse files
committed
[processing] Prioritze bundled gdal over framework on OS X
1 parent 7ed87c6 commit 09cfc03

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

python/plugins/processing/algs/gdal/GdalUtils.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
import os
2929
import subprocess
30+
import platform
3031
from PyQt4.QtCore import *
32+
from qgis.core import QgsApplication
3133
from processing.core.ProcessingLog import ProcessingLog
3234

3335
try:
@@ -43,12 +45,27 @@ class GdalUtils:
4345

4446
@staticmethod
4547
def runGdal(commands, progress):
46-
settings = QSettings()
47-
path = unicode(settings.value('/GdalTools/gdalPath', ''))
4848
envval = unicode(os.getenv('PATH'))
49-
if not path.lower() in envval.lower().split(os.pathsep):
50-
envval += '%s%s' % (os.pathsep, path)
51-
os.putenv('PATH', envval)
49+
# We need to give some extra hints to get things picked up on OS X
50+
if platform.system() == 'Darwin':
51+
if os.path.isfile(os.path.join(QgsApplication.prefixPath(), "bin", "gdalinfo")):
52+
# Looks like there's a bundled gdal. Let's use it.
53+
os.environ['PATH'] = "%s%s%s" % (os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep, envval)
54+
os.environ['DYLD_LIBRARY_PATH'] = os.path.join(QgsApplication.prefixPath(), "lib")
55+
else:
56+
# Nothing internal. Let's see if we can find it elsewhere.
57+
settings = QSettings()
58+
path = unicode(settings.value('/GdalTools/gdalPath', ''))
59+
envval += '%s%s' % (os.pathsep, path)
60+
os.putenv('PATH', envval)
61+
else:
62+
# Other platforms should use default gdal finder codepath
63+
settings = QSettings()
64+
path = unicode(settings.value('/GdalTools/gdalPath', ''))
65+
if not path.lower() in envval.lower().split(os.pathsep):
66+
envval += '%s%s' % (os.pathsep, path)
67+
os.putenv('PATH', envval)
68+
5269
loglines = []
5370
loglines.append('GDAL execution console output')
5471
fused_command = ''.join(['%s ' % c for c in commands])
@@ -127,4 +144,4 @@ def escapeAndJoin(strList):
127144
else:
128145
escaped = s
129146
joined += escaped + ' '
130-
return joined.strip()
147+
return joined.strip()

0 commit comments

Comments
 (0)