7
7
"""
8
8
9
9
import os
10
+ import shutil
10
11
import ctypes
11
12
12
13
#: Path to normal KfW installed bin folder
18
19
KFW_DL = "https://web.mit.edu/KERBEROS/dist"
19
20
20
21
21
- def k4w_in_path ():
22
- """Return if the main GSSAPI DLL for KfW is available in the PATH """
22
+ def kfw_available ():
23
+ """Return if the main GSSAPI DLL for KfW can be loaded """
23
24
try : # to load the main GSSAPI DLL
24
25
ctypes .WinDLL ('gssapi64.dll' )
25
26
except OSError : # DLL is not in PATH
@@ -41,14 +42,31 @@ def error_not_found():
41
42
def configure_windows ():
42
43
"""
43
44
Validate that KfW appears to be installed correctly and add it to the
44
- PATH if necessary. In the case that it can't be located, raise an error.
45
+ DLL directories/PATH if necessary. In the case that it can't be located,
46
+ raise an error.
45
47
"""
46
- if k4w_in_path ():
48
+ if kfw_available ():
47
49
return # All set, necessary DLLs should be available
50
+
48
51
if os .path .exists (KFW_BIN ): # In standard location
49
- os .environ ['PATH' ] += os .pathsep + KFW_BIN
50
- if k4w_in_path ():
52
+ try : # to use Python 3.8's DLL handling
53
+ os .add_dll_directory (KFW_BIN )
54
+ except AttributeError : # <3.8, use PATH
55
+ os .environ ['PATH' ] += os .pathsep + KFW_BIN
56
+ if kfw_available ():
51
57
return
58
+
59
+ # Check if kinit is in the PATH which should lead us to the bin folder
60
+ kinit_path = shutil .which ('kinit' ) # KfW provided binary
61
+ if kinit_path : # Non-standard install location
62
+ try : # Most likely >=3.8, otherwise it would have been found already
63
+ os .add_dll_directory (os .path .dirname (kinit_path ))
64
+ except AttributeError : # <3.8, corrupted installation?
65
+ pass
66
+ else :
67
+ if kfw_available ():
68
+ return
69
+
52
70
error_not_found ()
53
71
54
72
0 commit comments