All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Larson <clarson@kergoth.com>
To: Robert Yang <liezhi.yang@windriver.com>
Cc: bitbake-devel@lists.openembedded.org, Zhenfeng.Zhao@windriver.com
Subject: Re: [PATCH 2/2] replace os.popen with subprocess.Popen
Date: Wed, 16 May 2012 07:14:26 -0700	[thread overview]
Message-ID: <CABcZAN=Li=d73RueP18YRZSB-ExDMkW7EVw_gpF4j72Ch-j5Cg@mail.gmail.com> (raw)
In-Reply-To: <e22ec7981521df200e2db535630b666ce6d2731f.1337147194.git.liezhi.yang@windriver.com>

On Tue, May 15, 2012 at 10:55 PM, Robert Yang <liezhi.yang@windriver.com> wrote:
> 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.
>
> 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                 |    2 +-
>  bitbake/lib/bb/ui/crumbs/builddetailspage.py |    3 ++-
>  bitbake/lib/bb/ui/crumbs/hig.py              |    7 ++++---
>  4 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py
> index 6abf15d..e07afdd 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, errors) = bb.process.run("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
>         cset = p4file.readline().strip()

This is wrong, and will actually fail badly if you attempt to use
this. run() returns the values from Popen.communicate(), which returns
the data as strings, not pipes, so read() and readline() will not be
available on that object, and aren't needed. Also, the parens aren't
needed. "foo, bar =" is just as valid as "(foo, bar) =" (minor). This
should do it:

    output, errors = bb.process.run("%s%s changes -m 1 %s" % (p4cmd,
p4opt, depot))
    cset = output.strip()

> @@ -755,7 +756,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))
> +                    bb.process.run(args=shlex.split(cmdline))

This is wrong, and will fail. run() has no 'args' named argument. Try
not to get discouraged -- we do appreciate the work you're doing, but
checking this in would break bitbake for a great number of people. I'd
suggest actually testing bitbake with your changes before sending them
to the list. Thanks.
-- 
Christopher Larson



  parent reply	other threads:[~2012-05-16 14:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 1/2] replace os.system with subprocess.call 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 [this message]
2012-05-17  1:59     ` 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-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-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='CABcZAN=Li=d73RueP18YRZSB-ExDMkW7EVw_gpF4j72Ch-j5Cg@mail.gmail.com' \
    --to=clarson@kergoth.com \
    --cc=Zhenfeng.Zhao@windriver.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=liezhi.yang@windriver.com \
    /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.