blob: a2f19133a3c658a857609a4a5b7a6e202df98d3d [file] [log] [blame]
Brett Cannon4fc38552003-10-14 21:45:59 +00001\section{\module{platform} ---
2 Access to underlying platform's identifying data.}
3
4\declaremodule{standard}{platform}
5\modulesynopsis{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\versionadded{2.3}
10
Fred Drake4e21dc92003-10-21 17:58:55 +000011\begin{notice}
12 Specific platforms listed alphabetically, with Linux included in the
13 \UNIX{} section.
Brett Cannon4fc38552003-10-14 21:45:59 +000014\end{notice}
15
16\subsection{Cross Platform}
17
18\begin{funcdesc}{architecture}{executable=sys.executable, bits='', linkage=''}
19 Queries the given executable (defaults to the Python interpreter
Raymond Hettinger68804312005-01-01 00:28:46 +000020 binary) for various architecture information.
Brett Cannon4fc38552003-10-14 21:45:59 +000021
22 Returns a tuple \code{(bits, linkage)} which contain information about
23 the bit architecture and the linkage format used for the
24 executable. Both values are returned as strings.
25
26 Values that cannot be determined are returned as given by the
27 parameter presets. If bits is given as \code{''}, the
28 \cfunction{sizeof(pointer)}
29 (or \cfunction{sizeof(long)} on Python version < 1.5.2) is used as
30 indicator for the supported pointer size.
31
32 The function relies on the system's \file{file} command to do the
33 actual work. This is available on most if not all \UNIX{}
34 platforms and some non-\UNIX{} platforms and then only if the
35 executable points to the Python interpreter. Reasonable defaults
36 are used when the above needs are not met.
37\end{funcdesc}
38
39\begin{funcdesc}{machine}{}
40 Returns the machine type, e.g. \code{'i386'}.
Brett Cannon4fc38552003-10-14 21:45:59 +000041 An empty string is returned if the value cannot be determined.
42\end{funcdesc}
43
44\begin{funcdesc}{node}{}
Fred Drake4e21dc92003-10-21 17:58:55 +000045 Returns the computer's network name (may not be fully qualified!).
Brett Cannon4fc38552003-10-14 21:45:59 +000046 An empty string is returned if the value cannot be determined.
47\end{funcdesc}
48
49\begin{funcdesc}{platform}{aliased=0, terse=0}
Fred Drake4e21dc92003-10-21 17:58:55 +000050 Returns a single string identifying the underlying platform
51 with as much useful information as possible.
52
53 The output is intended to be \emph{human readable} rather than
54 machine parseable. It may look different on different platforms and
55 this is intended.
56
57 If \var{aliased} is true, the function will use aliases for various
58 platforms that report system names which differ from their common
59 names, for example SunOS will be reported as Solaris. The
60 \function{system_alias()} function is used to implement this.
61
62 Setting \var{terse} to true causes the function to return only the
63 absolute minimum information needed to identify the platform.
Brett Cannon4fc38552003-10-14 21:45:59 +000064\end{funcdesc}
65
Brett Cannon4fc38552003-10-14 21:45:59 +000066\begin{funcdesc}{processor}{}
Fred Drake4e21dc92003-10-21 17:58:55 +000067 Returns the (real) processor name, e.g. \code{'amdk6'}.
Brett Cannon4fc38552003-10-14 21:45:59 +000068
Fred Drake4e21dc92003-10-21 17:58:55 +000069 An empty string is returned if the value cannot be determined. Note
70 that many platforms do not provide this information or simply return
71 the same value as for \function{machine()}. NetBSD does this.
Brett Cannon4fc38552003-10-14 21:45:59 +000072\end{funcdesc}
73
74\begin{funcdesc}{python_build}{}
Fred Drake4e21dc92003-10-21 17:58:55 +000075 Returns a tuple \code{(\var{buildno}, \var{builddate})} stating the
76 Python build number and date as strings.
Brett Cannon4fc38552003-10-14 21:45:59 +000077\end{funcdesc}
78
79\begin{funcdesc}{python_compiler}{}
Fred Drake4e21dc92003-10-21 17:58:55 +000080 Returns a string identifying the compiler used for compiling Python.
Brett Cannon4fc38552003-10-14 21:45:59 +000081\end{funcdesc}
82
Guido van Rossumd8faa362007-04-27 19:54:29 +000083\begin{funcdesc}{python_branch}{}
84 Returns a string identifying the Python implementation SCM branch.
85 \versionadded{2.6}
86\end{funcdesc}
87
88\begin{funcdesc}{python_implementation}{}
89 Returns a string identifying the Python implementation.
90 Possible return values are: 'CPython', 'IronPython', 'Jython'
91 \versionadded{2.6}
92\end{funcdesc}
93
94\begin{funcdesc}{python_revision}{}
95 Returns a string identifying the Python implementation SCM revision.
96 \versionadded{2.6}
97\end{funcdesc}
98
Brett Cannon4fc38552003-10-14 21:45:59 +000099\begin{funcdesc}{python_version}{}
100 Returns the Python version as string \code{'major.minor.patchlevel'}
101
102 Note that unlike the Python \code{sys.version}, the returned value
103 will always include the patchlevel (it defaults to 0).
104\end{funcdesc}
105
106\begin{funcdesc}{python_version_tuple}{}
Fred Drake4e21dc92003-10-21 17:58:55 +0000107 Returns the Python version as tuple \code{(\var{major}, \var{minor},
108 \var{patchlevel})} of strings.
Brett Cannon4fc38552003-10-14 21:45:59 +0000109
110 Note that unlike the Python \code{sys.version}, the returned value
Fred Drake4e21dc92003-10-21 17:58:55 +0000111 will always include the patchlevel (it defaults to \code{'0'}).
Brett Cannon4fc38552003-10-14 21:45:59 +0000112\end{funcdesc}
113
114\begin{funcdesc}{release}{}
115 Returns the system's release, e.g. \code{'2.2.0'} or \code{'NT'}
Brett Cannon4fc38552003-10-14 21:45:59 +0000116 An empty string is returned if the value cannot be determined.
117\end{funcdesc}
118
119\begin{funcdesc}{system}{}
Fred Drake4e21dc92003-10-21 17:58:55 +0000120 Returns the system/OS name, e.g. \code{'Linux'}, \code{'Windows'},
121 or \code{'Java'}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000122 An empty string is returned if the value cannot be determined.
123\end{funcdesc}
124
125\begin{funcdesc}{system_alias}{system, release, version}
Fred Drake4e21dc92003-10-21 17:58:55 +0000126 Returns \code{(\var{system}, \var{release}, \var{version})} aliased
127 to common marketing names used for some systems. It also does some
128 reordering of the information in some cases where it would otherwise
129 cause confusion.
Brett Cannon4fc38552003-10-14 21:45:59 +0000130\end{funcdesc}
131
132\begin{funcdesc}{version}{}
Fred Drake4e21dc92003-10-21 17:58:55 +0000133 Returns the system's release version, e.g. \code{'\#3 on degas'}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000134 An empty string is returned if the value cannot be determined.
135\end{funcdesc}
136
137\begin{funcdesc}{uname}{}
Fred Drake4e21dc92003-10-21 17:58:55 +0000138 Fairly portable uname interface. Returns a tuple of strings
139 \code{(\var{system}, \var{node}, \var{release}, \var{version},
140 \var{machine}, \var{processor})} identifying the underlying
141 platform.
Brett Cannon4fc38552003-10-14 21:45:59 +0000142
143 Note that unlike the \function{os.uname()} function this also returns
144 possible processor information as additional tuple entry.
145
146 Entries which cannot be determined are set to \code{''}.
147\end{funcdesc}
148
Fred Drake4e21dc92003-10-21 17:58:55 +0000149
Brett Cannon4fc38552003-10-14 21:45:59 +0000150\subsection{Java Platform}
151
Fred Drake4e21dc92003-10-21 17:58:55 +0000152\begin{funcdesc}{java_ver}{release='', vendor='', vminfo=('','',''),
153 osinfo=('','','')}
154 Version interface for JPython.
155
156 Returns a tuple \code{(\var{release}, \var{vendor}, \var{vminfo},
157 \var{osinfo})} with \var{vminfo} being a tuple \code{(\var{vm_name},
158 \var{vm_release}, \var{vm_vendor})} and \var{osinfo} being a tuple
159 \code{(\var{os_name}, \var{os_version}, \var{os_arch})}.
160 Values which cannot be determined are set to the defaults
161 given as parameters (which all default to \code{''}).
Brett Cannon4fc38552003-10-14 21:45:59 +0000162\end{funcdesc}
163
Fred Drake4e21dc92003-10-21 17:58:55 +0000164
Brett Cannon4fc38552003-10-14 21:45:59 +0000165\subsection{Windows Platform}
166
167\begin{funcdesc}{win32_ver}{release='', version='', csd='', ptype=''}
Fred Drake4e21dc92003-10-21 17:58:55 +0000168 Get additional version information from the Windows Registry
169 and return a tuple \code{(\var{version}, \var{csd}, \var{ptype})}
170 referring to version number, CSD level and OS type (multi/single
171 processor).
Brett Cannon4fc38552003-10-14 21:45:59 +0000172
Fred Drake4e21dc92003-10-21 17:58:55 +0000173 As a hint: \var{ptype} is \code{'Uniprocessor Free'} on single
174 processor NT machines and \code{'Multiprocessor Free'} on multi
175 processor machines. The \emph{'Free'} refers to the OS version being
176 free of debugging code. It could also state \emph{'Checked'} which
177 means the OS version uses debugging code, i.e. code that
178 checks arguments, ranges, etc.
Brett Cannon4fc38552003-10-14 21:45:59 +0000179
Fred Drake4e21dc92003-10-21 17:58:55 +0000180 \begin{notice}[note]
181 This function only works if Mark Hammond's \module{win32all}
182 package is installed and (obviously) only runs on Win32
183 compatible platforms.
184 \end{notice}
Brett Cannon4fc38552003-10-14 21:45:59 +0000185\end{funcdesc}
186
187\subsubsection{Win95/98 specific}
188
189\begin{funcdesc}{popen}{cmd, mode='r', bufsize=None}
Fred Drake4e21dc92003-10-21 17:58:55 +0000190 Portable \function{popen()} interface. Find a working popen
191 implementation preferring \function{win32pipe.popen()}. On Windows
192 NT, \function{win32pipe.popen()} should work; on Windows 9x it hangs
193 due to bugs in the MS C library.
194 % This KnowledgeBase article appears to be missing...
195 %See also \ulink{MS KnowledgeBase article Q150956}{}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000196\end{funcdesc}
197
198
Fred Drake4e21dc92003-10-21 17:58:55 +0000199\subsection{Mac OS Platform}
Brett Cannon4fc38552003-10-14 21:45:59 +0000200
201\begin{funcdesc}{mac_ver}{release='', versioninfo=('','',''), machine=''}
Fred Drake4e21dc92003-10-21 17:58:55 +0000202 Get Mac OS version information and return it as tuple
203 \code{(\var{release}, \var{versioninfo}, \var{machine})} with
204 \var{versioninfo} being a tuple \code{(\var{version},
205 \var{dev_stage}, \var{non_release_version})}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000206
Fred Drake4e21dc92003-10-21 17:58:55 +0000207 Entries which cannot be determined are set to \code{''}. All tuple
208 entries are strings.
209
210 Documentation for the underlying \cfunction{gestalt()} API is
211 available online at \url{http://www.rgaros.nl/gestalt/}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000212\end{funcdesc}
213
Fred Drake4e21dc92003-10-21 17:58:55 +0000214
Brett Cannon4fc38552003-10-14 21:45:59 +0000215\subsection{\UNIX{} Platforms}
216
Fred Drake4e21dc92003-10-21 17:58:55 +0000217\begin{funcdesc}{dist}{distname='', version='', id='',
218 supported_dists=('SuSE','debian','redhat','mandrake')}
219 Tries to determine the name of the OS distribution name
220 Returns a tuple \code{(\var{distname}, \var{version}, \var{id})}
221 which defaults to the args given as parameters.
Brett Cannon4fc38552003-10-14 21:45:59 +0000222\end{funcdesc}
223
Guido van Rossumd8faa362007-04-27 19:54:29 +0000224% Document linux_distribution()?
Brett Cannon4fc38552003-10-14 21:45:59 +0000225
Fred Drake4e21dc92003-10-21 17:58:55 +0000226\begin{funcdesc}{libc_ver}{executable=sys.executable, lib='',
227 version='', chunksize=2048}
228 Tries to determine the libc version against which the file
229 executable (defaults to the Python interpreter) is linked. Returns
230 a tuple of strings \code{(\var{lib}, \var{version})} which default
231 to the given parameters in case the lookup fails.
Brett Cannon4fc38552003-10-14 21:45:59 +0000232
Fred Drake4e21dc92003-10-21 17:58:55 +0000233 Note that this function has intimate knowledge of how different
Brett Cannon4fc38552003-10-14 21:45:59 +0000234 libc versions add symbols to the executable is probably only
Fred Drake4e21dc92003-10-21 17:58:55 +0000235 useable for executables compiled using \program{gcc}.
Brett Cannon4fc38552003-10-14 21:45:59 +0000236
Fred Drake4e21dc92003-10-21 17:58:55 +0000237 The file is read and scanned in chunks of \var{chunksize} bytes.
Brett Cannon4fc38552003-10-14 21:45:59 +0000238\end{funcdesc}