[oe] [PATCH] Kill some direct usages of 'print'

Chris Larson kergoth at gmail.com
Fri Nov 19 22:17:38 UTC 2010


From: Chris Larson <chris_larson at mentor.com>

Instead, use the bitbake messaging functions, to ensure the output goes to the
bitbake UI, rather than directly to stdout.

Signed-off-by: Chris Larson <chris_larson at mentor.com>
---
 classes/base.bbclass         |    2 +-
 classes/package_ipk.bbclass  |    7 ++-----
 classes/package_tar.bbclass  |    7 ++-----
 classes/seppuku.bbclass      |   28 +++++++++++-----------------
 classes/staging.bbclass      |    1 -
 classes/tinderclient.bbclass |    9 +--------
 6 files changed, 17 insertions(+), 37 deletions(-)

diff --git a/classes/base.bbclass b/classes/base.bbclass
index 308498f..c875006 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -241,7 +241,7 @@ python build_summary() {
 		statusvars = bb.data.getVar("BUILDCFG_VARS", e.data, 1).split()
 		statuslines = ["%-17s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
 		statusmsg = "\n%s\n%s\n" % (bb.data.getVar("BUILDCFG_HEADER", e.data, 1), "\n".join(statuslines))
-		print statusmsg
+		bb.msg.plain(statusmsg)
 
 		needed_vars = bb.data.getVar("BUILDCFG_NEEDEDVARS", e.data, 1).split()
 		pesteruser = []
diff --git a/classes/package_ipk.bbclass b/classes/package_ipk.bbclass
index 5d388da..eac7c82 100644
--- a/classes/package_ipk.bbclass
+++ b/classes/package_ipk.bbclass
@@ -28,11 +28,8 @@ python package_ipk_install () {
 	try:
 		bb.mkdirhier(rootfs)
 		os.chdir(rootfs)
-	except OSError:
-		import sys
-		(type, value, traceback) = sys.exc_info()
-		print value
-		raise bb.build.FuncFailed
+	except OSError, exc:
+		bb.fatal("Unable to mkdir and chdir to %s: %s" % (rootfs, exc))
 
 	# Generate ipk.conf if it or the stamp doesnt exist
 	conffile = os.path.join(stagingdir,"opkg.conf")
diff --git a/classes/package_tar.bbclass b/classes/package_tar.bbclass
index 4ba69c7..ddaf775 100644
--- a/classes/package_tar.bbclass
+++ b/classes/package_tar.bbclass
@@ -16,11 +16,8 @@ python package_tar_install () {
 	try:
 		bb.mkdirhier(rootfs)
 		os.chdir(rootfs)
-	except OSError:
-		import sys
-		(type, value, traceback) = sys.exc_info()
-		print value
-		raise bb.build.FuncFailed
+	except OSError, exc:
+		bb.fatal("Unable to mkdir and chdir to %s: %s" % (rootfs, exc))
 
 	if not os.access(pkgfn, os.R_OK):
 		bb.debug(1, "%s does not exist, skipping" % pkgfn)
diff --git a/classes/seppuku.bbclass b/classes/seppuku.bbclass
index 81e7ff6..70c0ec7 100644
--- a/classes/seppuku.bbclass
+++ b/classes/seppuku.bbclass
@@ -140,11 +140,9 @@ def seppuku_find_bug_report(debug_file, opener, query, product, component, bugna
     if len(scanner.result()) == 0:
         print >> debug_file, "Scanner failed to scan the html site"
         print >> debug_file, "%(query)sproduct=%(product)s&component=%(component)s&short_desc_type=substring&short_desc=%(bugname)s" % vars()
-        #print >> debug_file, txt
         return (False,None)
     else: # silently pick the first result
         print >> debug_file, "Result of bug search is "
-        #print >> debug_file, txt
         (number,status) = scanner.result()[0]
         return (not status in ["CLOS", "RESO", "VERI"],number)
 
@@ -172,11 +170,10 @@ def seppuku_reopen_bug(poster, file, product, component, bug_number, bugname, te
     try:
         result = poster.open( uri, param )
     except urllib2.HTTPError, e:
-        print e.geturl()
-        print e.info()
+        bb.error("Unable to reopen bug at %s: %s" % (e.geturl(), e.info()))
         return False
     except Exception, e:
-        print e
+        bb.error("Unable to reopen bug: %s" % e)
         return False
 
     if result.code != 200:
@@ -211,22 +208,21 @@ def seppuku_file_bug(poster, file, product, component, bugname, text):
     try:
         result = poster.open( uri, param )
     except urllib2.HTTPError, e:
-        print e.geturl()
-        print e.info()
+        bb.error("Unable to file bug at %s: %s" % (e.geturl(), e.info()))
         return False
     except Exception, e:
-        print e
+        bb.error("Unable to file bug: %s" % e)
         return False
 
     # scan the result for a bug number
-    # it will look like 
+    # it will look like
     # '<title>Bug 2742 Submitted</title>'
     import re
     res = re.findall(("\>Bug (?P<int>\d+) Submitted"), result.read() )
     if result.code != 200 or len(res) != 1:
-        return None 
+        return None
     else:
-        return res[0] 
+        return res[0]
 
 def seppuku_create_attachment(data, debug, poster, attach_query, product, component, bug_number, text, file):
     """
@@ -255,11 +251,9 @@ def seppuku_create_attachment(data, debug, poster, attach_query, product, compon
     try:
         result = poster.open( attach_query, param )
     except urllib2.HTTPError, e:
-        print e.geturl()
-        print e.info()
+        bb.error("Unable to open %s: %s" % (e.geturl(), e.info()))
         return False
     except Exception, e:
-        print e
         print >> debug, "Got exception in poster.open( attach_query, param )"
 	print >> debug, "attach_query: %s  param: %s" % (attach_query, param )
 	return False
@@ -269,7 +263,7 @@ def seppuku_create_attachment(data, debug, poster, attach_query, product, compon
         print >> debug, "Got bad return code (%s)" % result.code
         return False
     else:
-        print >> debug, "Got good return code (200)" 
+        print >> debug, "Got good return code (200)"
         return True
 
 
@@ -339,7 +333,7 @@ python seppuku_eventhandler() {
         if name == "TaskFailed":
             bugname = "%(package)s-%(pv)s-autobuild" % { "package" : bb.data.getVar("PN", data, True),
                                                                "pv"      : bb.data.getVar("PV", data, True),
-                                                               }  
+                                                               }
             log_file = glob.glob("%s/log.%s.*" % (bb.data.getVar('T', event.data, True), event.task))
             text     = "The %s step in %s failed at %s for machine %s" % (e.task, bb.data.getVar("PN", data, True), bb.data.getVar('DATETIME', data, True), bb.data.getVar( 'MACHINE', data, True ) )
             if len(log_file) != 0:
@@ -371,7 +365,7 @@ python seppuku_eventhandler() {
                 print >> debug_file, "Failed to reopen the bug #%s" % bug_number
             else:
                 print >> debug_file, "Reopened the bug #%s" % bug_number
-        else:	
+        else:
             bug_number = seppuku_file_bug(poster, newbug, product, component, bugname, text)
             if not bug_number:
                 print >> debug_file, "Couldn't acquire a new bug_numer, filing a bugreport failed"
diff --git a/classes/staging.bbclass b/classes/staging.bbclass
index 3e7adbb..e049aad 100644
--- a/classes/staging.bbclass
+++ b/classes/staging.bbclass
@@ -14,7 +14,6 @@ def package_stagefile(file, d):
     if bb.data.getVar('PSTAGING_ACTIVE', d, True) == "1":
         destfile = file.replace(bb.data.getVar("TMPDIR", d, 1), bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1))
         bb.mkdirhier(os.path.dirname(destfile))
-        #print "%s to %s" % (file, destfile)
         bb.copyfile(file, destfile)
 
 package_stagefile_shell() {
diff --git a/classes/tinderclient.bbclass b/classes/tinderclient.bbclass
index 7ccc1f2..16f1f52 100644
--- a/classes/tinderclient.bbclass
+++ b/classes/tinderclient.bbclass
@@ -19,11 +19,9 @@ def tinder_http_post(d, server, selector, content_type, body):
            h.endheaders()
            h.send(body)
            errcode, errmsg, headers = h.getreply()
-           #print errcode, errmsg, headers
            return (errcode,errmsg, headers, h.file)
        except Exception, e:
-           print "Error sending the report! ", e
-           # try again
+           bb.error("Unable to send the report: %s" % e)
            pass
 
     # return some garbage
@@ -120,11 +118,8 @@ def tinder_build_start(d):
 
     selector = url + "/xml/build_start.pl"
 
-    #print "selector %s and url %s" % (selector, url)
-
     # now post it
     errcode, errmsg, headers, h_file = tinder_http_post(d,server,selector,content_type, body)
-    #print errcode, errmsg, headers
     report = h_file.read()
 
     # now let us find the machine id that was assigned to us
@@ -159,8 +154,6 @@ def tinder_send_http(d, status, _log):
     while len(new_log) > 0:
         content_type, body = tinder_format_http_post(d,status,new_log[0:18000])
         errcode, errmsg, headers, h_file = tinder_http_post(d,server,selector,content_type, body)
-        #print errcode, errmsg, headers
-        #print h.file.read()
         new_log = new_log[18000:]
 
 
-- 
1.7.3.2.164.g6f10c





More information about the Openembedded-devel mailing list