From e83d8e58a6b107eea87df0ec233a1bc932b2c6ea Mon Sep 17 00:00:00 2001 From: Robert Yang Date: Tue, 29 May 2012 22:53:08 +0800 Subject: meta: replace os.popen with subprocess.Popen Replace os.popen with subprocess.Popen since the older function would fail (more or less) silently if the executed program cannot be found There are both bb.process.run() and bb.process.Popen() which wraps the subprocess module, use it for simplifying the code. Note: We don't need the "2>/dev/null" or "2>&1" since bb.process.run() can handle it, it will raise exception when error occurs, we should handle the exception ourselves if we want to ignore the error. More info: http://docs.python.org/library/subprocess.html#subprocess-replacements [YOCTO #2454] Signed-off-by: Robert Yang Signed-off-by: Richard Purdie --- meta/classes/package.bbclass | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'meta/classes/package.bbclass') diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 41139ef921..bc83bfbf4e 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass @@ -1061,7 +1061,7 @@ python emit_pkgdata() { def get_directory_size(dir): if os.listdir(dir): - size = int(os.popen('du -sk %s' % dir).readlines()[0].split('\t')[0]) + size = int(bb.process.run('du -sk %s' % dir)[0].split('\t')[0]) else: size = 0 return size @@ -1221,7 +1221,7 @@ python package_do_filedeps() { rpfiles.append(os.path.join(root, file)) for files in chunks(rpfiles, 100): - dep_pipe = os.popen(rpmdeps + " " + " ".join(files)) + dep_pipe = bb.process.Popen(rpmdeps + " " + " ".join(files), shell=True).stdout process_deps(dep_pipe, pkg, provides_files, requires_files) @@ -1263,11 +1263,15 @@ python package_do_shlibs() { def linux_so(root, path, file): needs_ldconfig = False - cmd = d.getVar('OBJDUMP', True) + " -p " + pipes.quote(os.path.join(root, file)) + " 2>/dev/null" + cmd = d.getVar('OBJDUMP', True) + " -p " + pipes.quote(os.path.join(root, file)) cmd = "PATH=\"%s\" %s" % (d.getVar('PATH', True), cmd) - fd = os.popen(cmd) - lines = fd.readlines() - fd.close() + try: + lines = "" + lines = bb.process.run(cmd)[0] + # Some ".so" maybe ascii text, e.g: /usr/lib64/libpthread.so, + # ingore those errors. + except Exception: + sys.exc_clear() for l in lines: m = re.match("\s+NEEDED\s+([^\s]*)", l) if m: -- cgit 1.2.3-korg