1
1
"""Shared AIX support functions."""
2
2
3
- import subprocess
4
3
import sys
5
4
import sysconfig
6
5
7
6
7
+ # Taken from _osx_support _read_output function
8
+ def _read_cmd_output (commandstring , capture_stderr = False ):
9
+ """Output from successful command execution or None"""
10
+ # Similar to os.popen(commandstring, "r").read(),
11
+ # but without actually using os.popen because that
12
+ # function is not usable during python bootstrap.
13
+ import os
14
+ import contextlib
15
+ fp = open ("/tmp/_aix_support.%s" % (
16
+ os .getpid (),), "w+b" )
17
+
18
+ with contextlib .closing (fp ) as fp :
19
+ if capture_stderr :
20
+ cmd = "%s >'%s' 2>&1" % (commandstring , fp .name )
21
+ else :
22
+ cmd = "%s 2>/dev/null >'%s'" % (commandstring , fp .name )
23
+ return fp .read () if not os .system (cmd ) else None
24
+
25
+
8
26
def _aix_tag (vrtl , bd ):
9
27
# type: (List[int], int) -> str
10
28
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
@@ -30,7 +48,12 @@ def _aix_bos_rte():
30
48
If no builddate is found give a value that will satisfy pep425 related queries
31
49
"""
32
50
# All AIX systems to have lslpp installed in this location
33
- out = subprocess .check_output (["/usr/bin/lslpp" , "-Lqc" , "bos.rte" ])
51
+ # subprocess may not be available during python bootstrap
52
+ try :
53
+ import subprocess
54
+ out = subprocess .check_output (["/usr/bin/lslpp" , "-Lqc" , "bos.rte" ])
55
+ except ImportError :
56
+ out = _read_cmd_output ("/usr/bin/lslpp -Lqc bos.rte" )
34
57
out = out .decode ("utf-8" )
35
58
out = out .strip ().split (":" ) # type: ignore
36
59
_bd = int (out [- 1 ]) if out [- 1 ] != '' else 9988
0 commit comments