]>
Commit | Line | Data |
---|---|---|
63319e0a AM |
1 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et |
2 | ||
3 | import path | |
4 | import os | |
5 | import shutil | |
6 | import time | |
7 | ||
8 | from config import config | |
9 | import util | |
10 | ||
11 | class Notify_Queue: | |
12 | def __init__(self): | |
13 | self.queue = None | |
14 | self.some_failed = 0 | |
15 | ||
16 | def init(self, g=None): | |
17 | self.queue = [] | |
18 | self.requester_email = g.requester_email | |
19 | self.notify_url = config.notify_url | |
e6376553 | 20 | |
63319e0a AM |
21 | def add(self, file): |
22 | id = util.uuid() | |
9be34149 | 23 | f = open(path.notify_queue_dir + '/' + id, 'w') |
63319e0a AM |
24 | f.write(file.read()) |
25 | f.close() | |
26 | self.queue.append({'id': id}) | |
27 | ||
28 | def flush(self): | |
29 | def desc(l): | |
30 | return """Target: %s | |
31 | Id: %s | |
32 | Builder: %s | |
33 | Time: %d | |
34 | Requester: %s | |
35 | END | |
36 | """ % (self.notify_url, l['id'], config.builder, time.time(), self.requester_email) | |
e6376553 | 37 | |
63319e0a | 38 | for l in self.queue: |
9be34149 | 39 | f = open(path.notify_queue_dir + '/' + l['id'] + ".desc", "w") |
63319e0a AM |
40 | f.write(desc(l)) |
41 | f.close() | |
42 | ||
43 | def kill(self): | |
44 | for l in self.queue: | |
9be34149 | 45 | os.unlink(path.notify_queue_dir + '/' + l) |
63319e0a AM |
46 | |
47 | queue = Notify_Queue() | |
48 | ||
49 | def add(notify): | |
50 | queue.add(notify) | |
51 | ||
52 | def flush(): | |
53 | queue.flush() | |
e6376553 | 54 | |
63319e0a AM |
55 | def kill(): |
56 | queue.kill() | |
57 | ||
58 | def init(r): | |
59 | queue.init(r) | |
60 | ||
61 | def status(): | |
62 | return queue.status | |
e6376553 | 63 | |
63319e0a AM |
64 | def clear_status(): |
65 | queue.status = "" |