diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2012-05-29 22:53:08 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-05-30 10:58:10 +0100 |
commit | e83d8e58a6b107eea87df0ec233a1bc932b2c6ea (patch) | |
tree | 7373c71af06a1cc504ee251615c80ae3c07e6347 /meta/classes/metadata_scm.bbclass | |
parent | 57f843146ed62c04c23bc380dc8cb38aba264f1c (diff) | |
download | openembedded-core-e83d8e58a6b107eea87df0ec233a1bc932b2c6ea.tar.gz openembedded-core-e83d8e58a6b107eea87df0ec233a1bc932b2c6ea.tar.bz2 openembedded-core-e83d8e58a6b107eea87df0ec233a1bc932b2c6ea.zip |
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 <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/metadata_scm.bbclass')
-rw-r--r-- | meta/classes/metadata_scm.bbclass | 12 |
1 files changed, 5 insertions, 7 deletions
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 "<unknown>" 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 "<unknown>" |