diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 18:28:09 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 18:28:09 (GMT) |
commit | b27ee20b9c84bf30b59bf0c9b9da5e91c84932a1 (patch) | |
tree | 01132db9dc5a8005296b80cc2dfb0eab401f475e /Lib/platform.py | |
parent | c45c3d995053edd6ffc899853815443a4c6f8a13 (diff) | |
download | cpython-b27ee20b9c84bf30b59bf0c9b9da5e91c84932a1.zip cpython-b27ee20b9c84bf30b59bf0c9b9da5e91c84932a1.tar.gz cpython-b27ee20b9c84bf30b59bf0c9b9da5e91c84932a1.tar.bz2 |
Revert r80167, it breaks build on many platforms
Diffstat (limited to 'Lib/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 2801e8b..1601d59 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -111,7 +111,7 @@ __copyright__ = """ __version__ = '1.0.7' -import sys, os, re, subprocess +import sys, os, re ### Globals & Constants @@ -942,20 +942,13 @@ def _syscmd_file(target,default=''): if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default - 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] - output = output.decode('ASCII') - rc = proc.wait() + output = f.read().strip() + rc = f.close() if not output or rc: return default else: @@ -971,6 +964,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 @@ -1005,11 +1000,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... @@ -1021,6 +1016,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 |