[oe-commits] Jeremy Lainé : oestats-client.bbclass: support arbitrary URLs (Closes: #5283)

git version control git at git.openembedded.org
Wed Jul 22 05:48:44 UTC 2009


Module: openembedded.git
Branch: org.openembedded.dev
Commit: 4007d4d622a5b583403986a2e197cdf47b4bd816
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=4007d4d622a5b583403986a2e197cdf47b4bd816

Author: Jeremy Lainé <jeremy.laine at m4x.org>
Date:   Wed Jul 22 07:48:24 2009 +0200

oestats-client.bbclass: support arbitrary URLs (Closes: #5283)

---

 classes/oestats-client.bbclass |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/classes/oestats-client.bbclass b/classes/oestats-client.bbclass
index 8922496..e6b8485 100644
--- a/classes/oestats-client.bbclass
+++ b/classes/oestats-client.bbclass
@@ -5,8 +5,9 @@
 # To make use of this class, add to your local.conf:
 #
 # INHERIT += "oestats-client"
-# OESTATS_SERVER = "some.server.org"
+# OESTATS_SERVER = "http://some.server.org"
 # OESTATS_BUILDER = "some_nickname"
+# 
 
 def oestats_setid(d, val):
 	import bb
@@ -19,8 +20,8 @@ def oestats_getid(d):
 	return f.read()
 	
 def oestats_send(d, server, action, vars = {}, files = {}):
-	import httplib
 	import bb
+	import urllib2
 
 	# build body
 	output = []
@@ -49,21 +50,12 @@ def oestats_send(d, server, action, vars = {}, files = {}):
 		"Content-type": "multipart/form-data; boundary=%s" % bound,
 		"Content-length": str(len(body))}
 
-	# send request
-	proxy = bb.data.getVar('HTTP_PROXY', d, True )
-	if (proxy):
-		if (proxy.endswith('/')):
-			proxy = proxy[:-1]
-		if (proxy.startswith('http://')):
-			proxy = proxy[7:]
-		conn = httplib.HTTPConnection(proxy)
-		action = "http://%s%s" %(server, action)
-	else:
-		conn = httplib.HTTPConnection(server)
-	conn.request("POST", action, body, headers)
-	response = conn.getresponse()
+	# send request using urllib2, proxies should be auto-detected
+	actionURL = "%s%s" %(server, action)
+	req = urllib2.Request(actionURL, body, headers);
+	response = urllib2.urlopen(req)
 	data = response.read()
-	conn.close()
+	
 	return data
 
 def oestats_start(server, builder, d):
@@ -111,7 +103,7 @@ def oestats_stop(server, d, failures):
 			'status': status,
 		})
 		if status == 'Failed':
-			bb.note("oestats: build failed, see http://%s%s" % (server,response))
+			bb.note("oestats: build failed, see %s%s" % (server, response))
 	except:
 		bb.note("oestats: error stopping build")
 
@@ -169,7 +161,7 @@ def oestats_task(server, d, task, status):
 	try:
 		response = oestats_send(d, server, "/tasks/", vars, files)
 		if status == 'Failed':
-			bb.note("oestats: task failed, see http://%s%s" % (server, response))
+			bb.note("oestats: task failed, see %s%s" % (server, response))
 	except:
 		bb.note("oestats: error sending task, disabling stats")
 		oestats_setid(d, "")
@@ -184,6 +176,8 @@ python oestats_eventhandler () {
 		return NotHandled
 
 	server = bb.data.getVar('OESTATS_SERVER', e.data, True)
+	if not server.startswith('http://') and not server.startswith('https://'):
+		server = "http://%s" %(server)
 	builder = bb.data.getVar('OESTATS_BUILDER', e.data, True)
 	if not server or not builder:
 		return NotHandled





More information about the Openembedded-commits mailing list