Module platform
[hide private]
[frames] | no frames]

Module platform

This module tries to retrieve as much platform-identifying data as possible. It makes this information available via function APIs.

If called from the command line, it prints the platform information concatenated as single string to stdout. The output format is useable as part of a filename.


Version: 1.0.4

Copyright: Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 2000-2003, eGenix.com Software GmbH; mailto:info@egenix.com Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. EGENIX.COM SOFTWARE GMBH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !

Classes [hide private]
_popen
Fairly portable (alternative) popen implementation.
Functions [hide private]
 
libc_ver(executable='/usr/bin/python2.5', lib='', version='', chunksize=2048)
Tries to determine the libc version that the file executable (which defaults to the Python interpreter) is linked against.
 
_dist_try_harder(distname, version, id)
Tries some special tricks to get the distribution information in case the default method fails.
 
dist(distname='', version='', id='', supported_dists=('SuSE', 'debian', 'fedora', 'redhat', 'mandrake'))
Tries to determine the name of the Linux OS distribution name.
 
popen(cmd, mode='r', bufsize=None)
Portable popen() interface.
 
_norm_version(version, build='')
Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel).
 
_syscmd_ver(system='', release='', version='', supported_platforms=('win32', 'win16', 'dos', 'os2'))
Tries to figure out the OS version used and returns a tuple (system,release,version).
 
_win32_getvalue(key, name, default='')
Read a value for name from the registry key.
 
win32_ver(release='', version='', csd='', ptype='')
Get additional version information from the Windows Registry and return a tuple (version,csd,ptype) referring to version number, CSD level and OS type (multi/single processor).
 
_mac_ver_lookup(selectors, default=None)
 
_bcd2str(bcd)
 
mac_ver(release='', versioninfo=('', '', ''), machine='')
Get MacOS version information and return it as tuple (release, versioninfo, machine) with versioninfo being a tuple (version, dev_stage, non_release_version).
 
_java_getprop(name, default)
 
java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', ''))
Version interface for Jython.
 
system_alias(system, release, version)
Returns (system,release,version) aliased to common marketing names used for some systems.
 
_platform(*args)
Helper to format the platform string in a filename compatible format e.g.
 
_node(default='')
Helper to determine the node name of this machine.
 
_follow_symlinks(filepath)
In case filepath is a symlink, follow it until a real file is reached.
 
_syscmd_uname(option, default='')
Interface to the system's uname command.
 
_syscmd_file(target, default='')
Interface to the system's file command.
 
_architecture_split(...)
split(string[, maxsplit = 0]) --> list.
 
architecture(executable='/usr/bin/python2.5', bits='', linkage='')
Queries the given executable (defaults to the Python interpreter binary) for various architecture information.
 
uname()
Fairly portable uname interface.
 
system()
Returns the system/OS name, e.g.
 
node()
Returns the computer's network name (which may not be fully qualified)
 
release()
Returns the system's release, e.g.
 
version()
Returns the system's release version, e.g.
 
machine()
Returns the machine type, e.g.
 
processor()
Returns the (true) processor name, e.g.
 
_sys_version()
Returns a parsed version of Python's sys.version as tuple (version, buildno, builddate, compiler) referring to the Python version, build number, build date/time as string and the compiler identification string.
 
python_version()
Returns the Python version as string 'major.minor.patchlevel'
 
python_version_tuple()
Returns the Python version as tuple (major, minor, patchlevel) of strings.
 
python_build()
Returns a tuple (buildno, builddate) stating the Python build number and date as strings.
 
python_compiler()
Returns a string identifying the compiler used for compiling Python.
 
