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/metadata_scm.bbclass | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'meta/classes/metadata_scm.bbclass') diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass index 62650be675..5af593ae46 100644 --- a/meta/classes/metadata_scm.bbclass +++ b/meta/classes/metadata_scm.bbclass @@ -60,18 +60,16 @@ def base_get_metadata_svn_revision(path, d): return revision def base_get_metadata_git_branch(path, d): - branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read() + branch = bb.process.run('cd %s; git branch | grep "^* " | tr -d "* "' % path)[0] if len(branch) != 0: return branch return "" def base_get_metadata_git_revision(path, d): - f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path) - data = f.read() - if f.close() is None: - rev = data.split(" ")[0] - if len(rev) != 0: - return rev + rev = bb.process.run("cd %s; git log -n 1 --pretty=oneline" % path)[0] + if len(rev) != 0: + rev = rev.split(" ")[0] + return rev return "" -- cgit 1.2.3-korg