Skip to content

Commit 7f6c669

Browse files
committed
replace use of getstatusoutput() with which(command) followed by command()
1 parent beb878d commit 7f6c669

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

lib/spack/spack/relocate.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import stat
66
import platform
77
import re
8-
from commands import getstatusoutput
98
from spack.util.executable import which
109

1110
import llnl.util.tty as tty
@@ -16,9 +15,9 @@ def get_existing_elf_rpaths(path_name, patchelf_executable):
1615
Return the RPATHS in given elf file as a list of strings.
1716
"""
1817
if platform.system() == 'Linux':
19-
command = '%s --print-rpath %s ' % (patchelf_executable, path_name)
20-
status, output = getstatusoutput(command)
21-
if status != 0:
18+
command = which(patchelf_executable)
19+
output=command('--print-rpath' ,'%s' % path_name, output=str, err=str)
20+
if command.returncode != 0:
2221
tty.warn('failed reading rpath for %s.' % path_name)
2322
return False
2423
return output.split(':')
@@ -53,9 +52,9 @@ def modify_macho_object(path_name, old_dir, new_dir):
5352
the old install dir in LC_RPATH is replaced with the new install dir using
5453
install_name_tool -rpath old new binary
5554
"""
56-
command = which('otool')
57-
output = command("-l", path_name, output=str, err=str)
58-
if command.returncode != 0:
55+
otool = which('otool')
56+
output = otool("-l", path_name, output=str, err=str)
57+
if otool.returncode != 0:
5958
tty.warn('failed reading rpath for %s.' % path_name)
6059
return False
6160
last_cmd = None
@@ -93,26 +92,22 @@ def modify_macho_object(path_name, old_dir, new_dir):
9392
if not wmode:
9493
os.chmod(path_name, st.st_mode | stat.S_IWUSR)
9594

95+
install_name_tool=which('install_name_tool')
9696
if id:
97-
command = ("install_name_tool -id %s %s" % (id, path_name))
98-
status, output = getstatusoutput(command)
99-
if status != 0:
97+
output = install_name_tool('-id', id, path_name, output=str, err=str)
98+
if install_name_tool.returncode != 0:
10099
tty.warn('failed writing id for %s.' % path_name)
101100
tty.warn(output)
102101

103102
for orig, new in zip(deps, ndeps):
104-
command = ("install_name_tool -change %s %s %s" %
105-
(orig, new, path_name))
106-
status, output = getstatusoutput(command)
107-
if status != 0:
103+
output = install_name_tool('-change', orig, new, path_name)
104+
if install_name_tool.returncode != 0:
108105
tty.warn('failed writing dep for %s.' % path_name)
109106
tty.warn(output)
110107

111108
for orig, new in zip(rpaths, nrpaths):
112-
command = ("install_name_tool -rpath %s %s %s" %
113-
(orig, new, path_name))
114-
status, output = getstatusoutput(command)
115-
if status != 0:
109+
output = install_name_tool('-rpath', orig, new, path_name)
110+
if install_name_tool.returncode != 0:
116111
tty.warn('failed writing id for %s.' % path_name)
117112
tty.warn(output)
118113

@@ -124,9 +119,10 @@ def get_filetype(path_name):
124119
"""
125120
Check the output of the file command for given string.
126121
"""
127-
file_command = "LC_ALL=C file -b -h \"%s\"" % path_name
128-
status, output = getstatusoutput(file_command)
129-
if status != 0:
122+
bash=which('bash')
123+
output = bash('-c','LC_ALL=C && file -b -h %s' % path_name,
124+
output=str, err=str)
125+
if bash.returncode != 0:
130126
tty.warn('getting filetype of "%s" failed' % path_name)
131127
return None
132128
return output.strip()
@@ -142,10 +138,10 @@ def modify_elf_object(path_name, orig_rpath, new_rpath, patchelf_executable):
142138
os.chmod(path_name, st.st_mode | stat.S_IWUSR)
143139
if platform.system() == 'Linux':
144140
new_joined = ':'.join(new_rpath)
145-
command = "%s --force-rpath --set-rpath '%s' '%s'" % \
146-
(patchelf_executable, new_joined, path_name)
147-
status, output = getstatusoutput(command)
148-
if status != 0:
141+
command = which(patchelf_executable)
142+
output=command('--force-rpath', '--set-rpath %s' % new_joined,
143+
'%s' % path_name, output=str, cmd=str)
144+
if command.returncode != 0:
149145
tty.warn('failed writing rpath for %s.' % path_name)
150146
else:
151147
tty.die('relocation not supported for this platform')

0 commit comments

Comments
 (0)