platform(aliased=0, terse=0)
Returns a single string identifying the underlying platform with as much useful information as possible (but no more :).
Variables [hide private]
  _libc_search = re.compile(r'(__libc_init)|(GLIBC_([0-9\.]+))|(...
  _release_filename = re.compile(r'(\w+)[-_](release|version)')
  _release_version = re.compile(r'([\d\.]+)[^\(]*(?:\((.+)\))?')
  _ver_output = re.compile(r'(?:([\w ]+) ([\w\.]+) .*Version ([\...
  _default_architecture = {'dos': ('', 'MSDOS'), 'win16': ('', '...
  _uname_cache = ('Linux', 'syse', '2.6.18-5-686', '#1 SMP Fri J...
  _sys_version_parser = re.compile(r'([\w\.\+]+)\s*\(#?([^,]+),\...
  _sys_version_cache = None
  _platform_cache = {(0, 0): 'Linux-2.6.18-5-686-i686-with-debia...

Imports: sys, string, os, re, _abspath


Function Details [hide private]

libc_ver(executable='/usr/bin/python2.5', lib='', version='', chunksize=2048)

 

Tries to determine the libc version that the file executable (which defaults to the Python interpreter) is linked against.

Returns a tuple of strings (lib,version) which default to the given parameters in case the lookup fails.

Note that the function has intimate knowledge of how different libc versions add symbols to the executable and thus is probably only useable for executables compiled using gcc.

The file is read and scanned in chunks of chunksize bytes.

_dist_try_harder(distname, version, id)

 

Tries some special tricks to get the distribution information in case the default method fails.

Currently supports older SuSE Linux, Caldera OpenLinux and Slackware Linux distributions.

dist(distname='', version='', id='', supported_dists=('SuSE', 'debian', 'fedora', 'redhat', 'mandrake'))

 

Tries to determine the name of the Linux OS distribution name.

The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found.

Returns a tuple (distname,version,id) which default to the args given as parameters.

_syscmd_ver(system='', release='', version='', supported_platforms=('win32', 'win16', 'dos', 'os2'))

 

Tries to figure out the OS version used and returns a tuple (system,release,version).

It uses the "ver" shell command for this which is known to exists on Windows, DOS and OS/2. XXX Others too ?

In case this fails, the given parameters are used as defaults.

_win32_getvalue(key, name, default='')

 

Read a value for name from the registry key.

In case this fails, default is returned.

win32_ver(release='', version='', csd='', ptype='')

 

Get additional version information from the Windows Registry and return a tuple (version,csd,ptype) referring to version number, CSD level and OS type (multi/single processor).

As a hint: ptype returns 'Uniprocessor Free' on single processor NT machines and 'Multiprocessor Free' on multi processor machines. The 'Free' refers to the OS version being free of debugging code. It could also state 'Checked' which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc. (Thomas Heller).

Note: this function only works if Mark Hammond's win32 package is installed and obviously only runs on Win32 compatible platforms.

mac_ver(release='', versioninfo=('', '', ''), machine='')

 
Get MacOS version information and return it as tuple (release,
versioninfo, machine) with versioninfo being a tuple (version,
dev_stage, non_release_version).

Entries which cannot be determined are set to the paramter values
which default to ''. All tuple entries are strings.

Thanks to Mark R. Levinson for mailing documentation links and
code examples for this function. Documentation for the
gestalt() API is available online at:

   http://www.rgaros.nl/gestalt/

java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', ''))

 

Version interface for Jython.

Returns a tuple (release,vendor,vminfo,osinfo) with vminfo being a tuple (vm_name,vm_release,vm_vendor) and osinfo being a tuple (os_name,os_version,os_arch).

Values which cannot be determined are set to the defaults given as parameters (which all default to '').

system_alias(system, release, version)

 

Returns (system,release,version) aliased to common marketing names used for some systems.

It also does some reordering of the information in some cases where it would otherwise cause confusion.

_platform(*args)

 

Helper to format the platform string in a filename compatible format e.g. "system-version-machine".

_syscmd_file(target, default='')

 

Interface to the system's file command.

The function uses the -b option of the file command to have it ommit the filename in its output and if possible the -L option to have the command follow symlinks. It returns default in case the command should fail.

_architecture_split(...)

 

split(string[, maxsplit = 0]) --> list. Split string by the occurrences of pattern.

architecture(executable='/usr/bin/python2.5', bits='', linkage='')

 

Queries the given executable (defaults to the Python interpreter binary) for various architecture information.

Returns a tuple (bits,linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are returned as strings.

Values that cannot be determined are returned as given by the parameter presets. If bits is given as '', the sizeof(pointer) (or sizeof(long) on Python version < 1.5.2) is used as indicator for the supported pointer size.

The function relies on the system's "file" command to do the actual work. This is available on most if not all Unix platforms. On some non-Unix platforms where the "file" command does not exist and the executable is set to the Python interpreter binary defaults from _default_architecture are used.

uname()

 

Fairly portable uname interface. Returns a tuple of strings (system,node,release,version,machine,processor) identifying the underlying platform.

Note that unlike the os.uname function this also returns possible processor information as an additional tuple entry.

Entries which cannot be determined are set to ''.

system()

 

Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.

An empty string is returned if the value cannot be determined.

node()

 

Returns the computer's network name (which may not be fully qualified)

An empty string is returned if the value cannot be determined.

release()

 

Returns the system's release, e.g. '2.2.0' or 'NT'

An empty string is returned if the value cannot be determined.

version()

 

Returns the system's release version, e.g. '#3 on degas'

An empty string is returned if the value cannot be determined.

machine()

 

Returns the machine type, e.g. 'i386'

An empty string is returned if the value cannot be determined.

processor()

 

Returns the (true) processor name, e.g. 'amdk6'

An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for machine(), e.g. NetBSD does this.

_sys_version()

 

Returns a parsed version of Python's sys.version as tuple (version, buildno, builddate, compiler) referring to the Python version, build number, build date/time as string and the compiler identification string.

Note that unlike the Python sys.version, the returned value for the Python version will always include the patchlevel (it defaults to '.0').

python_version()

 

Returns the Python version as string 'major.minor.patchlevel'

Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0).

python_version_tuple()

 

Returns the Python version as tuple (major, minor, patchlevel) of strings.

Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0).

platform(aliased=0, terse=0)

 

Returns a single string identifying the underlying platform with as much useful information as possible (but no more :).

The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended.

If "aliased" is true, the function will use aliases for various platforms that report system names which differ from their common names, e.g. SunOS will be reported as Solaris. The system_alias() function is used to implement this.

Setting terse to true causes the function to return only the absolute minimum information needed to identify the platform.


Variables Details [hide private]

_libc_search

Value:
re.compile(r'(__libc_init)|(GLIBC_([0-9\.]+))|(libc(_\w+)?\.so(?:\.(\d\
[0-9\.]*))?)')

_ver_output

Value:
re.compile(r'(?:([\w ]+) ([\w\.]+) .*Version ([\d\.]+))')

_default_architecture

Value:
{'dos': ('', 'MSDOS'),
 'win16': ('', 'Windows'),
 'win32': ('', 'WindowsPE')}

_uname_cache

Value:
('Linux',
 'syse',
 '2.6.18-5-686',
 '#1 SMP Fri Jun 1 00:47:00 UTC 2007',
 'i686',
 '')

_sys_version_parser

Value:
re.compile(r'([\w\.\+]+)\s*\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*\[\
([^\]]+)\]?')

_platform_cache

Value:
{(0, 0): 'Linux-2.6.18-5-686-i686-with-debian-4.0'}