25
25
26
26
import glob
27
27
import os
28
+ import platform
28
29
import struct
29
30
import sys
30
31
from .utils .compat import PY3 , WIDE_CHARS , a2u
@@ -41,11 +42,11 @@ def _import_pyswat():
41
42
42
43
import importlib
43
44
44
- platform = 'linux'
45
+ plat = 'linux'
45
46
if sys .platform .lower ().startswith ('win' ):
46
- platform = 'win'
47
+ plat = 'win'
47
48
elif sys .platform .lower ().startswith ('darwin' ):
48
- platform = 'mac'
49
+ plat = 'mac'
49
50
50
51
if PY3 :
51
52
libname = '_py%s%sswat' % (sys .version_info [0 ], sys .version_info [1 ])
@@ -55,14 +56,14 @@ def _import_pyswat():
55
56
libname = '_pyswat'
56
57
57
58
# Bail out if we aren't on Linux
58
- # if platform != 'linux':
59
+ # if plat != 'linux':
59
60
# raise ValueError('Currently, Linux is the only platform with support '
60
61
# 'for the binary protocol. You must connect to CAS '
61
62
# 'using the REST interface on this platform.')
62
63
63
64
# Bail out if the C extension doesn't exist
64
65
if not glob .glob (os .path .join (os .path .dirname (__file__ ), 'lib' ,
65
- platform , libname + '.*' )):
66
+ plat , libname + '.*' )):
66
67
raise ValueError ('The extensions for the binary protocol have not been '
67
68
'installed. You can either install them using the full '
68
69
'platform-dependent install file, or use the REST interface '
@@ -85,7 +86,7 @@ def _import_pyswat():
85
86
86
87
# Try to import the C extension
87
88
try :
88
- _pyswat = importlib .import_module ('.lib.%s.%s' % (platform , libname ),
89
+ _pyswat = importlib .import_module ('.lib.%s.%s' % (plat , libname ),
89
90
package = 'swat' )
90
91
91
92
except ImportError :
@@ -141,11 +142,24 @@ def InitializeTK(*args, **kwargs):
141
142
''' Initialize the TK subsystem (importing _pyswat as needed) '''
142
143
if _pyswat is None :
143
144
_import_pyswat ()
144
- out = _pyswat .InitializeTK (* args , ** kwargs )
145
- # Override TKPATH after initialization so that other TK applications
146
- # won't be affected.
147
- if sys .platform .lower ().startswith ('win' ) and 'TKPATH' not in os .environ :
148
- os .environ ['TKPATH' ] = os .pathsep
145
+
146
+ # Patch ppc linux path
147
+ set_tkpath_env = 'ppc' in platform .machine () and 'TKPATH' not in os .environ
148
+ if set_tkpath_env and args :
149
+ os .environ ['TKPATH' ] = args [0 ]
150
+
151
+ try :
152
+ out = _pyswat .InitializeTK (* args , ** kwargs )
153
+
154
+ finally :
155
+ if set_tkpath_env :
156
+ del os .environ ['TKPATH' ]
157
+
158
+ # Override TKPATH after initialization so that other TK applications
159
+ # won't be affected (Windows only).
160
+ if sys .platform .lower ().startswith ('win' ) and 'TKPATH' not in os .environ :
161
+ os .environ ['TKPATH' ] = os .pathsep
162
+
149
163
return out
150
164
151
165
0 commit comments