From: Robert Yang <liezhi.yang@windriver.com>
To: <bitbake-devel@lists.openembedded.org>
Cc: Zhenfeng.Zhao@windriver.com
Subject: [PATCH 2/2] replace os.popen with subprocess.Popen
Date: Mon, 14 May 2012 16:07:35 +0800 [thread overview]
Message-ID: <a072dd7795f44603322db6583ac748f0418684fd.1336974361.git.liezhi.yang@windriver.com> (raw)
In-Reply-To: <cover.1336974361.git.liezhi.yang@windriver.com>
Replace os.popen with subprocess.Popen since the older function would
fail (more or less) silently if the executed program cannot be found
More info:
http://docs.python.org/library/subprocess.html#subprocess-replacements
[YOCTO #2075]
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
bitbake/lib/bb/fetch2/perforce.py | 6 +++---
bitbake/lib/bb/fetch2/svk.py | 3 ++-
bitbake/lib/bb/ui/crumbs/builddetailspage.py | 3 ++-
bitbake/lib/bb/ui/crumbs/hig.py | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py
index 6abf15d..ad7df5f 100644
--- a/bitbake/lib/bb/fetch2/perforce.py
+++ b/bitbake/lib/bb/fetch2/perforce.py
@@ -91,7 +91,7 @@ class Perforce(FetchMethod):
p4cmd = data.getVar('FETCHCOMMAND_p4', d, True)
logger.debug(1, "Running %s%s changes -m 1 %s", p4cmd, p4opt, depot)
- p4file = os.popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
+ p4file = subprocess.Popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot), shell=True, stdout=subprocess.PIPE).stdout
cset = p4file.readline().strip()
logger.debug(1, "READ %s", cset)
if not cset:
@@ -155,7 +155,7 @@ class Perforce(FetchMethod):
logger.debug(2, "Fetch: creating temporary directory")
bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata))
data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata)
- tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false")
+ tmppipe = subprocess.Popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false", shell=True, stdout=subprocess.PIPE).stdout
tmpfile = tmppipe.readline().strip()
if not tmpfile:
raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc)
@@ -169,7 +169,7 @@ class Perforce(FetchMethod):
os.chdir(tmpfile)
logger.info("Fetch " + loc)
logger.info("%s%s files %s", p4cmd, p4opt, depot)
- p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot))
+ p4file = subprocess.Popen("%s%s files %s" % (p4cmd, p4opt, depot), shell=True, stdout=subprocess.PIPE).stdout
if not p4file:
raise FetchError("Fetch: unable to get the P4 files from %s" % depot, loc)
diff --git a/bitbake/lib/bb/fetch2/svk.py b/bitbake/lib/bb/fetch2/svk.py
index 9d34abf..cfca713 100644
--- a/bitbake/lib/bb/fetch2/svk.py
+++ b/bitbake/lib/bb/fetch2/svk.py
@@ -26,6 +26,7 @@ This implementation is for svk. It is based on the svn implementation
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
import os
+import subprocess
import logging
import bb
from bb import data
@@ -77,7 +78,7 @@ class Svk(FetchMethod):
logger.debug(2, "Fetch: creating temporary directory")
bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata))
data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata)
- tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false")
+ tmppipe = subprocess.Popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false", shell=True, stdout=subprocess.PIPE).stdout
tmpfile = tmppipe.readline().strip()
if not tmpfile:
logger.error()
diff --git a/bitbake/lib/bb/ui/crumbs/builddetailspage.py b/bitbake/lib/bb/ui/crumbs/builddetailspage.py
index 51e6a4a..30f8249 100755
--- a/bitbake/lib/bb/ui/crumbs/builddetailspage.py
+++ b/bitbake/lib/bb/ui/crumbs/builddetailspage.py
@@ -28,6 +28,7 @@ from bb.ui.crumbs.hobwidget import hic, HobNotebook, HobAltButton, HobWarpCellRe
from bb.ui.crumbs.runningbuild import RunningBuildTreeView
from bb.ui.crumbs.runningbuild import BuildFailureTreeView
from bb.ui.crumbs.hobpages import HobPage
+import subprocess
class BuildConfigurationTreeView(gtk.TreeView):
def __init__ (self):
@@ -96,7 +97,7 @@ class BuildConfigurationTreeView(gtk.TreeView):
for path in src_config_info.layers:
import os, os.path
if os.path.exists(path):
- f = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path)
+ f = subprocess.Popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path, shell=True, stdout=subprocess.PIPE).stdout
if f:
branch = f.readline().lstrip('\n').rstrip('\n')
vars.append(self.set_vars("Branch:", branch))
diff --git a/bitbake/lib/bb/ui/crumbs/hig.py b/bitbake/lib/bb/ui/crumbs/hig.py
index 4baf960..e7650f2 100644
--- a/bitbake/lib/bb/ui/crumbs/hig.py
+++ b/bitbake/lib/bb/ui/crumbs/hig.py
@@ -726,7 +726,7 @@ class DeployImageDialog (CrumbsDialog):
self.progress_bar.hide()
def popen_read(self, cmd):
- return os.popen("%s 2>/dev/null" % cmd).read().strip()
+ return subprocess.Popen("%s 2>/dev/null" % cmd, shell=True, stdout=subprocess.PIPE).stdout.read().strip()
def find_all_usb_devices(self):
usb_devs = [ os.readlink(u)
--
1.7.1
next prev parent reply other threads:[~2012-05-14 8:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-14 8:07 [PATCH 0/2] replace os.system and os.popen with subbprocess module Robert Yang
2012-05-14 8:07 ` [PATCH 1/2] replace os.system with subprocess.call Robert Yang
2012-05-14 8:07 ` Robert Yang [this message]
2012-05-14 13:59 ` [PATCH 2/2] replace os.popen with subprocess.Popen Chris Larson
2012-05-15 6:49 ` Robert Yang
2012-05-15 9:53 [PATCH 0/2] V2 replace os.system and os.popen with subbprocess module Robert Yang
2012-05-15 9:53 ` [PATCH 2/2] replace os.popen with subprocess.Popen Robert Yang
2012-05-15 14:43 ` Chris Larson
2012-05-16 1:29 ` Robert Yang
2012-05-16 5:55 [PATCH 0/2] V3 replace os.system and os.popen with subbprocess module Robert Yang
2012-05-16 5:55 ` [PATCH 2/2] replace os.popen with subprocess.Popen Robert Yang
2012-05-16 9:35 ` GOPIKRISHNAN S
2012-05-16 14:14 ` Chris Larson
2012-05-17 1:59 ` Robert Yang
2012-05-20 12:36 [PATCH 0/2] V4 replace os.system and os.popen with subbprocess module Robert Yang
2012-05-20 12:36 ` [PATCH 2/2] replace os.popen with subprocess.Popen Robert Yang
2012-05-29 14:58 ` Wang, Shane
2012-05-29 15:17 ` Wang, Shane
2012-05-30 1:02 ` Robert Yang
2012-05-30 1:10 ` Wang, Shane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a072dd7795f44603322db6583ac748f0418684fd.1336974361.git.liezhi.yang@windriver.com \
--to=liezhi.yang@windriver.com \
--cc=Zhenfeng.Zhao@windriver.com \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.