diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2012-05-20 20:36:06 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-05-23 11:35:11 +0100 |
commit | 094742bed2fc01d55f572da946fcfa7a48521401 (patch) | |
tree | b85f26efa2cfd5a409681bcfc3a8758d085274fc /bitbake/lib | |
parent | 10a0f9ed929449543e5caab7e5f8855e0e68605b (diff) | |
download | poky-094742bed2fc01d55f572da946fcfa7a48521401.tar.gz |
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 is a bb.process.run() which will invoke the Popen to run command,
use it for simplify the code.
For the:
p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot))
...
for file in p4file:
list = file.split()
in bitbake/lib/bb/fetch2/perforce.py, it should be an error in the past,
since it didn't use readline() to read the pipe, but directly used the
split() for the pipe. Use the bb.process.run would fix the problem since
bb.process.run will return strings.
More info:
http://docs.python.org/library/subprocess.html#subprocess-replacements
[YOCTO #2075]
(Bitbake rev: 8d6700255a6d4dda403c89b171a6d4a1883e5aae)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/fetch2/perforce.py | 11 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/svk.py | 4 | ||||
-rwxr-xr-x | bitbake/lib/bb/ui/crumbs/builddetailspage.py | 5 | ||||
-rw-r--r-- | bitbake/lib/bb/ui/crumbs/hig.py | 7 |
4 files changed, 15 insertions, 12 deletions
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py index 6abf15d65a..df3a3a36db 100644 --- a/bitbake/lib/bb/fetch2/perforce.py +++ b/bitbake/lib/bb/fetch2/perforce.py | |||
@@ -91,8 +91,8 @@ class Perforce(FetchMethod): | |||
91 | 91 | ||
92 | p4cmd = data.getVar('FETCHCOMMAND_p4', d, True) | 92 | p4cmd = data.getVar('FETCHCOMMAND_p4', d, True) |
93 | logger.debug(1, "Running %s%s changes -m 1 %s", p4cmd, p4opt, depot) | 93 | logger.debug(1, "Running %s%s changes -m 1 %s", p4cmd, p4opt, depot) |
94 | p4file = os.popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot)) | 94 | p4file, errors = bb.process.run("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot)) |
95 | cset = p4file.readline().strip() | 95 | cset = p4file.strip() |
96 | logger.debug(1, "READ %s", cset) | 96 | logger.debug(1, "READ %s", cset) |
97 | if not cset: | 97 | if not cset: |
98 | return -1 | 98 | return -1 |
@@ -155,8 +155,8 @@ class Perforce(FetchMethod): | |||
155 | logger.debug(2, "Fetch: creating temporary directory") | 155 | logger.debug(2, "Fetch: creating temporary directory") |
156 | bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata)) | 156 | bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata)) |
157 | data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata) | 157 | data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata) |
158 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false") | 158 | tmpfile, errors = bb.process.run(data.getVar('MKTEMPDIRCMD', localdata, True) or "false") |
159 | tmpfile = tmppipe.readline().strip() | 159 | tmpfile = tmpfile.strip() |
160 | if not tmpfile: | 160 | if not tmpfile: |
161 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) | 161 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) |
162 | 162 | ||
@@ -169,7 +169,8 @@ class Perforce(FetchMethod): | |||
169 | os.chdir(tmpfile) | 169 | os.chdir(tmpfile) |
170 | logger.info("Fetch " + loc) | 170 | logger.info("Fetch " + loc) |
171 | logger.info("%s%s files %s", p4cmd, p4opt, depot) | 171 | logger.info("%s%s files %s", p4cmd, p4opt, depot) |
172 | p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot)) | 172 | p4file, errors = bb.process.run("%s%s files %s" % (p4cmd, p4opt, depot)) |
173 | p4file = p4file.strip() | ||
173 | 174 | ||
174 | if not p4file: | 175 | if not p4file: |
175 | raise FetchError("Fetch: unable to get the P4 files from %s" % depot, loc) | 176 | 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 9d34abf3da..ee3823f845 100644 --- a/bitbake/lib/bb/fetch2/svk.py +++ b/bitbake/lib/bb/fetch2/svk.py | |||
@@ -77,8 +77,8 @@ class Svk(FetchMethod): | |||
77 | logger.debug(2, "Fetch: creating temporary directory") | 77 | logger.debug(2, "Fetch: creating temporary directory") |
78 | bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata)) | 78 | bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata)) |
79 | data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata) | 79 | data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvk.XXXXXX', localdata), localdata) |
80 | tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, True) or "false") | 80 | tmpfile, errors = bb.process.run(data.getVar('MKTEMPDIRCMD', localdata, True) or "false") |
81 | tmpfile = tmppipe.readline().strip() | 81 | tmpfile = tmpfile.strip() |
82 | if not tmpfile: | 82 | if not tmpfile: |
83 | logger.error() | 83 | logger.error() |
84 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) | 84 | raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc) |
diff --git a/bitbake/lib/bb/ui/crumbs/builddetailspage.py b/bitbake/lib/bb/ui/crumbs/builddetailspage.py index 0052b017e5..0741a7ba73 100755 --- a/bitbake/lib/bb/ui/crumbs/builddetailspage.py +++ b/bitbake/lib/bb/ui/crumbs/builddetailspage.py | |||
@@ -23,6 +23,7 @@ | |||
23 | import gtk | 23 | import gtk |
24 | import pango | 24 | import pango |
25 | import gobject | 25 | import gobject |
26 | import bb.process | ||
26 | from bb.ui.crumbs.progressbar import HobProgressBar | 27 | from bb.ui.crumbs.progressbar import HobProgressBar |
27 | from bb.ui.crumbs.hobwidget import hic, HobNotebook, HobAltButton, HobWarpCellRendererText, HobButton | 28 | from bb.ui.crumbs.hobwidget import hic, HobNotebook, HobAltButton, HobWarpCellRendererText, HobButton |
28 | from bb.ui.crumbs.runningbuild import RunningBuildTreeView | 29 | from bb.ui.crumbs.runningbuild import RunningBuildTreeView |
@@ -97,9 +98,9 @@ class BuildConfigurationTreeView(gtk.TreeView): | |||
97 | for path in src_config_info.layers: | 98 | for path in src_config_info.layers: |
98 | import os, os.path | 99 | import os, os.path |
99 | if os.path.exists(path): | 100 | if os.path.exists(path): |
100 | f = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path) | 101 | f, errors = bb.process.run('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path) |
101 | if f: | 102 | if f: |
102 | branch = f.readline().lstrip('\n').rstrip('\n') | 103 | branch = f.strip('\n') |
103 | vars.append(self.set_vars("Branch:", branch)) | 104 | vars.append(self.set_vars("Branch:", branch)) |
104 | f.close() | 105 | f.close() |
105 | break | 106 | break |
diff --git a/bitbake/lib/bb/ui/crumbs/hig.py b/bitbake/lib/bb/ui/crumbs/hig.py index 1bc155d008..38f890b9f1 100644 --- a/bitbake/lib/bb/ui/crumbs/hig.py +++ b/bitbake/lib/bb/ui/crumbs/hig.py | |||
@@ -25,12 +25,12 @@ import gobject | |||
25 | import hashlib | 25 | import hashlib |
26 | import os | 26 | import os |
27 | import re | 27 | import re |
28 | import subprocess | ||
29 | import shlex | 28 | import shlex |
30 | from bb.ui.crumbs.hobcolor import HobColors | 29 | from bb.ui.crumbs.hobcolor import HobColors |
31 | from bb.ui.crumbs.hobwidget import hcc, hic, HobViewTable, HobInfoButton, HobButton, HobAltButton, HobIconChecker | 30 | from bb.ui.crumbs.hobwidget import hcc, hic, HobViewTable, HobInfoButton, HobButton, HobAltButton, HobIconChecker |
32 | from bb.ui.crumbs.progressbar import HobProgressBar | 31 | from bb.ui.crumbs.progressbar import HobProgressBar |
33 | import bb.ui.crumbs.utils | 32 | import bb.ui.crumbs.utils |
33 | import bb.process | ||
34 | 34 | ||
35 | """ | 35 | """ |
36 | The following are convenience classes for implementing GNOME HIG compliant | 36 | The following are convenience classes for implementing GNOME HIG compliant |
@@ -799,7 +799,8 @@ class DeployImageDialog (CrumbsDialog): | |||
799 | self.progress_bar.hide() | 799 | self.progress_bar.hide() |
800 | 800 | ||
801 | def popen_read(self, cmd): | 801 | def popen_read(self, cmd): |
802 | return os.popen("%s 2>/dev/null" % cmd).read().strip() | 802 | tmpout, errors = bb.process.run("%s" % cmd) |
803 | return tmpout.strip() | ||
803 | 804 | ||
804 | def find_all_usb_devices(self): | 805 | def find_all_usb_devices(self): |
805 | usb_devs = [ os.readlink(u) | 806 | usb_devs = [ os.readlink(u) |
@@ -828,7 +829,7 @@ class DeployImageDialog (CrumbsDialog): | |||
828 | cmdline = bb.ui.crumbs.utils.which_terminal() | 829 | cmdline = bb.ui.crumbs.utils.which_terminal() |
829 | if cmdline: | 830 | if cmdline: |
830 | cmdline += "\"sudo dd if=" + self.image_path + " of=" + combo_item + "\"" | 831 | cmdline += "\"sudo dd if=" + self.image_path + " of=" + combo_item + "\"" |
831 | subprocess.Popen(args=shlex.split(cmdline)) | 832 | bb.process.run(shlex.split(cmdline)) |
832 | 833 | ||
833 | def update_progress_bar(self, title, fraction, status=None): | 834 | def update_progress_bar(self, title, fraction, status=None): |
834 | self.progress_bar.update(fraction) | 835 | self.progress_bar.update(fraction) |