Lines Matching +full:min +full:- +full:os +full:- +full:version

3 """ This module tries to retrieve as much platform-identifying data as
11 # This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
19 # * support for MS-DOS (PythonDX ?)
23 # Many thanks to all those who helped adding platform-specific
38 # 1.0.8 - changed Windows support to read version from kernel32.dll
39 # 1.0.7 - added DEV_NULL
40 # 1.0.6 - added linux_distribution()
41 # 1.0.5 - fixed Java support to allow running the module on Jython
42 # 1.0.4 - added IronPython support
43 # 1.0.3 - added normalization of Windows system name
44 # 1.0.2 - added more Windows support
45 # 1.0.1 - reformatted to make doc.py happy
46 # 1.0.0 - reformatted a bit and checked into Python CVS
47 # 0.8.0 - added sys.version parser and various new access
49 # 0.7.2 - fixed architecture() to use sizeof(pointer) where available
50 # 0.7.1 - added support for Caldera OpenLinux
51 # 0.7.0 - some fixes for WinCE; untabified the source file
52 # 0.6.2 - support for OpenVMS - requires version 1.5.2-V006 or higher and
54 # 0.6.1 - added code to prevent 'uname -p' on platforms which are
56 # 0.6.0 - fixed win32_ver() to hopefully work on Win95,98,NT and Win2k;
57 # did some cleanup of the interfaces - some APIs have changed
58 # 0.5.5 - fixed another type in the MacOS code... should have
59 # used more coffee today ;-)
60 # 0.5.4 - fixed a few typos in the MacOS code
61 # 0.5.3 - added experimental MacOS support; added better popen()
62 # workarounds in _syscmd_ver() -- still not 100% elegant
64 # 0.5.2 - fixed uname() to return '' instead of 'unknown' in all
67 # 0.5.1 - included code for slackware dist; added exception handlers
68 # to cover up situations where platforms don't have os.popen
71 # 0.5.0 - changed the API names referring to system commands to *syscmd*;
73 # API (was system_ver() in previous versions) -- use uname()
76 # 0.4.0 - added win32_ver() and modified the platform() output for WinXX
77 # 0.3.4 - fixed a bug in _follow_symlinks()
78 # 0.3.3 - fixed popen() and "file" command invokation bugs
79 # 0.3.2 - added architecture() API and support for it in platform()
80 # 0.3.1 - fixed syscmd_ver() RE to support Windows NT
81 # 0.3.0 - added system alias support
82 # 0.2.3 - removed 'wince' again... oh well.
83 # 0.2.2 - added 'wince' to syscmd_ver() supported platforms
84 # 0.2.1 - added cache logic and changed the platform string format
85 # 0.2.0 - changed the API to use functions instead of module globals
87 # 0.1.0 - first release
89 # You can always get the latest version of this module at:
96 Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
97 Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info@egenix.com
118 import sys,string,os,re
124 DEV_NULL = os.devnull
126 # os.devnull was added in Python 2.4, so emulate it for earlier
135 # Helper for comparing two version number strings.
137 # http://php.net/manual/en/function.version-compare.php
150 _component_re = re.compile(r'([0-9]+|[._+-])')
152 def _comparable_version(version): argument
154 for v in _component_re.split(version):
155 if v not in '._+-':
168 '(GLIBC_([0-9.]+))'
170 '(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)')
172 def libc_ver(executable=sys.executable,lib='',version='', chunksize=2048): argument
174 """ Tries to determine the libc version that the file executable
177 Returns a tuple of strings (lib,version) which default to the
188 if hasattr(os.path, 'realpath'):
189 # Python 2.2 introduced os.path.realpath(); it is used
192 executable = os.path.realpath(executable)
201 binary = binary[max(pos, len(binary) - 1000):] + chunk
212 version = glibcversion
213 elif V(glibcversion) > V(version):
214 version = glibcversion
218 if soversion and (not version or V(soversion) > V(version)):
219 version = soversion
220 if threads and version[-len(threads):] != threads:
221 version = version + threads
223 return lib,version
225 def _dist_try_harder(distname,version,id): argument
234 if os.path.exists('/var/adm/inst-log/info'):
236 info = open('/var/adm/inst-log/info').readlines()
245 version = string.strip(value)
247 values = string.split(value,'-')
249 return distname,version,id
251 if os.path.exists('/etc/.installed'):
255 pkg = string.split(line,'-')
261 if os.path.isdir('/usr/lib/setup'):
262 # Check for slackware version tag file (thanks to Greg Andruk)
263 verfiles = os.listdir('/usr/lib/setup')
264 for n in range(len(verfiles)-1, -1, -1):
265 if verfiles[n][:14] != 'slack-version-':
270 version = verfiles[-1][14:]
271 return distname,version,id
273 return distname,version,id
275 _release_filename = re.compile(r'(\w+)[-_](release|version)')
280 _release_version = re.compile(r'([^0-9]+)'
286 # and http://linuxmafia.com/faq/Admin/release-files.html
287 # and http://data.linux-ntfs.org/rpm/whichrpm
297 # Default to empty 'version' and 'id' strings. Both defaults are used
300 version = ''
309 # Pre-LSB format: "distro x.x (codename)"
317 version = l[0]
320 return '', version, id
322 def linux_distribution(distname='', version='', id='', argument
327 """ Tries to determine the name of the Linux OS distribution name.
339 distribution read from the OS is returned. Otherwise the short
342 Returns a tuple (distname,version,id) which default to the
347 etc = os.listdir('/etc')
348 except os.error:
350 return distname,version,id
360 return _dist_try_harder(distname,version,id)
371 version = _version
374 return distname, version, id
378 def dist(distname='',version='',id='', argument
382 """ Tries to determine the name of the Linux OS distribution name.
388 Returns a tuple (distname,version,id) which default to the
392 return linux_distribution(distname, version, id,
400 This is mostly needed in case os.popen() is not available, or
415 raise ValueError,'popen()-emulation only supports read mode'
418 os.system(cmd + ' > %s' % tmpfile)
434 remove=os.unlink,error=os.error):
455 # over os.popen over _popen
457 if os.environ.get('OS','') == 'Windows_NT':
467 if hasattr(os,'popen'):
468 popen = os.popen
474 except os.error:
484 def _norm_version(version, build=''): argument
486 """ Normalize the version and build strings and return a single
487 version string using the format major.minor.build (or patchlevel).
489 l = string.split(version,'.')
498 version = string.join(strings[:3],'.')
499 return version
507 # Windows 2000: Microsoft Windows 2000 [Version 5.00.2195]
508 # Windows XP: Microsoft Windows XP [Version 5.1.2600]
509 # Windows Vista: Microsoft Windows [Version 6.0.6002]
511 # Note that the "Version" string gets localized on different
514 def _syscmd_ver(system='', release='', version='', argument
518 """ Tries to figure out the OS version used and returns
519 a tuple (system,release,version).
522 to exists on Windows, DOS and OS/2. XXX Others too ?
529 return system,release,version
537 raise os.error,'command failed'
540 except os.error,why:
549 return system,release,version
555 system,release,version = m.groups()
556 # Strip trailing dots from version and release
557 if release[-1] == '.':
558 release = release[:-1]
559 if version[-1] == '.':
560 version = version[:-1]
561 # Normalize the version and build strings (eliminating additional
563 version = _norm_version(version)
564 return system,release,version
569 # Strictly, 5.2 client is XP 64-bit, but platform.py historically
595 def _get_real_winver(maj, min, build): argument
596 if maj < 6 or (maj == 6 and min < 2):
597 return maj, min, build
623 version = WinDLL('version')
635 return maj, min, build
637 size = version.GetFileVersionInfoSizeW(name, None)
639 return maj, min, build
642 if (not version.GetFileVersionInfoW(name, None, size, ver_block) or
644 return maj, min, build
647 if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())):
648 return maj, min, build
651 min = pvi.contents.dwProductVersionMS & 0xFFFF
654 return maj, min, build
656 def win32_ver(release='', version='', csd='', ptype=''): argument
660 return release, version, csd, ptype
667 maj, min, build = _get_real_winver(*winver[:3])
668 version = '{0}.{1}.{2}'.format(maj, min, build)
670 release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
677 if winver[:2] == (maj, min):
686 release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
701 return release, version, csd, ptype
728 # Check whether the version info module is available
763 if not os.path.exists(fn):
774 machine = os.uname()[4]
784 """ Get MacOS version information and return it as tuple (release,
785 versioninfo, machine) with versioninfo being a tuple (version,
820 """ Version interface for Jython.
837 release = _java_getprop('java.version', release)
841 vm_release = _java_getprop('java.vm.version', vm_release)
844 os_arch = _java_getprop('java.os.arch', os_arch)
845 os_name = _java_getprop('java.os.name', os_name)
846 os_version = _java_getprop('java.os.version', os_version)
853 def system_alias(system,release,version): argument
855 """ Returns (system,release,version) aliased to common
865 return 'MacOS X Server',system+release,version
868 # Sun's OS
871 return system,release,version
872 # Modify release (marketing release = SunOS release - 3)
880 major = major - 3
890 # IRIX reports IRIX64 on platforms with 64-bit support; yet it
891 # is really a version and not a different platform, since 32-bit
894 if version:
895 version = version + ' (64bit)'
897 version = '64bit'
903 return system,release,version
910 compatible format e.g. "system-version-machine".
916 '-')
921 platform = replace(platform,'/','-')
922 platform = replace(platform,'\\','-')
923 platform = replace(platform,':','-')
924 platform = replace(platform,';','-')
925 platform = replace(platform,'"','-')
926 platform = replace(platform,'(','-')
927 platform = replace(platform,')','-')
932 # Fold '--'s and remove trailing '-'
934 cleaned = replace(platform,'--','-')
938 while platform[-1] == '-':
939 platform = platform[:-1]
958 # os.path.abspath is new in Python 1.5.2:
959 if not hasattr(os.path,'abspath'):
963 isabs=os.path.isabs,join=os.path.join,getcwd=os.getcwd,
964 normpath=os.path.normpath):
972 _abspath = os.path.abspath
980 while os.path.islink(filepath):
981 filepath = os.path.normpath(
982 os.path.join(os.path.dirname(filepath),os.readlink(filepath)))
993 f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
994 except (AttributeError,os.error):
1007 The function uses the -b option of the file command to have it
1008 ommit the filename in its output and if possible the -L option
1019 # gcc -o python \
1021 # libpython2.7.a -lsocket -lnsl -ldl -lm
1026 # import sys,string,os,re,subprocess
1041 except (AttributeError,os.error):
1052 # Default values for architecture; non-empty strings override the
1073 (or sizeof(long) on Python version < 1.5.2) is used as
1078 platforms. On some non-Unix platforms where the "file" command
1120 if '32-bit' in fileout:
1125 elif '64-bit' in fileout:
1139 elif 'MS-DOS' in fileout:
1154 of strings (system,node,release,version,machine,processor)
1157 Note that unlike the os.uname function this also returns
1171 # Get some infos from the builtin os.uname API...
1173 system,node,release,version,machine = os.uname()
1177 if no_os_uname or not filter(None, (system, node, release, version, machine)):
1183 version = ''
1191 release,version,csd,ptype = win32_ver()
1192 if release and version:
1200 if "PROCESSOR_ARCHITEW6432" in os.environ:
1201 machine = os.environ.get("PROCESSOR_ARCHITEW6432", '')
1203 machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
1205 processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
1210 system,release,version = _syscmd_ver(system)
1221 if '6.0' == version[:3]:
1229 if not version:
1231 version = '32bit'
1233 version = '16bit'
1239 version = string.join(vminfo,', ')
1240 if not version:
1241 version = vendor
1245 # OpenVMS seems to have release and version mixed up
1247 release = version
1248 version = ''
1262 processor = _syscmd_uname('-p','')
1271 if version == 'unknown':
1272 version = ''
1283 _uname_cache = system,node,release,version,machine,processor
1290 """ Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
1316 def version(): function
1318 """ Returns the system's release version, e.g. '#3 on degas'
1346 ### Various APIs for extracting information from sys.version
1349 r'([\w.+]+)\s*' # "version<space>"
1366 '\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
1378 """ Returns a parsed version of Python's sys.version as tuple
1379 (name, version, branch, revision, buildno, builddate, compiler)
1380 referring to the Python implementation name, version, branch,
1384 Note that unlike the Python sys.version, the returned value
1385 for the Python version will always include the patchlevel (it
1391 sys_version may be given to parse an alternative version
1392 string, e.g. if the version was read from a different Python
1396 # Get the Python version
1398 sys_version = sys.version
1416 'failed to parse IronPython sys.version: %s' %
1419 version, alt_version, compiler = match.groups()
1429 'failed to parse Jython sys.version: %s' %
1431 version, buildno, builddate, buildtime, _ = match.groups()
1441 raise ValueError("failed to parse PyPy sys.version: %s" %
1443 version, buildno, builddate, buildtime = match.groups()
1451 'failed to parse CPython sys.version: %s' %
1453 version, buildno, builddate, buildtime, compiler = \
1468 # Add the patchlevel version if missing
1469 l = string.split(version, '.')
1472 version = string.join(l, '.')
1475 result = (name, version, branch, revision, buildno, builddate, compiler)
1494 """ Returns the Python version as string 'major.minor.patchlevel'
1496 Note that unlike the Python sys.version, the returned value
1504 """ Returns the Python version as tuple (major, minor, patchlevel)
1507 Note that unlike the Python sys.version, the returned value
1556 ### The Opus Magnum of platform strings :-)
1585 system,node,release,version,machine,processor = uname()
1589 system,release,version = system_alias(system,release,version)
1593 rel,vers,csd,ptype = win32_ver(version)
1597 platform = _platform(system,release,version,csd)
1616 platform = _platform(system,release,version)
1618 platform = _platform(system,release,version,
1644 terse = ('terse' in sys.argv or '--terse' in sys.argv)
1645 aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv)