1 | """ |
---|
2 | Writes a html report of the build results. build_games.py |
---|
3 | should be run first. |
---|
4 | |
---|
5 | The report is written continuously. Hit Ctrl-c to stop. |
---|
6 | """ |
---|
7 | from __future__ import with_statement |
---|
8 | import sys |
---|
9 | import os |
---|
10 | from xml.dom.minidom import Document |
---|
11 | from os.path import * |
---|
12 | import shutil |
---|
13 | from shutil import * |
---|
14 | from glob import * |
---|
15 | from subprocess import * |
---|
16 | from datetime import * |
---|
17 | import time |
---|
18 | |
---|
19 | |
---|
20 | report_location = "\\\\eppu.it.jyu.fi\\kurssit\\npo\\temp" |
---|
21 | report = None |
---|
22 | table = None |
---|
23 | |
---|
24 | |
---|
25 | CSS = """ |
---|
26 | tr { |
---|
27 | color: white; |
---|
28 | } |
---|
29 | |
---|
30 | .success { |
---|
31 | background-color: green; |
---|
32 | } |
---|
33 | |
---|
34 | .fail { |
---|
35 | background-color: red; |
---|
36 | } |
---|
37 | """ |
---|
38 | |
---|
39 | |
---|
40 | def check_requirements(): |
---|
41 | if not exists("build"): |
---|
42 | raise Exception("Directory build not found. Run build_games.py first!") |
---|
43 | |
---|
44 | def addElement(parent, name): |
---|
45 | node = report.createElement(name) |
---|
46 | parent.appendChild(node) |
---|
47 | return node |
---|
48 | |
---|
49 | |
---|
50 | def addTextElement(parent, name, value): |
---|
51 | node = report.createElement(name) |
---|
52 | parent.appendChild(node) |
---|
53 | node.appendChild(report.createTextNode(str(value))) |
---|
54 | return node |
---|
55 | |
---|
56 | |
---|
57 | def initialize_report(): |
---|
58 | global report |
---|
59 | |
---|
60 | report = Document() |
---|
61 | html = addElement(report, "html") |
---|
62 | |
---|
63 | refresh_tag = addElement(html, "meta") |
---|
64 | refresh_tag.setAttribute("http-equiv", "refresh") |
---|
65 | refresh_tag.setAttribute("content", "30") |
---|
66 | |
---|
67 | head = addElement(html, "head") |
---|
68 | style = addTextElement(head, "style", CSS) |
---|
69 | style.setAttribute("type", "text/css") |
---|
70 | addTextElement(head, "title", "Build") |
---|
71 | |
---|
72 | body = addElement(html, "body") |
---|
73 | global table |
---|
74 | table = addElement(body, "table") |
---|
75 | |
---|
76 | |
---|
77 | def write_results(): |
---|
78 | for d in os.listdir("build"): |
---|
79 | with open(join("build", d), "r") as f: |
---|
80 | lines = f.readlines() |
---|
81 | author = lines[0].strip() |
---|
82 | name = lines[1].strip() |
---|
83 | result = lines[2].strip() |
---|
84 | time_of_update = lines[3].strip() |
---|
85 | |
---|
86 | success = (result == "success") |
---|
87 | |
---|
88 | style = "success" |
---|
89 | if not success: |
---|
90 | style = "fail" |
---|
91 | tr = addElement(table, "tr") |
---|
92 | tr.setAttribute("class", style) |
---|
93 | addTextElement(tr, "td", author) |
---|
94 | addTextElement(tr, "td", name) |
---|
95 | addTextElement(tr, "td", time_of_update) |
---|
96 | |
---|
97 | |
---|
98 | def write_report(): |
---|
99 | with open(join(report_location, "build_report.html"), "w") as f: |
---|
100 | f.write(report.toprettyxml()) |
---|
101 | |
---|
102 | |
---|
103 | def main(): |
---|
104 | try: |
---|
105 | while True: |
---|
106 | check_requirements() |
---|
107 | initialize_report() |
---|
108 | write_results() |
---|
109 | write_report() |
---|
110 | print "report written" |
---|
111 | time.sleep(10) |
---|
112 | except KeyboardInterrupt: |
---|
113 | print "cancelled" |
---|
114 | except Exception, e: |
---|
115 | print |
---|
116 | print "NOT SUCCESSFUL:", e |
---|
117 | return 1 |
---|
118 | |
---|
119 | |
---|
120 | if __name__ == '__main__': |
---|
121 | sys.exit(main()) |
---|
122 | |
---|