(root)/
Python-3.12.0/
Lib/
_aix_support.py
       1  """Shared AIX support functions."""
       2  
       3  import sys
       4  import sysconfig
       5  
       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  
      26  def _aix_tag(vrtl, bd):
      27      # type: (List[int], int) -> str
      28      # Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
      29      _sz = 32 if sys.maxsize == (2**31-1) else 64
      30      _bd = bd if bd != 0 else 9988
      31      # vrtl[version, release, technology_level]
      32      return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], _bd, _sz)
      33  
      34  
      35  # extract version, release and technology level from a VRMF string
      36  def _aix_vrtl(vrmf):
      37      # type: (str) -> List[int]
      38      v, r, tl = vrmf.split(".")[:3]
      39      return [int(v[-1]), int(r), int(tl)]
      40  
      41  
      42  def _aix_bos_rte():
      43      # type: () -> Tuple[str, int]
      44      """
      45      Return a Tuple[str, int] e.g., ['7.1.4.34', 1806]
      46      The fileset bos.rte represents the current AIX run-time level. It's VRMF and
      47      builddate reflect the current ABI levels of the runtime environment.
      48      If no builddate is found give a value that will satisfy pep425 related queries
      49      """
      50      # All AIX systems to have lslpp installed in this location
      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")
      57      out = out.decode("utf-8")
      58      out = out.strip().split(":")  # type: ignore
      59      _bd = int(out[-1]) if out[-1] != '' else 9988
      60      return (str(out[2]), _bd)
      61  
      62  
      63  def aix_platform():
      64      # type: () -> str
      65      """
      66      AIX filesets are identified by four decimal values: V.R.M.F.
      67      V (version) and R (release) can be retrieved using ``uname``
      68      Since 2007, starting with AIX 5.3 TL7, the M value has been
      69      included with the fileset bos.rte and represents the Technology
      70      Level (TL) of AIX. The F (Fix) value also increases, but is not
      71      relevant for comparing releases and binary compatibility.
      72      For binary compatibility the so-called builddate is needed.
      73      Again, the builddate of an AIX release is associated with bos.rte.
      74      AIX ABI compatibility is described  as guaranteed at: https://www.ibm.com/\
      75      support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html
      76  
      77      For pep425 purposes the AIX platform tag becomes:
      78      "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize)
      79      e.g., "aix-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit
      80      and, "aix-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit
      81      """
      82      vrmf, bd = _aix_bos_rte()
      83      return _aix_tag(_aix_vrtl(vrmf), bd)
      84  
      85  
      86  # extract vrtl from the BUILD_GNU_TYPE as an int
      87  def _aix_bgt():
      88      # type: () -> List[int]
      89      gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
      90      if not gnu_type:
      91          raise ValueError("BUILD_GNU_TYPE is not defined")
      92      return _aix_vrtl(vrmf=gnu_type)
      93  
      94  
      95  def aix_buildtag():
      96      # type: () -> str
      97      """
      98      Return the platform_tag of the system Python was built on.
      99      """
     100      # AIX_BUILDDATE is defined by configure with:
     101      # lslpp -Lcq bos.rte | awk -F:  '{ print $NF }'
     102      build_date = sysconfig.get_config_var("AIX_BUILDDATE")
     103      try:
     104          build_date = int(build_date)
     105      except (ValueError, TypeError):
     106          raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
     107                           f"{build_date!r}")
     108      return _aix_tag(_aix_bgt(), build_date)