[poky] [PATCH 1/1] kernel.py: replace os.popen with subprocess.Popen

Martin Jansa martin.jansa at gmail.com
Fri Jun 8 08:14:48 PDT 2012


On Fri, Jun 08, 2012 at 08:08:59AM -0700, Darren Hart wrote:
> 
> 
> On 06/01/2012 01:51 AM, Robert Yang wrote:
> > 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 #2454]
> > 
> > Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
> > ---
> >  scripts/lib/bsp/kernel.py |    5 +++--
> >  1 files changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/scripts/lib/bsp/kernel.py b/scripts/lib/bsp/kernel.py
> > index 8b3aa72..7c6da4e 100644
> > --- a/scripts/lib/bsp/kernel.py
> > +++ b/scripts/lib/bsp/kernel.py
> > @@ -31,6 +31,7 @@ import os
> >  import shutil
> >  from tags import *
> >  import glob
> > +import subprocess
> >  
> >  
> >  def find_bblayers(scripts_path):
> > @@ -678,7 +679,7 @@ def base_branches(context):
> >      print "Getting branches from remote repo %s..." % giturl
> >  
> >      gitcmd = "git ls-remote %s *heads* 2>&1" % (giturl)
> > -    tmp = os.popen(gitcmd).read()
> > +    tmp = subprocess.Popen(gitcmd, shell=True, stdout=subprocess.PIPE).stdout.read()
> 
> Subprocess is right module to use here, but I believe the recommended
> method would be:
> 
> subprocess.call(gitcmd...
> 
> According to:
> http://docs.python.org/library/subprocess.html
> 
> >  
> >      branches = []
> >  
> > @@ -708,7 +709,7 @@ def all_branches(context):
> >      print "Getting branches from remote repo %s..." % giturl
> >  
> >      gitcmd = "git ls-remote %s *heads* 2>&1" % (giturl)
> > -    tmp = os.popen(gitcmd).read()
> > +    tmp = subprocess.Popen(gitcmd, shell=True, stdout=subprocess.PIPE).stdout.read()
> >  
> >      branches = []
> >  
> 
> And here I think subprocess.check_output(...) is preferred.

That's only in python 2.7 and newer, are distros with python-2.6
unsupported now?

I did the same mistake in opkg-utils (patch for it is on yocto ML).
https://lists.yoctoproject.org/pipermail/yocto/2012-May/009182.html

Cheers,

-- 
Martin 'JaMa' Jansa     jabber: Martin.Jansa at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.yoctoproject.org/pipermail/poky/attachments/20120608/01926970/attachment.pgp>


More information about the poky mailing list