summaryrefslogtreecommitdiff
path: root/classes/oestats-client.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'classes/oestats-client.bbclass')
-rw-r--r--classes/oestats-client.bbclass88
1 files changed, 63 insertions, 25 deletions
diff --git a/classes/oestats-client.bbclass b/classes/oestats-client.bbclass
index b98177d40a..880f02e62d 100644
--- a/classes/oestats-client.bbclass
+++ b/classes/oestats-client.bbclass
@@ -19,31 +19,58 @@ def oestats_getid(d):
return f.read()
def oestats_send(server, action, vars = {}):
- import httplib, urllib
-
- params = urllib.urlencode(vars)
- headers = {"Content-type": "application/x-www-form-urlencoded",
- "Accept": "text/plain"}
+ import httplib
+
+ # build body
+ 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])
+ output.append('--' + bound + '--')
+ output.append('')
+ body = "\r\n".join(output)
+
+ # build headers
+ headers = {
+ "User-agent": "oestats-client/0.1",
+ "Content-type": "multipart/form-data; boundary=%s" % bound,
+ "Content-length": str(len(body))}
+
+ # send request
conn = httplib.HTTPConnection(server)
- conn.request("POST", action, params, headers)
+ conn.request("POST", action, body, headers)
response = conn.getresponse()
+ data = response.read()
conn.close()
- return response
+ return data
def oestats_start(server, builder, d):
import bb
import os.path
+ import re
# send report
- response = oestats_send(server, "/builds/start/", {
- 'builder': builder,
- 'revision': bb.data.getVar('METADATA_REVISION', d, True),
- 'machine': bb.data.getVar('MACHINE', d, True),
- 'distro': bb.data.getVar('DISTRO', d, True),
- })
- id = response.read()
+ id = ""
+ try:
+ data = oestats_send(server, "/builds/start/", {
+ 'builder': builder,
+ 'revision': bb.data.getVar('METADATA_REVISION', d, True),
+ 'machine': bb.data.getVar('MACHINE', d, True),
+ 'distro': bb.data.getVar('DISTRO', d, True),
+ })
+ if re.match("^\d+$", data): id=data
+ except:
+ pass
# save the build id
+ if id:
+ bb.note("oestats: build %s" % id)
+ else:
+ bb.note("oestats: error starting build, disabling stats")
oestats_setid(d, id)
def oestats_stop(server, d, status):
@@ -51,11 +78,15 @@ def oestats_stop(server, d, status):
# retrieve build id
id = oestats_getid(d)
+ if not id: return
# send report
- response = oestats_send(server, "/builds/stop/%s/" % id, {
- 'status': status,
- })
+ try:
+ response = oestats_send(server, "/builds/stop/%s/" % id, {
+ 'status': status,
+ })
+ except:
+ bb.note("oestats: error stopping build")
def oestats_task(server, d, task, status):
import bb
@@ -63,20 +94,27 @@ def oestats_task(server, d, task, status):
# retrieve build id
id = oestats_getid(d)
+ if not id: return
+
+ # calculate build time
try:
elapsed = time.time() - float(bb.data.getVar('OESTATS_STAMP', d, True))
except:
elapsed = 0
# send report
- response = oestats_send(server, "/builds/task/%s/" % id, {
- 'package': bb.data.getVar('PN', d, True),
- 'version': bb.data.getVar('PV', d, True),
- 'revision': bb.data.getVar('PR', d, True),
- 'task': task,
- 'status': status,
- 'time': elapsed,
- })
+ try:
+ response = oestats_send(server, "/builds/task/%s/" % id, {
+ 'package': bb.data.getVar('PN', d, True),
+ 'version': bb.data.getVar('PV', d, True),
+ 'revision': bb.data.getVar('PR', d, True),
+ 'task': task,
+ 'status': status,
+ 'time': str(elapsed),
+ })
+ except:
+ bb.note("oestats: error sending task, disabling stats")
+ oestats_setid(d, "")
addhandler oestats_eventhandler
python oestats_eventhandler () {