27
27
28
28
import os
29
29
import subprocess
30
+ import platform
30
31
from PyQt4 .QtCore import *
32
+ from qgis .core import QgsApplication
31
33
from processing .core .ProcessingLog import ProcessingLog
32
34
33
35
try :
@@ -43,12 +45,27 @@ class GdalUtils:
43
45
44
46
@staticmethod
45
47
def runGdal (commands , progress ):
46
- settings = QSettings ()
47
- path = unicode (settings .value ('/GdalTools/gdalPath' , '' ))
48
48
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
+
52
69
loglines = []
53
70
loglines .append ('GDAL execution console output' )
54
71
fused_command = '' .join (['%s ' % c for c in commands ])
@@ -127,4 +144,4 @@ def escapeAndJoin(strList):
127
144
else :
128
145
escaped = s
129
146
joined += escaped + ' '
130
- return joined .strip ()
147
+ return joined .strip ()
0 commit comments