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