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