Issue #17429: some PEP 8 compliance fixes for the platform modules, add whitespaces

This commit is contained in:
Victor Stinner 2013-12-09 00:14:52 +01:00
parent 0aba1a2663
commit ced3936894
1 changed files with 113 additions and 111 deletions

View File

@ -122,7 +122,7 @@ try:
except AttributeError: except AttributeError:
# os.devnull was added in Python 2.4, so emulate it for earlier # os.devnull was added in Python 2.4, so emulate it for earlier
# Python versions # Python versions
if sys.platform in ('dos','win32','win16'): if sys.platform in ('dos', 'win32', 'win16'):
# Use the old CP/M NUL as device name # Use the old CP/M NUL as device name
DEV_NULL = 'NUL' DEV_NULL = 'NUL'
else: else:
@ -141,7 +141,7 @@ _libc_search = re.compile(b'(__libc_init)'
b'|' b'|'
br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII) br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
def libc_ver(executable=sys.executable,lib='',version='', def libc_ver(executable=sys.executable, lib='', version='',
chunksize=16384): chunksize=16384):
@ -163,12 +163,12 @@ def libc_ver(executable=sys.executable,lib='',version='',
# here to work around problems with Cygwin not being # here to work around problems with Cygwin not being
# able to open symlinks for reading # able to open symlinks for reading
executable = os.path.realpath(executable) executable = os.path.realpath(executable)
f = open(executable,'rb') f = open(executable, 'rb')
binary = f.read(chunksize) binary = f.read(chunksize)
pos = 0 pos = 0
while 1: while 1:
if b'libc' in binary or b'GLIBC' in binary: if b'libc' in binary or b'GLIBC' in binary:
m = _libc_search.search(binary,pos) m = _libc_search.search(binary, pos)
else: else:
m = None m = None
if not m: if not m:
@ -177,7 +177,7 @@ def libc_ver(executable=sys.executable,lib='',version='',
break break
pos = 0 pos = 0
continue continue
libcinit,glibc,glibcversion,so,threads,soversion = [ libcinit, glibc, glibcversion, so, threads, soversion = [
s.decode('latin1') if s is not None else s s.decode('latin1') if s is not None else s
for s in m.groups()] for s in m.groups()]
if libcinit and not lib: if libcinit and not lib:
@ -197,9 +197,9 @@ def libc_ver(executable=sys.executable,lib='',version='',
version = version + threads version = version + threads
pos = m.end() pos = m.end()
f.close() f.close()
return lib,version return lib, version
def _dist_try_harder(distname,version,id): def _dist_try_harder(distname, version, id):
""" Tries some special tricks to get the distribution """ Tries some special tricks to get the distribution
information in case the default method fails. information in case the default method fails.
@ -214,7 +214,7 @@ def _dist_try_harder(distname,version,id):
for line in open('/var/adm/inst-log/info'): for line in open('/var/adm/inst-log/info'):
tv = line.split() tv = line.split()
if len(tv) == 2: if len(tv) == 2:
tag,value = tv tag, value = tv
else: else:
continue continue
if tag == 'MIN_DIST_VERSION': if tag == 'MIN_DIST_VERSION':
@ -222,7 +222,7 @@ def _dist_try_harder(distname,version,id):
elif tag == 'DIST_IDENT': elif tag == 'DIST_IDENT':
values = value.split('-') values = value.split('-')
id = values[2] id = values[2]
return distname,version,id return distname, version, id
if os.path.exists('/etc/.installed'): if os.path.exists('/etc/.installed'):
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong) # Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
@ -231,7 +231,7 @@ def _dist_try_harder(distname,version,id):
if len(pkg) >= 2 and pkg[0] == 'OpenLinux': if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
# XXX does Caldera support non Intel platforms ? If yes, # XXX does Caldera support non Intel platforms ? If yes,
# where can we find the needed id ? # where can we find the needed id ?
return 'OpenLinux',pkg[1],id return 'OpenLinux', pkg[1], id
if os.path.isdir('/usr/lib/setup'): if os.path.isdir('/usr/lib/setup'):
# Check for slackware version tag file (thanks to Greg Andruk) # Check for slackware version tag file (thanks to Greg Andruk)
@ -243,9 +243,9 @@ def _dist_try_harder(distname,version,id):
verfiles.sort() verfiles.sort()
distname = 'slackware' distname = 'slackware'
version = verfiles[-1][14:] version = verfiles[-1][14:]
return distname,version,id return distname, version, id
return distname,version,id return distname, version, id
_release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII) _release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
_lsb_release_version = re.compile(r'(.+)' _lsb_release_version = re.compile(r'(.+)'
@ -314,7 +314,7 @@ def linux_distribution(distname='', version='', id='',
distribution read from the OS is returned. Otherwise the short distribution read from the OS is returned. Otherwise the short
name taken from supported_dists is used. name taken from supported_dists is used.
Returns a tuple (distname,version,id) which default to the Returns a tuple (distname, version, id) which default to the
args given as parameters. args given as parameters.
""" """
@ -322,17 +322,17 @@ def linux_distribution(distname='', version='', id='',
etc = os.listdir(_UNIXCONFDIR) etc = os.listdir(_UNIXCONFDIR)
except OSError: except OSError:
# Probably not a Unix system # Probably not a Unix system
return distname,version,id return distname, version, id
etc.sort() etc.sort()
for file in etc: for file in etc:
m = _release_filename.match(file) m = _release_filename.match(file)
if m is not None: if m is not None:
_distname,dummy = m.groups() _distname, dummy = m.groups()
if _distname in supported_dists: if _distname in supported_dists:
distname = _distname distname = _distname
break break
else: else:
return _dist_try_harder(distname,version,id) return _dist_try_harder(distname, version, id)
# Read the first line # Read the first line
with open(os.path.join(_UNIXCONFDIR, file), 'r', with open(os.path.join(_UNIXCONFDIR, file), 'r',
@ -350,7 +350,7 @@ def linux_distribution(distname='', version='', id='',
# To maintain backwards compatibility: # To maintain backwards compatibility:
def dist(distname='',version='',id='', def dist(distname='', version='', id='',
supported_dists=_supported_dists): supported_dists=_supported_dists):
@ -360,7 +360,7 @@ def dist(distname='',version='',id='',
/etc and then reverts to _dist_try_harder() in case no /etc and then reverts to _dist_try_harder() in case no
suitable files are found. suitable files are found.
Returns a tuple (distname,version,id) which default to the Returns a tuple (distname, version, id) which default to the
args given as parameters. args given as parameters.
""" """
@ -385,11 +385,11 @@ def _norm_version(version, build=''):
if build: if build:
l.append(build) l.append(build)
try: try:
ints = map(int,l) ints = map(int, l)
except ValueError: except ValueError:
strings = l strings = l
else: else:
strings = list(map(str,ints)) strings = list(map(str, ints))
version = '.'.join(strings[:3]) version = '.'.join(strings[:3])
return version return version
@ -408,10 +408,10 @@ _ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
def _syscmd_ver(system='', release='', version='', def _syscmd_ver(system='', release='', version='',
supported_platforms=('win32','win16','dos')): supported_platforms=('win32', 'win16', 'dos')):
""" Tries to figure out the OS version used and returns """ Tries to figure out the OS version used and returns
a tuple (system,release,version). a tuple (system, release, version).
It uses the "ver" shell command for this which is known It uses the "ver" shell command for this which is known
to exists on Windows, DOS. XXX Others too ? to exists on Windows, DOS. XXX Others too ?
@ -421,10 +421,10 @@ def _syscmd_ver(system='', release='', version='',
""" """
if sys.platform not in supported_platforms: if sys.platform not in supported_platforms:
return system,release,version return system, release, version
# Try some common cmd strings # Try some common cmd strings
for cmd in ('ver','command /c ver','cmd /c ver'): for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
try: try:
pipe = popen(cmd) pipe = popen(cmd)
info = pipe.read() info = pipe.read()
@ -433,18 +433,18 @@ def _syscmd_ver(system='', release='', version='',
# XXX How can I suppress shell errors from being written # XXX How can I suppress shell errors from being written
# to stderr ? # to stderr ?
except OSError as why: except OSError as why:
#print 'Command %s failed: %s' % (cmd,why) #print 'Command %s failed: %s' % (cmd, why)
continue continue
else: else:
break break
else: else:
return system,release,version return system, release, version
# Parse the output # Parse the output
info = info.strip() info = info.strip()
m = _ver_output.match(info) m = _ver_output.match(info)
if m is not None: if m is not None:
system,release,version = m.groups() system, release, version = m.groups()
# Strip trailing dots from version and release # Strip trailing dots from version and release
if release[-1] == '.': if release[-1] == '.':
release = release[:-1] release = release[:-1]
@ -453,9 +453,9 @@ def _syscmd_ver(system='', release='', version='',
# Normalize the version and build strings (eliminating additional # Normalize the version and build strings (eliminating additional
# zeros) # zeros)
version = _norm_version(version) version = _norm_version(version)
return system,release,version return system, release, version
def _win32_getvalue(key,name,default=''): def _win32_getvalue(key, name, default=''):
""" Read a value for name from the registry key. """ Read a value for name from the registry key.
@ -470,14 +470,14 @@ def _win32_getvalue(key,name,default=''):
import winreg import winreg
RegQueryValueEx = winreg.QueryValueEx RegQueryValueEx = winreg.QueryValueEx
try: try:
return RegQueryValueEx(key,name) return RegQueryValueEx(key, name)
except: except:
return default return default
def win32_ver(release='',version='',csd='',ptype=''): def win32_ver(release='', version='', csd='', ptype=''):
""" Get additional version information from the Windows Registry """ Get additional version information from the Windows Registry
and return a tuple (version,csd,ptype) referring to version and return a tuple (version, csd, ptype) referring to version
number, CSD level (service pack), and OS type (multi/single number, CSD level (service pack), and OS type (multi/single
processor). processor).
@ -514,7 +514,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
sys.getwindowsversion sys.getwindowsversion
except AttributeError: except AttributeError:
# No emulation possible, so return the defaults... # No emulation possible, so return the defaults...
return release,version,csd,ptype return release, version, csd, ptype
else: else:
# Emulation using winreg (added in Python 2.0) and # Emulation using winreg (added in Python 2.0) and
# sys.getwindowsversion() (added in Python 2.3) # sys.getwindowsversion() (added in Python 2.3)
@ -532,8 +532,8 @@ def win32_ver(release='',version='',csd='',ptype=''):
# Find out the registry key and some general version infos # Find out the registry key and some general version infos
winver = GetVersionEx() winver = GetVersionEx()
maj,min,buildno,plat,csd = winver maj, min, buildno, plat, csd = winver
version = '%i.%i.%i' % (maj,min,buildno & 0xFFFF) version = '%i.%i.%i' % (maj, min, buildno & 0xFFFF)
if hasattr(winver, "service_pack"): if hasattr(winver, "service_pack"):
if winver.service_pack != "": if winver.service_pack != "":
csd = 'SP%s' % winver.service_pack_major csd = 'SP%s' % winver.service_pack_major
@ -608,8 +608,8 @@ def win32_ver(release='',version='',csd='',ptype=''):
else: else:
if not release: if not release:
# E.g. Win3.1 with win32s # E.g. Win3.1 with win32s
release = '%i.%i' % (maj,min) release = '%i.%i' % (maj, min)
return release,version,csd,ptype return release, version, csd, ptype
# Open the registry key # Open the registry key
try: try:
@ -617,7 +617,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
# Get a value to make sure the key exists... # Get a value to make sure the key exists...
RegQueryValueEx(keyCurVer, 'SystemRoot') RegQueryValueEx(keyCurVer, 'SystemRoot')
except: except:
return release,version,csd,ptype return release, version, csd, ptype
# Parse values # Parse values
#subversion = _win32_getvalue(keyCurVer, #subversion = _win32_getvalue(keyCurVer,
@ -627,17 +627,17 @@ def win32_ver(release='',version='',csd='',ptype=''):
# release = release + subversion # 95a, 95b, etc. # release = release + subversion # 95a, 95b, etc.
build = _win32_getvalue(keyCurVer, build = _win32_getvalue(keyCurVer,
'CurrentBuildNumber', 'CurrentBuildNumber',
('',1))[0] ('', 1))[0]
ptype = _win32_getvalue(keyCurVer, ptype = _win32_getvalue(keyCurVer,
'CurrentType', 'CurrentType',
(ptype,1))[0] (ptype, 1))[0]
# Normalize version # Normalize version
version = _norm_version(version,build) version = _norm_version(version, build)
# Close key # Close key
RegCloseKey(keyCurVer) RegCloseKey(keyCurVer)
return release,version,csd,ptype return release, version, csd, ptype
def _mac_ver_xml(): def _mac_ver_xml():
fn = '/System/Library/CoreServices/SystemVersion.plist' fn = '/System/Library/CoreServices/SystemVersion.plist'
@ -651,16 +651,16 @@ def _mac_ver_xml():
pl = plistlib.readPlist(fn) pl = plistlib.readPlist(fn)
release = pl['ProductVersion'] release = pl['ProductVersion']
versioninfo=('', '', '') versioninfo = ('', '', '')
machine = os.uname().machine machine = os.uname().machine
if machine in ('ppc', 'Power Macintosh'): if machine in ('ppc', 'Power Macintosh'):
# Canonical name # Canonical name
machine = 'PowerPC' machine = 'PowerPC'
return release,versioninfo,machine return release, versioninfo, machine
def mac_ver(release='',versioninfo=('','',''),machine=''): def mac_ver(release='', versioninfo=('', '', ''), machine=''):
""" Get MacOS version information and return it as tuple (release, """ Get MacOS version information and return it as tuple (release,
versioninfo, machine) with versioninfo being a tuple (version, versioninfo, machine) with versioninfo being a tuple (version,
@ -677,9 +677,9 @@ def mac_ver(release='',versioninfo=('','',''),machine=''):
return info return info
# If that also doesn't work return the default values # If that also doesn't work return the default values
return release,versioninfo,machine return release, versioninfo, machine
def _java_getprop(name,default): def _java_getprop(name, default):
from java.lang import System from java.lang import System
try: try:
@ -690,13 +690,13 @@ def _java_getprop(name,default):
except AttributeError: except AttributeError:
return default return default
def java_ver(release='',vendor='',vminfo=('','',''),osinfo=('','','')): def java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', '')):
""" Version interface for Jython. """ Version interface for Jython.
Returns a tuple (release,vendor,vminfo,osinfo) with vminfo being Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being
a tuple (vm_name,vm_release,vm_vendor) and osinfo being a a tuple (vm_name, vm_release, vm_vendor) and osinfo being a
tuple (os_name,os_version,os_arch). tuple (os_name, os_version, os_arch).
Values which cannot be determined are set to the defaults Values which cannot be determined are set to the defaults
given as parameters (which all default to ''). given as parameters (which all default to '').
@ -706,7 +706,7 @@ def java_ver(release='',vendor='',vminfo=('','',''),osinfo=('','','')):
try: try:
import java.lang import java.lang
except ImportError: except ImportError:
return release,vendor,vminfo,osinfo return release, vendor, vminfo, osinfo
vendor = _java_getprop('java.vendor', vendor) vendor = _java_getprop('java.vendor', vendor)
release = _java_getprop('java.version', release) release = _java_getprop('java.version', release)
@ -725,9 +725,9 @@ def java_ver(release='',vendor='',vminfo=('','',''),osinfo=('','','')):
### System name aliasing ### System name aliasing
def system_alias(system,release,version): def system_alias(system, release, version):
""" Returns (system,release,version) aliased to common """ Returns (system, release, version) aliased to common
marketing names used for some systems. marketing names used for some systems.
It also does some reordering of the information in some cases It also does some reordering of the information in some cases
@ -737,13 +737,13 @@ def system_alias(system,release,version):
if system == 'Rhapsody': if system == 'Rhapsody':
# Apple's BSD derivative # Apple's BSD derivative
# XXX How can we determine the marketing release number ? # XXX How can we determine the marketing release number ?
return 'MacOS X Server',system+release,version return 'MacOS X Server', system+release, version
elif system == 'SunOS': elif system == 'SunOS':
# Sun's OS # Sun's OS
if release < '5': if release < '5':
# These releases use the old name SunOS # These releases use the old name SunOS
return system,release,version return system, release, version
# Modify release (marketing release = SunOS release - 3) # Modify release (marketing release = SunOS release - 3)
l = release.split('.') l = release.split('.')
if l: if l:
@ -771,11 +771,11 @@ def system_alias(system,release,version):
else: else:
version = '64bit' version = '64bit'
elif system in ('win32','win16'): elif system in ('win32', 'win16'):
# In case one of the other tricks # In case one of the other tricks
system = 'Windows' system = 'Windows'
return system,release,version return system, release, version
### Various internal helpers ### Various internal helpers
@ -788,21 +788,21 @@ def _platform(*args):
platform = '-'.join(x.strip() for x in filter(len, args)) platform = '-'.join(x.strip() for x in filter(len, args))
# Cleanup some possible filename obstacles... # Cleanup some possible filename obstacles...
platform = platform.replace(' ','_') platform = platform.replace(' ', '_')
platform = platform.replace('/','-') platform = platform.replace('/', '-')
platform = platform.replace('\\','-') platform = platform.replace('\\', '-')
platform = platform.replace(':','-') platform = platform.replace(':', '-')
platform = platform.replace(';','-') platform = platform.replace(';', '-')
platform = platform.replace('"','-') platform = platform.replace('"', '-')
platform = platform.replace('(','-') platform = platform.replace('(', '-')
platform = platform.replace(')','-') platform = platform.replace(')', '-')
# No need to report 'unknown' information... # No need to report 'unknown' information...
platform = platform.replace('unknown','') platform = platform.replace('unknown', '')
# Fold '--'s and remove trailing '-' # Fold '--'s and remove trailing '-'
while 1: while 1:
cleaned = platform.replace('--','-') cleaned = platform.replace('--', '-')
if cleaned == platform: if cleaned == platform:
break break
platform = cleaned platform = cleaned
@ -834,14 +834,14 @@ def _follow_symlinks(filepath):
filepath = os.path.abspath(filepath) filepath = os.path.abspath(filepath)
while os.path.islink(filepath): while os.path.islink(filepath):
filepath = os.path.normpath( filepath = os.path.normpath(
os.path.join(os.path.dirname(filepath),os.readlink(filepath))) os.path.join(os.path.dirname(filepath), os.readlink(filepath)))
return filepath return filepath
def _syscmd_uname(option,default=''): def _syscmd_uname(option, default=''):
""" Interface to the system's uname command. """ Interface to the system's uname command.
""" """
if sys.platform in ('dos','win32','win16'): if sys.platform in ('dos', 'win32', 'win16'):
# XXX Others too ? # XXX Others too ?
return default return default
try: try:
@ -855,7 +855,7 @@ def _syscmd_uname(option,default=''):
else: else:
return output return output
def _syscmd_file(target,default=''): def _syscmd_file(target, default=''):
""" Interface to the system's file command. """ Interface to the system's file command.
@ -864,7 +864,7 @@ def _syscmd_file(target,default=''):
default in case the command should fail. default in case the command should fail.
""" """
if sys.platform in ('dos','win32','win16'): if sys.platform in ('dos', 'win32', 'win16'):
# XXX Others too ? # XXX Others too ?
return default return default
target = _follow_symlinks(target) target = _follow_symlinks(target)
@ -886,17 +886,17 @@ def _syscmd_file(target,default=''):
# Default values for architecture; non-empty strings override the # Default values for architecture; non-empty strings override the
# defaults given as parameters # defaults given as parameters
_default_architecture = { _default_architecture = {
'win32': ('','WindowsPE'), 'win32': ('', 'WindowsPE'),
'win16': ('','Windows'), 'win16': ('', 'Windows'),
'dos': ('','MSDOS'), 'dos': ('', 'MSDOS'),
} }
def architecture(executable=sys.executable,bits='',linkage=''): def architecture(executable=sys.executable, bits='', linkage=''):
""" Queries the given executable (defaults to the Python interpreter """ Queries the given executable (defaults to the Python interpreter
binary) for various architecture information. binary) for various architecture information.
Returns a tuple (bits,linkage) which contains information about Returns a tuple (bits, linkage) which contains information about
the bit architecture and the linkage format used for the the bit architecture and the linkage format used for the
executable. Both values are returned as strings. executable. Both values are returned as strings.
@ -934,16 +934,16 @@ def architecture(executable=sys.executable,bits='',linkage=''):
# "file" command did not return anything; we'll try to provide # "file" command did not return anything; we'll try to provide
# some sensible defaults then... # some sensible defaults then...
if sys.platform in _default_architecture: if sys.platform in _default_architecture:
b,l = _default_architecture[sys.platform] b, l = _default_architecture[sys.platform]
if b: if b:
bits = b bits = b
if l: if l:
linkage = l linkage = l
return bits,linkage return bits, linkage
if 'executable' not in fileout: if 'executable' not in fileout:
# Format not supported # Format not supported
return bits,linkage return bits, linkage
# Bits # Bits
if '32-bit' in fileout: if '32-bit' in fileout:
@ -971,7 +971,7 @@ def architecture(executable=sys.executable,bits='',linkage=''):
# XXX the A.OUT format also falls under this class... # XXX the A.OUT format also falls under this class...
pass pass
return bits,linkage return bits, linkage
### Portable uname() interface ### Portable uname() interface
@ -983,7 +983,7 @@ _uname_cache = None
def uname(): def uname():
""" Fairly portable uname interface. Returns a tuple """ Fairly portable uname interface. Returns a tuple
of strings (system,node,release,version,machine,processor) of strings (system, node, release, version, machine, processor)
identifying the underlying platform. identifying the underlying platform.
Note that unlike the os.uname function this also returns Note that unlike the os.uname function this also returns
@ -1002,7 +1002,7 @@ def uname():
# Get some infos from the builtin os.uname API... # Get some infos from the builtin os.uname API...
try: try:
system,node,release,version,machine = os.uname() system, node, release, version, machine = os.uname()
except AttributeError: except AttributeError:
no_os_uname = 1 no_os_uname = 1
@ -1020,7 +1020,7 @@ def uname():
# Try win32_ver() on win32 platforms # Try win32_ver() on win32 platforms
if system == 'win32': if system == 'win32':
release,version,csd,ptype = win32_ver() release, version, csd, ptype = win32_ver()
if release and version: if release and version:
use_syscmd_ver = 0 use_syscmd_ver = 0
# Try to use the PROCESSOR_* environment variables # Try to use the PROCESSOR_* environment variables
@ -1039,7 +1039,7 @@ def uname():
# Try the 'ver' system command available on some # Try the 'ver' system command available on some
# platforms # platforms
if use_syscmd_ver: if use_syscmd_ver:
system,release,version = _syscmd_ver(system) system, release, version = _syscmd_ver(system)
# Normalize system to what win32_ver() normally returns # Normalize system to what win32_ver() normally returns
# (_syscmd_ver() tends to return the vendor name as well) # (_syscmd_ver() tends to return the vendor name as well)
if system == 'Microsoft Windows': if system == 'Microsoft Windows':
@ -1057,7 +1057,7 @@ def uname():
# In case we still don't know anything useful, we'll try to # In case we still don't know anything useful, we'll try to
# help ourselves # help ourselves
if system in ('win32','win16'): if system in ('win32', 'win16'):
if not version: if not version:
if system == 'win32': if system == 'win32':
version = '32bit' version = '32bit'
@ -1066,7 +1066,7 @@ def uname():
system = 'Windows' system = 'Windows'
elif system[:4] == 'java': elif system[:4] == 'java':
release,vendor,vminfo,osinfo = java_ver() release, vendor, vminfo, osinfo = java_ver()
system = 'Java' system = 'Java'
version = ', '.join(vminfo) version = ', '.join(vminfo)
if not version: if not version:
@ -1084,14 +1084,14 @@ def uname():
except ImportError: except ImportError:
pass pass
else: else:
csid, cpu_number = vms_lib.getsyi('SYI$_CPU',0) csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
if (cpu_number >= 128): if (cpu_number >= 128):
processor = 'Alpha' processor = 'Alpha'
else: else:
processor = 'VAX' processor = 'VAX'
if not processor: if not processor:
# Get processor information from the uname system command # Get processor information from the uname system command
processor = _syscmd_uname('-p','') processor = _syscmd_uname('-p', '')
#If any unknowns still exist, replace them with ''s, which are more portable #If any unknowns still exist, replace them with ''s, which are more portable
if system == 'unknown': if system == 'unknown':
@ -1112,7 +1112,8 @@ def uname():
system = 'Windows' system = 'Windows'
release = 'Vista' release = 'Vista'
_uname_cache = uname_result(system,node,release,version,machine,processor) _uname_cache = uname_result(system, node, release, version,
machine, processor)
return _uname_cache return _uname_cache
### Direct interfaces to some of the uname() return values ### Direct interfaces to some of the uname() return values
@ -1409,57 +1410,58 @@ def platform(aliased=0, terse=0):
# Get uname information and then apply platform specific cosmetics # Get uname information and then apply platform specific cosmetics
# to it... # to it...
system,node,release,version,machine,processor = uname() system, node, release, version, machine, processor = uname()
if machine == processor: if machine == processor:
processor = '' processor = ''
if aliased: if aliased:
system,release,version = system_alias(system,release,version) system, release, version = system_alias(system, release, version)
if system == 'Windows': if system == 'Windows':
# MS platforms # MS platforms
rel,vers,csd,ptype = win32_ver(version) rel, vers, csd, ptype = win32_ver(version)
if terse: if terse:
platform = _platform(system,release) platform = _platform(system, release)
else: else:
platform = _platform(system,release,version,csd) platform = _platform(system, release, version, csd)
elif system in ('Linux',): elif system in ('Linux',):
# Linux based systems # Linux based systems
distname,distversion,distid = dist('') distname, distversion, distid = dist('')
if distname and not terse: if distname and not terse:
platform = _platform(system,release,machine,processor, platform = _platform(system, release, machine, processor,
'with', 'with',
distname,distversion,distid) distname, distversion, distid)
else: else:
# If the distribution name is unknown check for libc vs. glibc # If the distribution name is unknown check for libc vs. glibc
libcname,libcversion = libc_ver(sys.executable) libcname, libcversion = libc_ver(sys.executable)
platform = _platform(system,release,machine,processor, platform = _platform(system, release, machine, processor,
'with', 'with',
libcname+libcversion) libcname+libcversion)
elif system == 'Java': elif system == 'Java':
# Java platforms # Java platforms
r,v,vminfo,(os_name,os_version,os_arch) = java_ver() r, v, vminfo, (os_name, os_version, os_arch) = java_ver()
if terse or not os_name: if terse or not os_name:
platform = _platform(system,release,version) platform = _platform(system, release, version)
else: else:
platform = _platform(system,release,version, platform = _platform(system, release, version,
'on', 'on',
os_name,os_version,os_arch) os_name, os_version, os_arch)
elif system == 'MacOS': elif system == 'MacOS':
# MacOS platforms # MacOS platforms
if terse: if terse:
platform = _platform(system,release) platform = _platform(system, release)
else: else:
platform = _platform(system,release,machine) platform = _platform(system, release, machine)
else: else:
# Generic handler # Generic handler
if terse: if terse:
platform = _platform(system,release) platform = _platform(system, release)
else: else:
bits,linkage = architecture(sys.executable) bits, linkage = architecture(sys.executable)
platform = _platform(system,release,machine,processor,bits,linkage) platform = _platform(system, release, machine,
processor, bits, linkage)
_platform_cache[(aliased, terse)] = platform _platform_cache[(aliased, terse)] = platform
return platform return platform
@ -1470,5 +1472,5 @@ if __name__ == '__main__':
# Default is to print the aliased verbose platform string # Default is to print the aliased verbose platform string
terse = ('terse' in sys.argv or '--terse' in sys.argv) terse = ('terse' in sys.argv or '--terse' in sys.argv)
aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv) aliased = (not 'nonaliased' in sys.argv and not '--nonaliased' in sys.argv)
print(platform(aliased,terse)) print(platform(aliased, terse))
sys.exit(0) sys.exit(0)