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: Tue, 15 May 2012 17:53:25 +0800 [thread overview]
Message-ID: <6ca7f7e56bdab86c3920182256220077a94fe78d.1337073916.git.liezhi.yang@windriver.com> (raw)
In-Reply-To: <cover.1337073916.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
There is a wrappers around Popen for convenience in the bb.process python
module, so use the Popen from bb.process to simplify the code.
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 | 7 ++++---
bitbake/lib/bb/fetch2/svk.py | 3 ++-
bitbake/lib/bb/ui/crumbs/builddetailspage.py | 3 ++-
bitbake/lib/bb/ui/crumbs/hig.py | 6 +++---
4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py
index 6abf15d..1c4ef25 100644
--- a/bitbake/lib/bb/fetch2/perforce.py
+++ b/bitbake/lib/bb/fetch2/perforce.py
@@ -35,6 +35,7 @@ from bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError
from bb.fetch2 import logger
from bb.fetch2 import runfetchcmd
+from bb.process import Popen
class Perforce(FetchMethod):
def supports(self, url, ud, d):
@@ -91,7 +92,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 = Popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot)).stdout
cset = p4file.readline().strip()
logger.debug(1, "READ %s", cset)
if not cset:
@@ -155,7 +156,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 = Popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false").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 +170,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 = Popen("%s%s files %s" % (p4cmd, p4opt, depot)).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..43d30a3 100644
--- a/bitbake/lib/bb/fetch2/svk.py
+++ b/bitbake/lib/bb/fetch2/svk.py
@@ -34,6 +34,7 @@ from bb.fetch2 import FetchError
from bb.fetch2 import MissingParameterError
from bb.fetch2 import logger
from bb.fetch2 import runfetchcmd
+from bb.process import Popen
class Svk(FetchMethod):
"""Class to fetch a module or modules from svk repositories"""
@@ -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 = Popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false").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..8387161 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
+from bb.process import Popen
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 = Popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).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..d4fcb55 100644
--- a/bitbake/lib/bb/ui/crumbs/hig.py
+++ b/bitbake/lib/bb/ui/crumbs/hig.py
@@ -25,11 +25,11 @@ import gobject
import hashlib
import os
import re
-import subprocess
import shlex
from bb.ui.crumbs.hobcolor import HobColors
from bb.ui.crumbs.hobwidget import hcc, hic, HobViewTable, HobInfoButton, HobButton, HobAltButton, HobIconChecker
from bb.ui.crumbs.progressbar import HobProgressBar
+from bb.process import Popen
import bb.ui.crumbs.utils
"""
@@ -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 Popen("%s" % cmd).stdout.read().strip()
def find_all_usb_devices(self):
usb_devs = [ os.readlink(u)
@@ -755,7 +755,7 @@ class DeployImageDialog (CrumbsDialog):
cmdline = bb.ui.crumbs.utils.which_terminal()
if cmdline:
cmdline += "\"sudo dd if=" + self.image_path + " of=" + combo_item + "\""
- subprocess.Popen(args=shlex.split(cmdline))
+ Popen(args=shlex.split(cmdline))
def update_progress_bar(self, title, fraction, status=None):
self.progress_bar.update(fraction)
--
1.7.1
next prev parent reply other threads:[~2012-05-15 10:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
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 1/2] replace os.system with subprocess.call Robert Yang
2012-05-15 9:53 ` Robert Yang [this message]
2012-05-15 14:43 ` [PATCH 2/2] replace os.popen with subprocess.Popen Chris Larson
2012-05-16 1:29 ` Robert Yang
-- strict thread matches above, loose matches on Subject: below --
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
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-14 8:07 [PATCH 0/2] replace os.system and os.popen with subbprocess module Robert Yang
2012-05-14 8:07 ` [PATCH 2/2] replace os.popen with subprocess.Popen Robert Yang
2012-05-14 13:59 ` Chris Larson
2012-05-15 6:49 ` Robert Yang
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=6ca7f7e56bdab86c3920182256220077a94fe78d.1337073916.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.