Home | History | Annotate | Download | only in library
      1 :mod:`platform` ---  Access to underlying platform's identifying data
      2 =====================================================================
      3 
      4 .. module:: platform
      5    :synopsis: Retrieves as much platform identifying data as possible.
      6 .. moduleauthor:: Marc-Andre Lemburg <mal (a] egenix.com>
      7 .. sectionauthor:: Bjorn Pettersen <bpettersen (a] corp.fairisaac.com>
      8 
      9 
     10 .. versionadded:: 2.3
     11 
     12 **Source code:** :source:`Lib/platform.py`
     13 
     14 --------------
     15 
     16 .. note::
     17 
     18    Specific platforms listed alphabetically, with Linux included in the Unix
     19    section.
     20 
     21 
     22 Cross Platform
     23 --------------
     24 
     25 
     26 .. function:: architecture(executable=sys.executable, bits='', linkage='')
     27 
     28    Queries the given executable (defaults to the Python interpreter binary) for
     29    various architecture information.
     30 
     31    Returns a tuple ``(bits, linkage)`` which contain information about the bit
     32    architecture and the linkage format used for the executable. Both values are
     33    returned as strings.
     34 
     35    Values that cannot be determined are returned as given by the parameter presets.
     36    If bits is given as ``''``, the :c:func:`sizeof(pointer)` (or
     37    :c:func:`sizeof(long)` on Python version < 1.5.2) is used as indicator for the
     38    supported pointer size.
     39 
     40    The function relies on the system's :file:`file` command to do the actual work.
     41    This is available on most if not all Unix  platforms and some non-Unix platforms
     42    and then only if the executable points to the Python interpreter.  Reasonable
     43    defaults are used when the above needs are not met.
     44 
     45    .. note::
     46 
     47       On Mac OS X (and perhaps other platforms), executable files may be
     48       universal files containing multiple architectures.
     49 
     50       To get at the "64-bitness" of the current interpreter, it is more
     51       reliable to query the :attr:`sys.maxsize` attribute::
     52 
     53          is_64bits = sys.maxsize > 2**32
     54 
     55 
     56 .. function:: machine()
     57 
     58    Returns the machine type, e.g. ``'i386'``. An empty string is returned if the
     59    value cannot be determined.
     60 
     61 
     62 .. function:: node()
     63 
     64    Returns the computer's network name (may not be fully qualified!). An empty
     65    string is returned if the value cannot be determined.
     66 
     67 
     68 .. function:: platform(aliased=0, terse=0)
     69 
     70    Returns a single string identifying the underlying platform with as much useful
     71    information as possible.
     72 
     73    The output is intended to be *human readable* rather than machine parseable. It
     74    may look different on different platforms and this is intended.
     75 
     76    If *aliased* is true, the function will use aliases for various platforms that
     77    report system names which differ from their common names, for example SunOS will
     78    be reported as Solaris.  The :func:`system_alias` function is used to implement
     79    this.
     80 
     81    Setting *terse* to true causes the function to return only the absolute minimum
     82    information needed to identify the platform.
     83 
     84 
     85 .. function:: processor()
     86 
     87    Returns the (real) processor name, e.g. ``'amdk6'``.
     88 
     89    An empty string is returned if the value cannot be determined. Note that many
     90    platforms do not provide this information or simply return the same value as for
     91    :func:`machine`.  NetBSD does this.
     92 
     93 
     94 .. function:: python_build()
     95 
     96    Returns a tuple ``(buildno, builddate)`` stating the Python build number and
     97    date as strings.
     98 
     99 
    100 .. function:: python_compiler()
    101 
    102    Returns a string identifying the compiler used for compiling Python.
    103 
    104 
    105 .. function:: python_branch()
    106 
    107    Returns a string identifying the Python implementation SCM branch.
    108 
    109    .. versionadded:: 2.6
    110 
    111 
    112 .. function:: python_implementation()
    113 
    114    Returns a string identifying the Python implementation. Possible return values
    115    are: 'CPython', 'IronPython', 'Jython', 'PyPy'.
    116 
    117    .. versionadded:: 2.6
    118 
    119 
    120 .. function:: python_revision()
    121 
    122    Returns a string identifying the Python implementation SCM revision.
    123 
    124    .. versionadded:: 2.6
    125 
    126 
    127 .. function:: python_version()
    128 
    129    Returns the Python version as string ``'major.minor.patchlevel'``.
    130 
    131    Note that unlike the Python ``sys.version``, the returned value will always
    132    include the patchlevel (it defaults to 0).
    133 
    134 
    135 .. function:: python_version_tuple()
    136 
    137    Returns the Python version as tuple ``(major, minor, patchlevel)`` of strings.
    138 
    139    Note that unlike the Python ``sys.version``, the returned value will always
    140    include the patchlevel (it defaults to ``'0'``).
    141 
    142 
    143 .. function:: release()
    144 
    145    Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'`` An empty string is
    146    returned if the value cannot be determined.
    147 
    148 
    149 .. function:: system()
    150 
    151    Returns the system/OS name, e.g. ``'Linux'``, ``'Windows'``, or ``'Java'``. An
    152    empty string is returned if the value cannot be determined.
    153 
    154 
    155 .. function:: system_alias(system, release, version)
    156 
    157    Returns ``(system, release, version)`` aliased to common marketing names used
    158    for some systems.  It also does some reordering of the information in some cases
    159    where it would otherwise cause confusion.
    160 
    161 
    162 .. function:: version()
    163 
    164    Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
    165    returned if the value cannot be determined.
    166 
    167 
    168 .. function:: uname()
    169 
    170    Fairly portable uname interface. Returns a tuple of strings ``(system, node,
    171    release, version, machine, processor)`` identifying the underlying platform.
    172 
    173    Note that unlike the :func:`os.uname` function this also returns possible
    174    processor information as additional tuple entry.
    175 
    176    Entries which cannot be determined are set to ``''``.
    177 
    178 
    179 Java Platform
    180 -------------
    181 
    182 
    183 .. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','',''))
    184 
    185    Version interface for Jython.
    186 
    187    Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a
    188    tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple
    189    ``(os_name, os_version, os_arch)``. Values which cannot be determined are set to
    190    the defaults given as parameters (which all default to ``''``).
    191 
    192 
    193 Windows Platform
    194 ----------------
    195 
    196 
    197 .. function:: win32_ver(release='', version='', csd='', ptype='')
    198 
    199    Get additional version information from the Windows Registry and return a tuple
    200    ``(release, version, csd, ptype)`` referring to OS release, version number,
    201    CSD level (service pack) and OS type (multi/single processor).
    202 
    203    As a hint: *ptype* is ``'Uniprocessor Free'`` on single processor NT machines
    204    and ``'Multiprocessor Free'`` on multi processor machines. The *'Free'* refers
    205    to the OS version being free of debugging code. It could also state *'Checked'*
    206    which means the OS version uses debugging code, i.e. code that checks arguments,
    207    ranges, etc.
    208 
    209    .. note::
    210 
    211       This function works best with Mark Hammond's
    212       :mod:`win32all` package installed, but also on Python 2.3 and
    213       later (support for this was added in Python 2.6). It obviously
    214       only runs on Win32 compatible platforms.
    215 
    216 
    217 Win95/98 specific
    218 ^^^^^^^^^^^^^^^^^
    219 
    220 .. function:: popen(cmd, mode='r', bufsize=None)
    221 
    222    Portable :func:`popen` interface.  Find a working popen implementation
    223    preferring :func:`win32pipe.popen`.  On Windows NT, :func:`win32pipe.popen`
    224    should work; on Windows 9x it hangs due to bugs in the MS C library.
    225 
    226 
    227 Mac OS Platform
    228 ---------------
    229 
    230 
    231 .. function:: mac_ver(release='', versioninfo=('','',''), machine='')
    232 
    233    Get Mac OS version information and return it as tuple ``(release, versioninfo,
    234    machine)`` with *versioninfo* being a tuple ``(version, dev_stage,
    235    non_release_version)``.
    236 
    237    Entries which cannot be determined are set to ``''``.  All tuple entries are
    238    strings.
    239 
    240 
    241 Unix Platforms
    242 --------------
    243 
    244 
    245 .. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...))
    246 
    247    This is an old version of the functionality now provided by
    248    :func:`linux_distribution`. For new code, please use the
    249    :func:`linux_distribution`.
    250 
    251    The only difference between the two is that ``dist()`` always
    252    returns the short name of the distribution taken from the
    253    ``supported_dists`` parameter.
    254 
    255    .. deprecated:: 2.6
    256 
    257 .. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1)
    258 
    259    Tries to determine the name of the Linux OS distribution name.
    260 
    261    ``supported_dists`` may be given to define the set of Linux distributions to
    262    look for. It defaults to a list of currently supported Linux distributions
    263    identified by their release file name.
    264 
    265    If ``full_distribution_name`` is true (default), the full distribution read
    266    from the OS is returned. Otherwise the short name taken from
    267    ``supported_dists`` is used.
    268 
    269    Returns a tuple ``(distname,version,id)`` which defaults to the args given as
    270    parameters.  ``id`` is the item in parentheses after the version number.  It
    271    is usually the version codename.
    272 
    273    .. versionadded:: 2.6
    274 
    275 .. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
    276 
    277    Tries to determine the libc version against which the file executable (defaults
    278    to the Python interpreter) is linked.  Returns a tuple of strings ``(lib,
    279    version)`` which default to the given parameters in case the lookup fails.
    280 
    281    Note that this function has intimate knowledge of how different libc versions
    282    add symbols to the executable is probably only usable for executables compiled
    283    using :program:`gcc`.
    284 
    285    The file is read and scanned in chunks of *chunksize* bytes.
    286 
    287