Commit 84da0905 authored by Eric Smith's avatar Eric Smith

Per the discussion in issue6882, backport the try/finally work that was done...

Per the discussion in issue6882, backport the try/finally work that was done to the py3k version (mostly in r59477, I think).
parent 60bae6f1
...@@ -96,7 +96,9 @@ elif os.name == "posix": ...@@ -96,7 +96,9 @@ elif os.name == "posix":
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
try: try:
f = os.popen(cmd) f = os.popen(cmd)
try:
trace = f.read() trace = f.read()
finally:
rv = f.close() rv = f.close()
finally: finally:
try: try:
...@@ -118,7 +120,12 @@ elif os.name == "posix": ...@@ -118,7 +120,12 @@ elif os.name == "posix":
if not f: if not f:
return None return None
cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', os.popen(cmd).read()) f = os.popen(cmd)
try:
data = f.read()
finally:
f.close()
res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
if not res: if not res:
return None return None
return res.group(1) return res.group(1)
...@@ -134,7 +141,12 @@ elif os.name == "posix": ...@@ -134,7 +141,12 @@ elif os.name == "posix":
rv = f.close() rv = f.close()
if rv == 10: if rv == 10:
raise OSError, 'objdump command not found' raise OSError, 'objdump command not found'
res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) f = os.popen(cmd)
try:
data = f.read()
finally:
f.close()
res = re.search(r'\sSONAME\s+([^\s]+)', data)
if not res: if not res:
return None return None
return res.group(1) return res.group(1)
...@@ -157,8 +169,12 @@ elif os.name == "posix": ...@@ -157,8 +169,12 @@ elif os.name == "posix":
def find_library(name): def find_library(name):
ename = re.escape(name) ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename) expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
res = re.findall(expr, f = os.popen('/sbin/ldconfig -r 2>/dev/null')
os.popen('/sbin/ldconfig -r 2>/dev/null').read()) try:
data = f.read()
finally:
f.close()
res = re.findall(expr, data)
if not res: if not res:
return _get_soname(_findLib_gcc(name)) return _get_soname(_findLib_gcc(name))
res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y))) res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
...@@ -169,12 +185,21 @@ elif os.name == "posix": ...@@ -169,12 +185,21 @@ elif os.name == "posix":
def _findLib_ldconfig(name): def _findLib_ldconfig(name):
# XXX assuming GLIBC's ldconfig (with option -p) # XXX assuming GLIBC's ldconfig (with option -p)
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
res = re.search(expr, f = os.popen('/sbin/ldconfig -p 2>/dev/null')
os.popen('/sbin/ldconfig -p 2>/dev/null').read()) try:
data = f.read()
finally:
f.close()
res = re.search(expr, data)
if not res: if not res:
# Hm, this works only for libs needed by the python executable. # Hm, this works only for libs needed by the python executable.
cmd = 'ldd %s 2>/dev/null' % sys.executable cmd = 'ldd %s 2>/dev/null' % sys.executable
res = re.search(expr, os.popen(cmd).read()) f = os.popen(cmd)
try:
data = f.read()
finally:
f.close()
res = re.search(expr, data)
if not res: if not res:
return None return None
return res.group(0) return res.group(0)
...@@ -197,8 +222,12 @@ elif os.name == "posix": ...@@ -197,8 +222,12 @@ elif os.name == "posix":
# XXX assuming GLIBC's ldconfig (with option -p) # XXX assuming GLIBC's ldconfig (with option -p)
expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \ expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
% (abi_type, re.escape(name)) % (abi_type, re.escape(name))
res = re.search(expr, f = os.popen('/sbin/ldconfig -p 2>/dev/null')
os.popen('/sbin/ldconfig -p 2>/dev/null').read()) try:
data = f.read()
finally:
f.close()
res = re.search(expr, data)
if not res: if not res:
return None return None
return res.group(1) return res.group(1)
......
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