Commit b27ee20b authored by Victor Stinner's avatar Victor Stinner

Revert r80167, it breaks build on many platforms

parent c45c3d99
...@@ -111,7 +111,7 @@ __copyright__ = """ ...@@ -111,7 +111,7 @@ __copyright__ = """
__version__ = '1.0.7' __version__ = '1.0.7'
import sys, os, re, subprocess import sys, os, re
### Globals & Constants ### Globals & Constants
...@@ -942,20 +942,13 @@ def _syscmd_file(target,default=''): ...@@ -942,20 +942,13 @@ def _syscmd_file(target,default=''):
if sys.platform in ('dos','win32','win16','os2'): if sys.platform in ('dos','win32','win16','os2'):
# XXX Others too ? # XXX Others too ?
return default return default
target = _follow_symlinks(target) target = _follow_symlinks(target).replace('"', '\\"')
try: try:
proc = subprocess.Popen( f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
['file', target],
stdout=subprocess.PIPE,
stderr=open(DEV_NULL, 'wb'))
except (AttributeError,os.error): except (AttributeError,os.error):
return default return default
stdout, stderr = proc.communicate() output = f.read().strip()
stdout = stdout.rstrip(b'\n\r') rc = f.close()
# get output from "filename: output"
output = stdout.split(b': ', 1)[-1]
output = output.decode('ASCII')
rc = proc.wait()
if not output or rc: if not output or rc:
return default return default
else: else:
...@@ -971,6 +964,8 @@ _default_architecture = { ...@@ -971,6 +964,8 @@ _default_architecture = {
'dos': ('','MSDOS'), 'dos': ('','MSDOS'),
} }
_architecture_split = re.compile(r'[\s,]').split
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
...@@ -1005,11 +1000,11 @@ def architecture(executable=sys.executable,bits='',linkage=''): ...@@ -1005,11 +1000,11 @@ def architecture(executable=sys.executable,bits='',linkage=''):
# Get data from the 'file' system command # Get data from the 'file' system command
if executable: if executable:
fileout = _syscmd_file(executable, '') output = _syscmd_file(executable, '')
else: else:
fileout = '' output = ''
if not fileout and \ if not output and \
executable == sys.executable: executable == sys.executable:
# "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...
...@@ -1021,6 +1016,9 @@ def architecture(executable=sys.executable,bits='',linkage=''): ...@@ -1021,6 +1016,9 @@ def architecture(executable=sys.executable,bits='',linkage=''):
linkage = l linkage = l
return bits,linkage 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 fileout:
# Format not supported # Format not supported
return bits,linkage return bits,linkage
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment