Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 1 | \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 Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 11 | \begin{notice} |
| 12 | Specific platforms listed alphabetically, with Linux included in the |
| 13 | \UNIX{} section. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 14 | \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 Hettinger | 6880431 | 2005-01-01 00:28:46 +0000 | [diff] [blame] | 20 | binary) for various architecture information. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 21 | |
| 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 41 | An empty string is returned if the value cannot be determined. |
| 42 | \end{funcdesc} |
| 43 | |
| 44 | \begin{funcdesc}{node}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 45 | Returns the computer's network name (may not be fully qualified!). |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 46 | An empty string is returned if the value cannot be determined. |
| 47 | \end{funcdesc} |
| 48 | |
| 49 | \begin{funcdesc}{platform}{aliased=0, terse=0} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 50 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 66 | \begin{funcdesc}{processor}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 67 | Returns the (real) processor name, e.g. \code{'amdk6'}. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 68 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 69 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 72 | \end{funcdesc} |
| 73 | |
| 74 | \begin{funcdesc}{python_build}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 75 | Returns a tuple \code{(\var{buildno}, \var{builddate})} stating the |
| 76 | Python build number and date as strings. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 77 | \end{funcdesc} |
| 78 | |
| 79 | \begin{funcdesc}{python_compiler}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 80 | Returns a string identifying the compiler used for compiling Python. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 81 | \end{funcdesc} |
| 82 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame^] | 83 | \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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 99 | \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 Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 107 | Returns the Python version as tuple \code{(\var{major}, \var{minor}, |
| 108 | \var{patchlevel})} of strings. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 109 | |
| 110 | Note that unlike the Python \code{sys.version}, the returned value |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 111 | will always include the patchlevel (it defaults to \code{'0'}). |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 112 | \end{funcdesc} |
| 113 | |
| 114 | \begin{funcdesc}{release}{} |
| 115 | Returns the system's release, e.g. \code{'2.2.0'} or \code{'NT'} |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 116 | An empty string is returned if the value cannot be determined. |
| 117 | \end{funcdesc} |
| 118 | |
| 119 | \begin{funcdesc}{system}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 120 | Returns the system/OS name, e.g. \code{'Linux'}, \code{'Windows'}, |
| 121 | or \code{'Java'}. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 122 | An empty string is returned if the value cannot be determined. |
| 123 | \end{funcdesc} |
| 124 | |
| 125 | \begin{funcdesc}{system_alias}{system, release, version} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 126 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 130 | \end{funcdesc} |
| 131 | |
| 132 | \begin{funcdesc}{version}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 133 | Returns the system's release version, e.g. \code{'\#3 on degas'}. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 134 | An empty string is returned if the value cannot be determined. |
| 135 | \end{funcdesc} |
| 136 | |
| 137 | \begin{funcdesc}{uname}{} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 138 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 142 | |
| 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 Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 149 | |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 150 | \subsection{Java Platform} |
| 151 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 152 | \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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 162 | \end{funcdesc} |
| 163 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 164 | |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 165 | \subsection{Windows Platform} |
| 166 | |
| 167 | \begin{funcdesc}{win32_ver}{release='', version='', csd='', ptype=''} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 168 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 172 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 173 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 179 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 180 | \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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 185 | \end{funcdesc} |
| 186 | |
| 187 | \subsubsection{Win95/98 specific} |
| 188 | |
| 189 | \begin{funcdesc}{popen}{cmd, mode='r', bufsize=None} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 190 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 196 | \end{funcdesc} |
| 197 | |
| 198 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 199 | \subsection{Mac OS Platform} |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 200 | |
| 201 | \begin{funcdesc}{mac_ver}{release='', versioninfo=('','',''), machine=''} |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 202 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 206 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 207 | 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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 212 | \end{funcdesc} |
| 213 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 214 | |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 215 | \subsection{\UNIX{} Platforms} |
| 216 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 217 | \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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 222 | \end{funcdesc} |
| 223 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame^] | 224 | % Document linux_distribution()? |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 225 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 226 | \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 Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 232 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 233 | Note that this function has intimate knowledge of how different |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 234 | libc versions add symbols to the executable is probably only |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 235 | useable for executables compiled using \program{gcc}. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 236 | |
Fred Drake | 4e21dc9 | 2003-10-21 17:58:55 +0000 | [diff] [blame] | 237 | The file is read and scanned in chunks of \var{chunksize} bytes. |
Brett Cannon | 4fc3855 | 2003-10-14 21:45:59 +0000 | [diff] [blame] | 238 | \end{funcdesc} |