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