diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 18:22:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 18:22:25 (GMT) |
commit | 814b6c222dfbff0a9ea7d96b493c565e9b3beb24 (patch) | |
tree | 35c6f8486bfe3bd586f06512303899e84b755e67 | |
parent | 974eb5eace4187c81f2bc13022260467eb72c82b (diff) | |
download | cpython-814b6c222dfbff0a9ea7d96b493c565e9b3beb24.zip cpython-814b6c222dfbff0a9ea7d96b493c565e9b3beb24.tar.gz cpython-814b6c222dfbff0a9ea7d96b493c565e9b3beb24.tar.bz2 |
Revert r80166 (and r80171), restore Lib/platform.py. subprocess cannot be used in platform.py
-rwxr-xr-x | Lib/platform.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index b213a92..79695ba 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -113,7 +113,7 @@ __copyright__ = """ __version__ = '1.0.7' -import sys, string, os, re +import sys,string,os,re ### Globals & Constants @@ -966,20 +966,13 @@ def _syscmd_file(target,default=''): if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default - import subprocess - target = _follow_symlinks(target) + target = _follow_symlinks(target).replace('"', '\\"') try: - proc = subprocess.Popen( - ['file', target], - stdout=subprocess.PIPE, - stderr=open(DEV_NULL, 'wb')) + f = os.popen('file "%s" 2> %s' % (target, DEV_NULL)) except (AttributeError,os.error): return default - stdout, stderr = proc.communicate() - stdout = stdout.rstrip(b'\n\r') - # get output from "filename: output" - output = stdout.split(b': ', 1)[-1] - rc = proc.wait() + output = string.strip(f.read()) + rc = f.close() if not output or rc: return default else: @@ -995,6 +988,8 @@ _default_architecture = { '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 @@ -1029,11 +1024,11 @@ def architecture(executable=sys.executable,bits='',linkage=''): # Get data from the 'file' system command if executable: - fileout = _syscmd_file(executable, '') + output = _syscmd_file(executable, '') else: - fileout = '' + output = '' - if not fileout and \ + if not output and \ executable == sys.executable: # "file" command did not return anything; we'll try to provide # some sensible defaults then... @@ -1045,6 +1040,9 @@ def architecture(executable=sys.executable,bits='',linkage=''): 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: # Format not supported return bits,linkage |