mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 80166 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80166 | victor.stinner | 2010-04-18 11:07:49 +0200 (dim., 18 avril 2010) | 7 lines platform: use subprocess.Popen() instead of os.popen() in _syscmd_file() * Popen() avoids ugly shell escape: target.replace('"', '\\"') * Use proc.communicate() instead of f.stdout.read() * Get output from stdout by splitting with ": " instead of splitting by spaces to support filename with spaces ........
This commit is contained in:
parent
1efde679ce
commit
38148ea5f0
1 changed files with 15 additions and 13 deletions
|
@ -111,7 +111,7 @@ __copyright__ = """
|
||||||
|
|
||||||
__version__ = '1.0.7'
|
__version__ = '1.0.7'
|
||||||
|
|
||||||
import sys, os, re
|
import sys, os, re, subprocess
|
||||||
|
|
||||||
### Globals & Constants
|
### Globals & Constants
|
||||||
|
|
||||||
|
@ -942,13 +942,20 @@ 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).replace('"', '\\"')
|
target = _follow_symlinks(target)
|
||||||
try:
|
try:
|
||||||
f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
|
proc = subprocess.Popen(
|
||||||
|
['file', target],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=open(DEV_NULL, 'wb'))
|
||||||
except (AttributeError,os.error):
|
except (AttributeError,os.error):
|
||||||
return default
|
return default
|
||||||
output = f.read().strip()
|
stdout, stderr = proc.communicate()
|
||||||
rc = f.close()
|
stdout = stdout.rstrip(b'\n\r')
|
||||||
|
# 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:
|
||||||
|
@ -964,8 +971,6 @@ _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
|
||||||
|
@ -1000,11 +1005,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:
|
||||||
output = _syscmd_file(executable, '')
|
fileout = _syscmd_file(executable, '')
|
||||||
else:
|
else:
|
||||||
output = ''
|
fileout = ''
|
||||||
|
|
||||||
if not output and \
|
if not fileout 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...
|
||||||
|
@ -1016,9 +1021,6 @@ 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue