From patchwork Tue May 15 09:53:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel,1/2] replace os.system with subprocess.call Date: Tue, 15 May 2012 09:53:24 -0000 From: Robert Yang X-Patchwork-Id: 27765 Message-Id: <47b15ac83dad92bfc723a6d47e94454ab3c04134.1337073916.git.liezhi.yang@windriver.com> To: Cc: Zhenfeng.Zhao@windriver.com Replace os.system with subprocess.call 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 --- bitbake/lib/bb/fetch2/perforce.py | 3 ++- bitbake/lib/bb/shell.py | 6 +++--- bitbake/lib/bb/ui/crumbs/imagedetailspage.py | 3 ++- bitbake/lib/bb/ui/ncurses.py | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py index cbdc848..6abf15d 100644 --- a/bitbake/lib/bb/fetch2/perforce.py +++ b/bitbake/lib/bb/fetch2/perforce.py @@ -27,6 +27,7 @@ BitBake build tools. from future_builtins import zip import os +import subprocess import logging import bb from bb import data @@ -184,7 +185,7 @@ class Perforce(FetchMethod): dest = list[0][len(path)+1:] where = dest.find("#") - os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module, dest[:where], list[0])) + subprocess.call("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module, dest[:where], list[0]), shell=True) count = count + 1 if count == 0: diff --git a/bitbake/lib/bb/shell.py b/bitbake/lib/bb/shell.py index 1dd8d54..a83dedd 100644 --- a/bitbake/lib/bb/shell.py +++ b/bitbake/lib/bb/shell.py @@ -214,7 +214,7 @@ class BitBakeShellCommands: name = params[0] bbfile = self._findProvider( name ) if bbfile is not None: - os.system( "%s %s" % ( os.environ.get( "EDITOR", "vi" ), bbfile ) ) + subprocess.call( "%s %s" % ( os.environ.get( "EDITOR", "vi" ), bbfile ) , shell=True) else: print("ERROR: Nothing provides '%s'" % name) edit.usage = "" @@ -259,7 +259,7 @@ class BitBakeShellCommands: def fileEdit( self, params ): """Call $EDITOR on a .bb file""" name = params[0] - os.system( "%s %s" % ( os.environ.get( "EDITOR", "vi" ), completeFilePath( name ) ) ) + subprocess.call( "%s %s" % ( os.environ.get( "EDITOR", "vi" ), completeFilePath( name ) ) , shell=True) fileEdit.usage = "" def fileRebuild( self, params ): @@ -370,7 +370,7 @@ SRC_URI = "" #} """, file=newpackage) newpackage.close() - os.system( "%s %s/%s" % ( os.environ.get( "EDITOR" ), fulldirname, filename ) ) + subprocess.call( "%s %s/%s" % ( os.environ.get( "EDITOR" ), fulldirname, filename ) , shell=True) new.usage = " " def package( self, params ): diff --git a/bitbake/lib/bb/ui/crumbs/imagedetailspage.py b/bitbake/lib/bb/ui/crumbs/imagedetailspage.py index 1cfef80..2453dbc 100755 --- a/bitbake/lib/bb/ui/crumbs/imagedetailspage.py +++ b/bitbake/lib/bb/ui/crumbs/imagedetailspage.py @@ -25,6 +25,7 @@ import gtk from bb.ui.crumbs.hobcolor import HobColors from bb.ui.crumbs.hobwidget import hic, HobViewTable, HobAltButton, HobButton from bb.ui.crumbs.hobpages import HobPage +import subprocess # # ImageDetailsPage @@ -299,7 +300,7 @@ class ImageDetailsPage (HobPage): self.show_all() def view_files_clicked_cb(self, button, image_addr): - os.system("xdg-open /%s" % image_addr) + subprocess.call("xdg-open /%s" % image_addr, shell=True) def refresh_package_detail_box(self, image_size): self.package_detail.update_line_widgets("Total image size: ", image_size) diff --git a/bitbake/lib/bb/ui/ncurses.py b/bitbake/lib/bb/ui/ncurses.py index 8524446..1425bbd 100644 --- a/bitbake/lib/bb/ui/ncurses.py +++ b/bitbake/lib/bb/ui/ncurses.py @@ -47,7 +47,7 @@ from __future__ import division import logging -import os, sys, curses, itertools, time +import os, sys, curses, itertools, time, subprocess import bb import xmlrpclib from bb import ui @@ -286,7 +286,7 @@ class NCursesUI: # bb.error("log data follows (%s)" % logfile) # number_of_lines = data.getVar("BBINCLUDELOGS_LINES", d) # if number_of_lines: -# os.system('tail -n%s %s' % (number_of_lines, logfile)) +# subprocess.call('tail -n%s %s' % (number_of_lines, logfile), shell=True) # else: # f = open(logfile, "r") # while True: