summaryrefslogtreecommitdiffstats
path: root/openembedded/classes/tinderclient.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2005-08-31 10:45:47 +0000
committerRichard Purdie <richard@openedhand.com>2005-08-31 10:45:47 +0000
commit4b46c1f6e891b1ddd5968536440b888661fade3e (patch)
treee0ba2c1f56f61b868bf746da5c4feabb25b800b2 /openembedded/classes/tinderclient.bbclass
downloadpoky-4b46c1f6e891b1ddd5968536440b888661fade3e.tar.gz
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@1 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'openembedded/classes/tinderclient.bbclass')
-rw-r--r--openembedded/classes/tinderclient.bbclass158
1 files changed, 158 insertions, 0 deletions
diff --git a/openembedded/classes/tinderclient.bbclass b/openembedded/classes/tinderclient.bbclass
new file mode 100644
index 0000000000..290166bb03
--- /dev/null
+++ b/openembedded/classes/tinderclient.bbclass
@@ -0,0 +1,158 @@
1def tinder_tz_offset(off):
2 # get the offset.n minutes Either it is a number like
3 # +200 or -300
4 try:
5 return int(off)
6 except ValueError:
7 if off == "Europe/Berlin":
8 return 120
9 else:
10 return 0
11
12def tinder_tinder_time(offset):
13 import datetime
14 td = datetime.timedelta(minutes=tinder_tz_offset(offset))
15 time = datetime.datetime.utcnow() + td
16 return time.strftime('%m/%d/%Y %H:%M:%S')
17
18def tinder_tinder_start(date,offset):
19 import datetime, time
20 td = datetime.timedelta(minutes=tinder_tz_offset(offset))
21 ti = time.strptime(date, "%m/%d/%Y %H:%M:%S")
22 time = datetime.datetime(*ti[0:7])+td
23 return time.strftime('%m/%d/%Y %H:%M:%S')
24
25def tinder_send_email(da, header, log):
26 import smtplib
27 from bb import data
28 from email.MIMEText import MIMEText
29 msg = MIMEText(header +'\n' + log)
30 msg['Subject'] = data.getVar('TINDER_SUBJECT',da, True) or "Tinder-Client build log"
31 msg['To'] = data.getVar('TINDER_MAILTO' ,da, True)
32 msg['From'] = data.getVar('TINDER_FROM', da, True)
33
34
35 s = smtplib.SMTP()
36 s.connect()
37 s.sendmail(data.getVar('TINDER_FROM', da, True), [data.getVar('TINDER_MAILTO', da, True)], msg.as_string())
38 s.close()
39
40def tinder_send_http(da, header, log):
41 from bb import data
42 import httplib, urllib
43 cont = "\n%s\n%s" % ( header, log)
44 headers = {"Content-type": "multipart/form-data" }
45
46 conn = httplib.HTTPConnection(data.getVar('TINDER_HOST',da, True))
47 conn.request("POST", data.getVar('TINDER_URL',da,True), cont, headers)
48 conn.close()
49
50
51# Prepare tinderbox mail header
52def tinder_prepare_mail_header(da, status):
53 from bb import data
54
55 str = "tinderbox: administrator: %s\n" % data.getVar('TINDER_ADMIN', da, True)
56 str += "tinderbox: starttime: %s\n" % tinder_tinder_start(data.getVar('TINDER_START', da, True) or data.getVar('BUILDSTART', da, True), data.getVar('TINDER_TZ', da, True))
57 str += "tinderbox: buildname: %s\n" % data.getVar('TINDER_BUILD', da, True)
58 str += "tinderbox: errorparser: %s\n" % data.getVar('TINDER_ERROR', da, True)
59 str += "tinderbox: status: %s\n" % status
60 str += "tinderbox: timenow: %s\n" % tinder_tinder_time(data.getVar('TINDER_TZ', da, True))
61 str += "tinderbox: tree: %s\n" % data.getVar('TINDER_TREE', da, True)
62 str += "tinderbox: buildfamily: %s\n" % "unix"
63 str += "tinderbox: END"
64
65 return str
66
67def tinder_do_tinder_report(event):
68 """
69 Report to the tinderbox. Either we will report every step
70 (depending on TINDER_VERBOSE_REPORT) at the end we will send the
71 tinderclient.log
72 """
73 from bb.event import getName
74 from bb import data, mkdirhier
75 import os, glob
76
77 # variables
78 name = getName(event)
79 log = ""
80 header = ""
81 verbose = data.getVar('TINDER_VERBOSE_REPORT', event.data, True) == "1"
82
83 # Check what we need to do Build* shows we start or are done
84 if name == "BuildStarted":
85 header = tinder_prepare_mail_header(event.data, 'building')
86 # generate
87 for var in os.environ:
88 log += "%s=%s\n" % (var, os.environ[var])
89
90 mkdirhier(data.getVar('TMPDIR', event.data, True))
91 file = open(data.getVar('TINDER_LOG', event.data, True), 'w')
92 file.write(log)
93
94 if not verbose:
95 header = ""
96
97 if name == "PkgFailed" or name == "BuildCompleted":
98 status = 'build_failed'
99 if name == "BuildCompleted":
100 status = "success"
101 header = tinder_prepare_mail_header(event.data, status)
102 # append the log
103 log_file = data.getVar('TINDER_LOG', event.data, True)
104 file = open(log_file, 'r')
105 for line in file.readlines():
106 log += line
107
108 if verbose and name == "TaskStarted":
109 header = tinder_prepare_mail_header(event.data, 'building')
110 log = "Task %s started" % event.task
111
112 if verbose and name == "PkgStarted":
113 header = tinder_prepare_mail_header(event.data, 'building')
114 log = "Package %s started" % data.getVar('P', event.data, True)
115
116 if verbose and name == "PkgSucceeded":
117 header = tinder_prepare_mail_header(event.data, 'building')
118 log = "Package %s done" % data.getVar('P', event.data, True)
119
120 # Append the Task Log
121 if name == "TaskSucceeded" or name == "TaskFailed":
122 log_file = glob.glob("%s/log.%s.*" % (data.getVar('T', event.data, True), event.task))
123
124 if len(log_file) != 0:
125 to_file = data.getVar('TINDER_LOG', event.data, True)
126 log_txt = open(log_file[0], 'r').readlines()
127 to_file = open(to_file, 'a')
128
129 to_file.writelines(log_txt)
130
131 # append to the log
132 if verbose:
133 header = tinder_prepare_mail_header(event.data, 'building')
134 for line in log_txt:
135 log += line
136
137 # now mail the log
138 if len(log) == 0 or len(header) == 0:
139 return
140
141 log_post_method = tinder_send_email
142 if data.getVar('TINDER_SENDLOG', event.data, True) == "http":
143 log_post_method = tinder_send_http
144
145 log_post_method(event.data, header, log)
146
147
148addhandler tinderclient_eventhandler
149python tinderclient_eventhandler() {
150 from bb import note, error, data
151 from bb.event import NotHandled
152
153 do_tinder_report = data.getVar('TINDER_REPORT', e.data, True)
154 if do_tinder_report and do_tinder_report == "1":
155 tinder_do_tinder_report(e)
156
157 return NotHandled
158}