Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: platform.py
#! /usr/libexec/platform-python
[0] Fix | Delete
[1] Fix | Delete
""" This module tries to retrieve as much platform-identifying data as
[2] Fix | Delete
possible. It makes this information available via function APIs.
[3] Fix | Delete
[4] Fix | Delete
If called from the command line, it prints the platform
[5] Fix | Delete
information concatenated as single string to stdout. The output
[6] Fix | Delete
format is useable as part of a filename.
[7] Fix | Delete
[8] Fix | Delete
"""
[9] Fix | Delete
# This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
[10] Fix | Delete
# If you find problems, please submit bug reports/patches via the
[11] Fix | Delete
# Python bug tracker (http://bugs.python.org) and assign them to "lemburg".
[12] Fix | Delete
#
[13] Fix | Delete
# Still needed:
[14] Fix | Delete
# * support for MS-DOS (PythonDX ?)
[15] Fix | Delete
# * support for Amiga and other still unsupported platforms running Python
[16] Fix | Delete
# * support for additional Linux distributions
[17] Fix | Delete
#
[18] Fix | Delete
# Many thanks to all those who helped adding platform-specific
[19] Fix | Delete
# checks (in no particular order):
[20] Fix | Delete
#
[21] Fix | Delete
# Charles G Waldman, David Arnold, Gordon McMillan, Ben Darnell,
[22] Fix | Delete
# Jeff Bauer, Cliff Crawford, Ivan Van Laningham, Josef
[23] Fix | Delete
# Betancourt, Randall Hopper, Karl Putland, John Farrell, Greg
[24] Fix | Delete
# Andruk, Just van Rossum, Thomas Heller, Mark R. Levinson, Mark
[25] Fix | Delete
# Hammond, Bill Tutt, Hans Nowak, Uwe Zessin (OpenVMS support),
[26] Fix | Delete
# Colin Kong, Trent Mick, Guido van Rossum, Anthony Baxter, Steve
[27] Fix | Delete
# Dower
[28] Fix | Delete
#
[29] Fix | Delete
# History:
[30] Fix | Delete
#
[31] Fix | Delete
# <see CVS and SVN checkin messages for history>
[32] Fix | Delete
#
[33] Fix | Delete
# 1.0.8 - changed Windows support to read version from kernel32.dll
[34] Fix | Delete
# 1.0.7 - added DEV_NULL
[35] Fix | Delete
# 1.0.6 - added linux_distribution()
[36] Fix | Delete
# 1.0.5 - fixed Java support to allow running the module on Jython
[37] Fix | Delete
# 1.0.4 - added IronPython support
[38] Fix | Delete
# 1.0.3 - added normalization of Windows system name
[39] Fix | Delete
# 1.0.2 - added more Windows support
[40] Fix | Delete
# 1.0.1 - reformatted to make doc.py happy
[41] Fix | Delete
# 1.0.0 - reformatted a bit and checked into Python CVS
[42] Fix | Delete
# 0.8.0 - added sys.version parser and various new access
[43] Fix | Delete
# APIs (python_version(), python_compiler(), etc.)
[44] Fix | Delete
# 0.7.2 - fixed architecture() to use sizeof(pointer) where available
[45] Fix | Delete
# 0.7.1 - added support for Caldera OpenLinux
[46] Fix | Delete
# 0.7.0 - some fixes for WinCE; untabified the source file
[47] Fix | Delete
# 0.6.2 - support for OpenVMS - requires version 1.5.2-V006 or higher and
[48] Fix | Delete
# vms_lib.getsyi() configured
[49] Fix | Delete
# 0.6.1 - added code to prevent 'uname -p' on platforms which are
[50] Fix | Delete
# known not to support it
[51] Fix | Delete
# 0.6.0 - fixed win32_ver() to hopefully work on Win95,98,NT and Win2k;
[52] Fix | Delete
# did some cleanup of the interfaces - some APIs have changed
[53] Fix | Delete
# 0.5.5 - fixed another type in the MacOS code... should have
[54] Fix | Delete
# used more coffee today ;-)
[55] Fix | Delete
# 0.5.4 - fixed a few typos in the MacOS code
[56] Fix | Delete
# 0.5.3 - added experimental MacOS support; added better popen()
[57] Fix | Delete
# workarounds in _syscmd_ver() -- still not 100% elegant
[58] Fix | Delete
# though
[59] Fix | Delete
# 0.5.2 - fixed uname() to return '' instead of 'unknown' in all
[60] Fix | Delete
# return values (the system uname command tends to return
[61] Fix | Delete
# 'unknown' instead of just leaving the field empty)
[62] Fix | Delete
# 0.5.1 - included code for slackware dist; added exception handlers
[63] Fix | Delete
# to cover up situations where platforms don't have os.popen
[64] Fix | Delete
# (e.g. Mac) or fail on socket.gethostname(); fixed libc
[65] Fix | Delete
# detection RE
[66] Fix | Delete
# 0.5.0 - changed the API names referring to system commands to *syscmd*;
[67] Fix | Delete
# added java_ver(); made syscmd_ver() a private
[68] Fix | Delete
# API (was system_ver() in previous versions) -- use uname()
[69] Fix | Delete
# instead; extended the win32_ver() to also return processor
[70] Fix | Delete
# type information
[71] Fix | Delete
# 0.4.0 - added win32_ver() and modified the platform() output for WinXX
[72] Fix | Delete
# 0.3.4 - fixed a bug in _follow_symlinks()
[73] Fix | Delete
# 0.3.3 - fixed popen() and "file" command invokation bugs
[74] Fix | Delete
# 0.3.2 - added architecture() API and support for it in platform()
[75] Fix | Delete
# 0.3.1 - fixed syscmd_ver() RE to support Windows NT
[76] Fix | Delete
# 0.3.0 - added system alias support
[77] Fix | Delete
# 0.2.3 - removed 'wince' again... oh well.
[78] Fix | Delete
# 0.2.2 - added 'wince' to syscmd_ver() supported platforms
[79] Fix | Delete
# 0.2.1 - added cache logic and changed the platform string format
[80] Fix | Delete
# 0.2.0 - changed the API to use functions instead of module globals
[81] Fix | Delete
# since some action take too long to be run on module import
[82] Fix | Delete
# 0.1.0 - first release
[83] Fix | Delete
#
[84] Fix | Delete
# You can always get the latest version of this module at:
[85] Fix | Delete
#
[86] Fix | Delete
# http://www.egenix.com/files/python/platform.py
[87] Fix | Delete
#
[88] Fix | Delete
# If that URL should fail, try contacting the author.
[89] Fix | Delete
[90] Fix | Delete
__copyright__ = """
[91] Fix | Delete
Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
[92] Fix | Delete
Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info@egenix.com
[93] Fix | Delete
[94] Fix | Delete
Permission to use, copy, modify, and distribute this software and its
[95] Fix | Delete
documentation for any purpose and without fee or royalty is hereby granted,
[96] Fix | Delete
provided that the above copyright notice appear in all copies and that
[97] Fix | Delete
both that copyright notice and this permission notice appear in
[98] Fix | Delete
supporting documentation or portions thereof, including modifications,
[99] Fix | Delete
that you make.
[100] Fix | Delete
[101] Fix | Delete
EGENIX.COM SOFTWARE GMBH DISCLAIMS ALL WARRANTIES WITH REGARD TO
[102] Fix | Delete
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
[103] Fix | Delete
FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
[104] Fix | Delete
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
[105] Fix | Delete
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
[106] Fix | Delete
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
[107] Fix | Delete
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
[108] Fix | Delete
[109] Fix | Delete
"""
[110] Fix | Delete
[111] Fix | Delete
__version__ = '1.0.8'
[112] Fix | Delete
[113] Fix | Delete
import collections
[114] Fix | Delete
import sys, os, re, subprocess
[115] Fix | Delete
[116] Fix | Delete
import warnings
[117] Fix | Delete
[118] Fix | Delete
### Globals & Constants
[119] Fix | Delete
[120] Fix | Delete
# Determine the platform's /dev/null device
[121] Fix | Delete
try:
[122] Fix | Delete
DEV_NULL = os.devnull
[123] Fix | Delete
except AttributeError:
[124] Fix | Delete
# os.devnull was added in Python 2.4, so emulate it for earlier
[125] Fix | Delete
# Python versions
[126] Fix | Delete
if sys.platform in ('dos', 'win32', 'win16'):
[127] Fix | Delete
# Use the old CP/M NUL as device name
[128] Fix | Delete
DEV_NULL = 'NUL'
[129] Fix | Delete
else:
[130] Fix | Delete
# Standard Unix uses /dev/null
[131] Fix | Delete
DEV_NULL = '/dev/null'
[132] Fix | Delete
[133] Fix | Delete
# Directory to search for configuration information on Unix.
[134] Fix | Delete
# Constant used by test_platform to test linux_distribution().
[135] Fix | Delete
_UNIXCONFDIR = '/etc'
[136] Fix | Delete
[137] Fix | Delete
# Helper for comparing two version number strings.
[138] Fix | Delete
# Based on the description of the PHP's version_compare():
[139] Fix | Delete
# http://php.net/manual/en/function.version-compare.php
[140] Fix | Delete
[141] Fix | Delete
_ver_stages = {
[142] Fix | Delete
# any string not found in this dict, will get 0 assigned
[143] Fix | Delete
'dev': 10,
[144] Fix | Delete
'alpha': 20, 'a': 20,
[145] Fix | Delete
'beta': 30, 'b': 30,
[146] Fix | Delete
'c': 40,
[147] Fix | Delete
'RC': 50, 'rc': 50,
[148] Fix | Delete
# number, will get 100 assigned
[149] Fix | Delete
'pl': 200, 'p': 200,
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
_component_re = re.compile(r'([0-9]+|[._+-])')
[153] Fix | Delete
[154] Fix | Delete
def _comparable_version(version):
[155] Fix | Delete
result = []
[156] Fix | Delete
for v in _component_re.split(version):
[157] Fix | Delete
if v not in '._+-':
[158] Fix | Delete
try:
[159] Fix | Delete
v = int(v, 10)
[160] Fix | Delete
t = 100
[161] Fix | Delete
except ValueError:
[162] Fix | Delete
t = _ver_stages.get(v, 0)
[163] Fix | Delete
result.extend((t, v))
[164] Fix | Delete
return result
[165] Fix | Delete
[166] Fix | Delete
### Platform specific APIs
[167] Fix | Delete
[168] Fix | Delete
_libc_search = re.compile(b'(__libc_init)'
[169] Fix | Delete
b'|'
[170] Fix | Delete
b'(GLIBC_([0-9.]+))'
[171] Fix | Delete
b'|'
[172] Fix | Delete
br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
[173] Fix | Delete
[174] Fix | Delete
def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384):
[175] Fix | Delete
[176] Fix | Delete
""" Tries to determine the libc version that the file executable
[177] Fix | Delete
(which defaults to the Python interpreter) is linked against.
[178] Fix | Delete
[179] Fix | Delete
Returns a tuple of strings (lib,version) which default to the
[180] Fix | Delete
given parameters in case the lookup fails.
[181] Fix | Delete
[182] Fix | Delete
Note that the function has intimate knowledge of how different
[183] Fix | Delete
libc versions add symbols to the executable and thus is probably
[184] Fix | Delete
only useable for executables compiled using gcc.
[185] Fix | Delete
[186] Fix | Delete
The file is read and scanned in chunks of chunksize bytes.
[187] Fix | Delete
[188] Fix | Delete
"""
[189] Fix | Delete
V = _comparable_version
[190] Fix | Delete
if hasattr(os.path, 'realpath'):
[191] Fix | Delete
# Python 2.2 introduced os.path.realpath(); it is used
[192] Fix | Delete
# here to work around problems with Cygwin not being
[193] Fix | Delete
# able to open symlinks for reading
[194] Fix | Delete
executable = os.path.realpath(executable)
[195] Fix | Delete
with open(executable, 'rb') as f:
[196] Fix | Delete
binary = f.read(chunksize)
[197] Fix | Delete
pos = 0
[198] Fix | Delete
while pos < len(binary):
[199] Fix | Delete
if b'libc' in binary or b'GLIBC' in binary:
[200] Fix | Delete
m = _libc_search.search(binary, pos)
[201] Fix | Delete
else:
[202] Fix | Delete
m = None
[203] Fix | Delete
if not m or m.end() == len(binary):
[204] Fix | Delete
chunk = f.read(chunksize)
[205] Fix | Delete
if chunk:
[206] Fix | Delete
binary = binary[max(pos, len(binary) - 1000):] + chunk
[207] Fix | Delete
pos = 0
[208] Fix | Delete
continue
[209] Fix | Delete
if not m:
[210] Fix | Delete
break
[211] Fix | Delete
libcinit, glibc, glibcversion, so, threads, soversion = [
[212] Fix | Delete
s.decode('latin1') if s is not None else s
[213] Fix | Delete
for s in m.groups()]
[214] Fix | Delete
if libcinit and not lib:
[215] Fix | Delete
lib = 'libc'
[216] Fix | Delete
elif glibc:
[217] Fix | Delete
if lib != 'glibc':
[218] Fix | Delete
lib = 'glibc'
[219] Fix | Delete
version = glibcversion
[220] Fix | Delete
elif V(glibcversion) > V(version):
[221] Fix | Delete
version = glibcversion
[222] Fix | Delete
elif so:
[223] Fix | Delete
if lib != 'glibc':
[224] Fix | Delete
lib = 'libc'
[225] Fix | Delete
if soversion and (not version or V(soversion) > V(version)):
[226] Fix | Delete
version = soversion
[227] Fix | Delete
if threads and version[-len(threads):] != threads:
[228] Fix | Delete
version = version + threads
[229] Fix | Delete
pos = m.end()
[230] Fix | Delete
return lib, version
[231] Fix | Delete
[232] Fix | Delete
def _dist_try_harder(distname, version, id):
[233] Fix | Delete
[234] Fix | Delete
""" Tries some special tricks to get the distribution
[235] Fix | Delete
information in case the default method fails.
[236] Fix | Delete
[237] Fix | Delete
Currently supports older SuSE Linux, Caldera OpenLinux and
[238] Fix | Delete
Slackware Linux distributions.
[239] Fix | Delete
[240] Fix | Delete
"""
[241] Fix | Delete
if os.path.exists('/var/adm/inst-log/info'):
[242] Fix | Delete
# SuSE Linux stores distribution information in that file
[243] Fix | Delete
distname = 'SuSE'
[244] Fix | Delete
with open('/var/adm/inst-log/info') as f:
[245] Fix | Delete
for line in f:
[246] Fix | Delete
tv = line.split()
[247] Fix | Delete
if len(tv) == 2:
[248] Fix | Delete
tag, value = tv
[249] Fix | Delete
else:
[250] Fix | Delete
continue
[251] Fix | Delete
if tag == 'MIN_DIST_VERSION':
[252] Fix | Delete
version = value.strip()
[253] Fix | Delete
elif tag == 'DIST_IDENT':
[254] Fix | Delete
values = value.split('-')
[255] Fix | Delete
id = values[2]
[256] Fix | Delete
return distname, version, id
[257] Fix | Delete
[258] Fix | Delete
if os.path.exists('/etc/.installed'):
[259] Fix | Delete
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
[260] Fix | Delete
with open('/etc/.installed') as f:
[261] Fix | Delete
for line in f:
[262] Fix | Delete
pkg = line.split('-')
[263] Fix | Delete
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
[264] Fix | Delete
# XXX does Caldera support non Intel platforms ? If yes,
[265] Fix | Delete
# where can we find the needed id ?
[266] Fix | Delete
return 'OpenLinux', pkg[1], id
[267] Fix | Delete
[268] Fix | Delete
if os.path.isdir('/usr/lib/setup'):
[269] Fix | Delete
# Check for slackware version tag file (thanks to Greg Andruk)
[270] Fix | Delete
verfiles = os.listdir('/usr/lib/setup')
[271] Fix | Delete
for n in range(len(verfiles)-1, -1, -1):
[272] Fix | Delete
if verfiles[n][:14] != 'slack-version-':
[273] Fix | Delete
del verfiles[n]
[274] Fix | Delete
if verfiles:
[275] Fix | Delete
verfiles.sort()
[276] Fix | Delete
distname = 'slackware'
[277] Fix | Delete
version = verfiles[-1][14:]
[278] Fix | Delete
return distname, version, id
[279] Fix | Delete
[280] Fix | Delete
return distname, version, id
[281] Fix | Delete
[282] Fix | Delete
_release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
[283] Fix | Delete
_lsb_release_version = re.compile(r'(.+)'
[284] Fix | Delete
r' release '
[285] Fix | Delete
r'([\d.]+)'
[286] Fix | Delete
r'[^(]*(?:\((.+)\))?', re.ASCII)
[287] Fix | Delete
_release_version = re.compile(r'([^0-9]+)'
[288] Fix | Delete
r'(?: release )?'
[289] Fix | Delete
r'([\d.]+)'
[290] Fix | Delete
r'[^(]*(?:\((.+)\))?', re.ASCII)
[291] Fix | Delete
[292] Fix | Delete
# See also http://www.novell.com/coolsolutions/feature/11251.html
[293] Fix | Delete
# and http://linuxmafia.com/faq/Admin/release-files.html
[294] Fix | Delete
# and http://data.linux-ntfs.org/rpm/whichrpm
[295] Fix | Delete
# and http://www.die.net/doc/linux/man/man1/lsb_release.1.html
[296] Fix | Delete
[297] Fix | Delete
_supported_dists = (
[298] Fix | Delete
'SuSE', 'debian', 'fedora', 'redhat', 'centos', 'almalinux',
[299] Fix | Delete
'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo',
[300] Fix | Delete
'UnitedLinux', 'turbolinux', 'arch', 'mageia')
[301] Fix | Delete
[302] Fix | Delete
def _parse_release_file(firstline):
[303] Fix | Delete
[304] Fix | Delete
# Default to empty 'version' and 'id' strings. Both defaults are used
[305] Fix | Delete
# when 'firstline' is empty. 'id' defaults to empty when an id can not
[306] Fix | Delete
# be deduced.
[307] Fix | Delete
version = ''
[308] Fix | Delete
id = ''
[309] Fix | Delete
[310] Fix | Delete
# Parse the first line
[311] Fix | Delete
m = _lsb_release_version.match(firstline)
[312] Fix | Delete
if m is not None:
[313] Fix | Delete
# LSB format: "distro release x.x (codename)"
[314] Fix | Delete
return tuple(m.groups())
[315] Fix | Delete
[316] Fix | Delete
# Pre-LSB format: "distro x.x (codename)"
[317] Fix | Delete
m = _release_version.match(firstline)
[318] Fix | Delete
if m is not None:
[319] Fix | Delete
return tuple(m.groups())
[320] Fix | Delete
[321] Fix | Delete
# Unknown format... take the first two words
[322] Fix | Delete
l = firstline.strip().split()
[323] Fix | Delete
if l:
[324] Fix | Delete
version = l[0]
[325] Fix | Delete
if len(l) > 1:
[326] Fix | Delete
id = l[1]
[327] Fix | Delete
return '', version, id
[328] Fix | Delete
[329] Fix | Delete
def linux_distribution(distname='', version='', id='',
[330] Fix | Delete
[331] Fix | Delete
supported_dists=_supported_dists,
[332] Fix | Delete
full_distribution_name=1):
[333] Fix | Delete
import warnings
[334] Fix | Delete
warnings.warn("dist() and linux_distribution() functions are deprecated "
[335] Fix | Delete
"in Python 3.5", PendingDeprecationWarning, stacklevel=2)
[336] Fix | Delete
return _linux_distribution(distname, version, id, supported_dists,
[337] Fix | Delete
full_distribution_name)
[338] Fix | Delete
[339] Fix | Delete
def _linux_distribution(distname, version, id, supported_dists,
[340] Fix | Delete
full_distribution_name):
[341] Fix | Delete
[342] Fix | Delete
""" Tries to determine the name of the Linux OS distribution name.
[343] Fix | Delete
[344] Fix | Delete
The function first looks for a distribution release file in
[345] Fix | Delete
/etc and then reverts to _dist_try_harder() in case no
[346] Fix | Delete
suitable files are found.
[347] Fix | Delete
[348] Fix | Delete
supported_dists may be given to define the set of Linux
[349] Fix | Delete
distributions to look for. It defaults to a list of currently
[350] Fix | Delete
supported Linux distributions identified by their release file
[351] Fix | Delete
name.
[352] Fix | Delete
[353] Fix | Delete
If full_distribution_name is true (default), the full
[354] Fix | Delete
distribution read from the OS is returned. Otherwise the short
[355] Fix | Delete
name taken from supported_dists is used.
[356] Fix | Delete
[357] Fix | Delete
Returns a tuple (distname, version, id) which default to the
[358] Fix | Delete
args given as parameters.
[359] Fix | Delete
[360] Fix | Delete
"""
[361] Fix | Delete
try:
[362] Fix | Delete
etc = os.listdir(_UNIXCONFDIR)
[363] Fix | Delete
except OSError:
[364] Fix | Delete
# Probably not a Unix system
[365] Fix | Delete
return distname, version, id
[366] Fix | Delete
etc.sort()
[367] Fix | Delete
for file in etc:
[368] Fix | Delete
m = _release_filename.match(file)
[369] Fix | Delete
if m is not None:
[370] Fix | Delete
_distname, dummy = m.groups()
[371] Fix | Delete
if _distname in supported_dists:
[372] Fix | Delete
distname = _distname
[373] Fix | Delete
break
[374] Fix | Delete
else:
[375] Fix | Delete
return _dist_try_harder(distname, version, id)
[376] Fix | Delete
[377] Fix | Delete
# Read the first line
[378] Fix | Delete
with open(os.path.join(_UNIXCONFDIR, file), 'r',
[379] Fix | Delete
encoding='utf-8', errors='surrogateescape') as f:
[380] Fix | Delete
firstline = f.readline()
[381] Fix | Delete
_distname, _version, _id = _parse_release_file(firstline)
[382] Fix | Delete
[383] Fix | Delete
if _distname and full_distribution_name:
[384] Fix | Delete
distname = _distname
[385] Fix | Delete
if _version:
[386] Fix | Delete
version = _version
[387] Fix | Delete
if _id:
[388] Fix | Delete
id = _id
[389] Fix | Delete
return distname, version, id
[390] Fix | Delete
[391] Fix | Delete
# To maintain backwards compatibility:
[392] Fix | Delete
[393] Fix | Delete
def dist(distname='', version='', id='',
[394] Fix | Delete
[395] Fix | Delete
supported_dists=_supported_dists):
[396] Fix | Delete
[397] Fix | Delete
""" Tries to determine the name of the Linux OS distribution name.
[398] Fix | Delete
[399] Fix | Delete
The function first looks for a distribution release file in
[400] Fix | Delete
/etc and then reverts to _dist_try_harder() in case no
[401] Fix | Delete
suitable files are found.
[402] Fix | Delete
[403] Fix | Delete
Returns a tuple (distname, version, id) which default to the
[404] Fix | Delete
args given as parameters.
[405] Fix | Delete
[406] Fix | Delete
"""
[407] Fix | Delete
import warnings
[408] Fix | Delete
warnings.warn("dist() and linux_distribution() functions are deprecated "
[409] Fix | Delete
"in Python 3.5", PendingDeprecationWarning, stacklevel=2)
[410] Fix | Delete
return _linux_distribution(distname, version, id,
[411] Fix | Delete
supported_dists=supported_dists,
[412] Fix | Delete
full_distribution_name=0)
[413] Fix | Delete
[414] Fix | Delete
def popen(cmd, mode='r', bufsize=-1):
[415] Fix | Delete
[416] Fix | Delete
""" Portable popen() interface.
[417] Fix | Delete
"""
[418] Fix | Delete
import warnings
[419] Fix | Delete
warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2)
[420] Fix | Delete
return os.popen(cmd, mode, bufsize)
[421] Fix | Delete
[422] Fix | Delete
[423] Fix | Delete
def _norm_version(version, build=''):
[424] Fix | Delete
[425] Fix | Delete
""" Normalize the version and build strings and return a single
[426] Fix | Delete
version string using the format major.minor.build (or patchlevel).
[427] Fix | Delete
"""
[428] Fix | Delete
l = version.split('.')
[429] Fix | Delete
if build:
[430] Fix | Delete
l.append(build)
[431] Fix | Delete
try:
[432] Fix | Delete
ints = map(int, l)
[433] Fix | Delete
except ValueError:
[434] Fix | Delete
strings = l
[435] Fix | Delete
else:
[436] Fix | Delete
strings = list(map(str, ints))
[437] Fix | Delete
version = '.'.join(strings[:3])
[438] Fix | Delete
return version
[439] Fix | Delete
[440] Fix | Delete
_ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
[441] Fix | Delete
r'.*'
[442] Fix | Delete
r'\[.* ([\d.]+)\])')
[443] Fix | Delete
[444] Fix | Delete
# Examples of VER command output:
[445] Fix | Delete
#
[446] Fix | Delete
# Windows 2000: Microsoft Windows 2000 [Version 5.00.2195]
[447] Fix | Delete
# Windows XP: Microsoft Windows XP [Version 5.1.2600]
[448] Fix | Delete
# Windows Vista: Microsoft Windows [Version 6.0.6002]
[449] Fix | Delete
#
[450] Fix | Delete
# Note that the "Version" string gets localized on different
[451] Fix | Delete
# Windows versions.
[452] Fix | Delete
[453] Fix | Delete
def _syscmd_ver(system='', release='', version='',
[454] Fix | Delete
[455] Fix | Delete
supported_platforms=('win32', 'win16', 'dos')):
[456] Fix | Delete
[457] Fix | Delete
""" Tries to figure out the OS version used and returns
[458] Fix | Delete
a tuple (system, release, version).
[459] Fix | Delete
[460] Fix | Delete
It uses the "ver" shell command for this which is known
[461] Fix | Delete
to exists on Windows, DOS. XXX Others too ?
[462] Fix | Delete
[463] Fix | Delete
In case this fails, the given parameters are used as
[464] Fix | Delete
defaults.
[465] Fix | Delete
[466] Fix | Delete
"""
[467] Fix | Delete
if sys.platform not in supported_platforms:
[468] Fix | Delete
return system, release, version
[469] Fix | Delete
[470] Fix | Delete
# Try some common cmd strings
[471] Fix | Delete
for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
[472] Fix | Delete
try:
[473] Fix | Delete
pipe = os.popen(cmd)
[474] Fix | Delete
info = pipe.read()
[475] Fix | Delete
if pipe.close():
[476] Fix | Delete
raise OSError('command failed')
[477] Fix | Delete
# XXX How can I suppress shell errors from being written
[478] Fix | Delete
# to stderr ?
[479] Fix | Delete
except OSError as why:
[480] Fix | Delete
#print 'Command %s failed: %s' % (cmd, why)
[481] Fix | Delete
continue
[482] Fix | Delete
else:
[483] Fix | Delete
break
[484] Fix | Delete
else:
[485] Fix | Delete
return system, release, version
[486] Fix | Delete
[487] Fix | Delete
# Parse the output
[488] Fix | Delete
info = info.strip()
[489] Fix | Delete
m = _ver_output.match(info)
[490] Fix | Delete
if m is not None:
[491] Fix | Delete
system, release, version = m.groups()
[492] Fix | Delete
# Strip trailing dots from version and release
[493] Fix | Delete
if release[-1] == '.':
[494] Fix | Delete
release = release[:-1]
[495] Fix | Delete
if version[-1] == '.':
[496] Fix | Delete
version = version[:-1]
[497] Fix | Delete
# Normalize the version and build strings (eliminating additional
[498] Fix | Delete
# zeros)
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function