[oe-commits] Yuri Bushmelev : oestats-client.bbclass: Fix oestats-client

git version control git at git.openembedded.org
Sun Feb 6 19:51:09 UTC 2011


Module: openembedded.git
Branch: master
Commit: da89a83b1d7781ed0baf7fa4d8f6c8382836fe79
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=da89a83b1d7781ed0baf7fa4d8f6c8382836fe79

Author: Yuri Bushmelev <jay4mail at gmail.com>
Date:   Sun Feb  6 01:25:18 2011 +0300

oestats-client.bbclass: Fix oestats-client

* Relax empty data checking (replace asserts)
* Replace direct path manipulations with os.path.join
* Replace bb.note() with bb.warn() where appropriate
* Improve diagnostic messages

---

 classes/oestats-client.bbclass |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/classes/oestats-client.bbclass b/classes/oestats-client.bbclass
index f64d21f..9302b29 100644
--- a/classes/oestats-client.bbclass
+++ b/classes/oestats-client.bbclass
@@ -11,7 +11,8 @@
 
 def oestats_setid(d, val):
 	import bb
-	f = file(bb.data.getVar('TMPDIR', d, True) + '/oestats.id', 'w')
+	import os
+	f = open(os.path.join(bb.data.getVar('TMPDIR', d, True), 'oestats.id'), 'w')
 	f.write(val)
 
 def oestats_getid(d):
@@ -19,6 +20,11 @@ def oestats_getid(d):
 	f = file(bb.data.getVar('TMPDIR', d, True) + '/oestats.id', 'r')
 	return f.read()
 	
+def get_exc_info():
+	import sys
+	exctype, value = sys.exc_info()[:2]
+	return "exception " + str(exctype) + ", value " + str(value)
+
 def oestats_send(d, server, action, vars = {}, files = {}):
 	import bb
 	import urllib2
@@ -27,13 +33,12 @@ def oestats_send(d, server, action, vars = {}, files = {}):
 	output = []
 	bound = '----------ThIs_Is_tHe_bouNdaRY_$'
 	for key in vars:
-		assert vars[key]
 		output.append('--' + bound)
 		output.append('Content-Disposition: form-data; name="%s"' % key)
 		output.append('')
 		output.append(vars[key])
 	for key in files:
-		assert files[key]
+		if not vars[key]: continue
 		output.append('--' + bound)
 		output.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, files[key]['filename']))
 		output.append('Content-Type: %s' % files[key]['content-type'])
@@ -81,13 +86,14 @@ def oestats_start(server, builder, d):
 		})
 		if re.match("^\d+$", data): id=data
 	except:
+		bb.warn("oestats: %s" % get_exc_info())
 		pass
 
 	# save the build id
 	if id:
 		bb.note("oestats: build %s" % id)
 	else:
-		bb.note("oestats: error starting build, disabling stats")
+		bb.warn("oestats: error starting build, disabling stats")
 	oestats_setid(d, id)
 
 def oestats_stop(server, d, failures):
@@ -108,9 +114,9 @@ def oestats_stop(server, d, failures):
 			'status': status,
 		})
 		if status == 'Failed':
-			bb.note("oestats: build failed, see %s%s" % (server, response))
+			bb.warn("oestats: build failed, see %s%s" % (server, response))
 	except:
-		bb.note("oestats: error stopping build")
+		bb.warn("oestats: error stopping build (%s)" % get_exc_info())
 
 def oestats_task(server, d, task, status):
 	import bb
@@ -132,7 +138,7 @@ def oestats_task(server, d, task, status):
 	files = {}
 	if status == 'Failed':
 		logs = glob.glob("%s/log.%s.*" % (bb.data.getVar('T', d, True), task))
-        	if len(logs) > 0:
+		if len(logs) > 0:
 			log = logs[0]
 			files['log'] = {
 				'filename': 'log.txt',
@@ -163,12 +169,13 @@ def oestats_task(server, d, task, status):
 		vars['bug_tracker'] = bug_tracker
 
 	# send report
+	# FIXME: resend on http/url error?
 	try:
 		response = oestats_send(d, server, "/tasks/", vars, files)
 		if status == 'Failed':
-			bb.note("oestats: task failed, see %s%s" % (server, response))
+			bb.warn("oestats: task failed, see %s%s" % (server, response))
 	except:
-		bb.note("oestats: error sending task, disabling stats")
+		bb.warn("oestats: error sending task (%s), disabling stats" % get_exc_info())
 		oestats_setid(d, "")
 
 addhandler oestats_eventhandler





More information about the Openembedded-commits mailing list