Index: lib/platform.py =================================================================== --- lib/platform.py (revision 66142) +++ lib/platform.py (working copy) @@ -112,7 +112,7 @@ __version__ = '1.0.6' -import sys,string,os,re +import sys,string,os,re,subprocess ### Platform specific APIs @@ -936,24 +936,29 @@ os.path.join(filepath,os.readlink(filepath))) return filepath -def _syscmd_uname(option,default=''): +def _syscmd(command,default): - """ Interface to the system's uname command. + """ Interface to the system command. """ if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default try: - f = os.popen('uname %s 2> /dev/null' % option) + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except (AttributeError,os.error): return default - output = string.strip(f.read()) - rc = f.close() - if not output or rc: + output = string.strip(p.communicate()[0]) + if not output or p.returncode: return default else: return output +def _syscmd_uname(option,default=''): + + """ Interface to the system's uname command. + """ + return _syscmd(['uname', option], default) + def _syscmd_file(target,default=''): """ Interface to the system's file command. @@ -964,20 +969,7 @@ case the command should fail. """ - if sys.platform in ('dos','win32','win16','os2'): - # XXX Others too ? - return default - target = _follow_symlinks(target) - try: - f = os.popen('file %s 2> /dev/null' % target) - except (AttributeError,os.error): - return default - output = string.strip(f.read()) - rc = f.close() - if not output or rc: - return default - else: - return output + return _syscmd(['file', '-b', _follow_symlinks(target)], default) ### Information about the used architecture @@ -989,8 +981,6 @@ 'dos': ('','MSDOS'), } -_architecture_split = re.compile(r'[\s,]').split - def architecture(executable=sys.executable,bits='',linkage=''): """ Queries the given executable (defaults to the Python interpreter @@ -1041,34 +1031,31 @@ linkage = l return bits,linkage - # Split the output into a list of strings omitting the filename - fileout = _architecture_split(output)[1:] - - if 'executable' not in fileout: + if 'executable' not in output: # Format not supported return bits,linkage # Bits - if '32-bit' in fileout: + if '32-bit' in output: bits = '32bit' - elif 'N32' in fileout: + elif 'N32' in output: # On Irix only bits = 'n32bit' - elif '64-bit' in fileout: + elif '64-bit' in output: bits = '64bit' # Linkage - if 'ELF' in fileout: + if 'ELF' in output: linkage = 'ELF' - elif 'PE' in fileout: + elif 'PE' in output: # E.g. Windows uses this format - if 'Windows' in fileout: + if 'Windows' in output: linkage = 'WindowsPE' else: linkage = 'PE' - elif 'COFF' in fileout: + elif 'COFF' in output: linkage = 'COFF' - elif 'MS-DOS' in fileout: + elif 'MS-DOS' in output: linkage = 'MSDOS' else: # XXX the A.OUT format also falls under this class...