shared aix support functions import sys import sysconfig taken from osxsupport readoutput function def readcmdoutputcommandstring capturestderrfalse similar to os popencommandstring r read but without actually using os popen because that function is not usable during python bootstrap type listint int str infer the abi bitwidth from maxsize assuming 64 bit as the default vrtlversion release technologylevel extract version release and technology level from a vrmf string type str listint type tuplestr int return a tuplestr int e g 7 1 4 34 1806 the fileset bos rte represents the current aix runtime level it s vrmf and builddate reflect the current abi levels of the runtime environment if no builddate is found give a value that will satisfy pep425 related queries all aix systems to have lslpp installed in this location subprocess may not be available during python bootstrap type str aix filesets are identified by four decimal values v r m f v version and r release can be retrieved using uname since 2007 starting with aix 5 3 tl7 the m value has been included with the fileset bos rte and represents the technology level tl of aix the f fix value also increases but is not relevant for comparing releases and binary compatibility for binary compatibility the socalled builddate is needed again the builddate of an aix release is associated with bos rte aix abi compatibility is described as guaranteed at https www ibm com supportknowledgecenterensswaix72installbinarycompatability html for pep425 purposes the aix platform tag becomes aix 1x 1d 02d 04d formatv r tl builddate bitsize e g aix6107141532 for aix 6 1 tl7 bd 1415 32bit and aix6107141564 for aix 6 1 tl7 bd 1415 64bit extract vrtl from the buildgnutype as an int type listint type str return the platformtag of the system python was built on aixbuilddate is defined by configure with lslpp lcq bos rte awk f print nf taken from _osx_support _read_output function output from successful command execution or none similar to os popen commandstring r read but without actually using os popen because that function is not usable during python bootstrap type list int int str infer the abi bitwidth from maxsize assuming 64 bit as the default vrtl version release technology_level extract version release and technology level from a vrmf string type str list int type tuple str int return a tuple str int e g 7 1 4 34 1806 the fileset bos rte represents the current aix run time level it s vrmf and builddate reflect the current abi levels of the runtime environment if no builddate is found give a value that will satisfy pep425 related queries all aix systems to have lslpp installed in this location subprocess may not be available during python bootstrap type ignore type str aix filesets are identified by four decimal values v r m f v version and r release can be retrieved using uname since 2007 starting with aix 5 3 tl7 the m value has been included with the fileset bos rte and represents the technology level tl of aix the f fix value also increases but is not relevant for comparing releases and binary compatibility for binary compatibility the so called builddate is needed again the builddate of an aix release is associated with bos rte aix abi compatibility is described as guaranteed at https www ibm com support knowledgecenter en ssw_aix_72 install binary_compatability html for pep425 purposes the aix platform tag becomes aix 1x 1d 02d 04d format v r tl builddate bitsize e g aix 6107 1415 32 for aix 6 1 tl7 bd 1415 32 bit and aix 6107 1415 64 for aix 6 1 tl7 bd 1415 64 bit extract vrtl from the build_gnu_type as an int type list int type str return the platform_tag of the system python was built on aix_builddate is defined by configure with lslpp lcq bos rte awk f print nf
import sys
import sysconfig



def _read_cmd_output(commandstring, capture_stderr=False):
    
    
    
    
    import os
    import contextlib
    fp = open("/tmp/_aix_support.%s"%(
        os.getpid(),), "w+b")

    with contextlib.closing(fp) as fp:
        if capture_stderr:
            cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
        else:
            cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
        return fp.read() if not os.system(cmd) else None


def _aix_tag(vrtl, bd):
    
    
    _sz = 32 if sys.maxsize == (2**31-1) else 64
    _bd = bd if bd != 0 else 9988
    
    return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], _bd, _sz)



def _aix_vrtl(vrmf):
    
    v, r, tl = vrmf.split(".")[:3]
    return [int(v[-1]), int(r), int(tl)]


def _aix_bos_rte():
    
    
    
    
    try:
        import subprocess
        out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
    except ImportError:
        out = _read_cmd_output("/usr/bin/lslpp -Lqc bos.rte")
    out = out.decode("utf-8")
    out = out.strip().split(":")  
    _bd = int(out[-1]) if out[-1] != '' else 9988
    return (str(out[2]), _bd)


def aix_platform():
    
    
    vrmf, bd = _aix_bos_rte()
    return _aix_tag(_aix_vrtl(vrmf), bd)



def _aix_bgt():
    
    gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
    if not gnu_type:
        raise ValueError("BUILD_GNU_TYPE is not defined")
    return _aix_vrtl(vrmf=gnu_type)


def aix_buildtag():
    
    
    
    
    build_date = sysconfig.get_config_var("AIX_BUILDDATE")
    try:
        build_date = int(build_date)
    except (ValueError, TypeError):
        raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
                         f"{build_date!r}")
    return _aix_tag(_aix_bgt(), build_date)