source: 2011/24/build_games.py @ 2250

Revision 2250, 3.8 KB checked in by tekrjant, 12 years ago (diff)

Build report is html.

Line 
1import sys
2import os
3from os.path import *
4import shutil
5from shutil import *
6from glob import *
7from subprocess import *
8from xml.dom.minidom import Document
9
10
11report_location = "\\\\eppu.it.jyu.fi\\kurssit\\npo\\temp"
12output_dir = abspath("pelit")
13lib_dir_x86 = abspath('lib\\x86')
14personal_dirs = [d for d in os.listdir(".") if isdir(d) and d not in ("lib", basename(output_dir), ".svn")]
15projects_that_did_not_build = []
16report = Document()
17table = ""
18
19def check_requirements():
20        if not exists("lib\\x86\\Jypeli4.dll"):
21                raise Exception("lib\\x86\\Jypeli4.dll expected")
22
23
24def create_output_directory():
25        if not exists(output_dir):
26                os.mkdir(output_dir)
27        for d in personal_dirs:
28                if not exists(join(output_dir, d)):
29                        os.mkdir(join(output_dir, d))
30
31def build_games():
32        for d in personal_dirs:
33                build_games_in_personal_dir(abspath(d))
34
35
36def addElement(parent, name):
37        node = report.createElement(name)
38        parent.appendChild(node)
39        return node
40
41
42def addTextElement(parent, name, value):
43        node = report.createElement(name)
44        parent.appendChild(node)
45        node.appendChild(report.createTextNode(str(value)))
46        return node
47
48
49def add_to_report(author, name, success):
50        style = "success"
51        if not success:
52                style = "fail"
53        tr = addElement(table, "tr")
54        tr.setAttribute("class", style)
55        addTextElement(tr, "td", author)
56        addTextElement(tr, "td", name)
57
58
59def build_games_in_personal_dir(personal_dir):
60        for root, dirs, files in os.walk(personal_dir):
61                if '.svn' in dirs:
62                        dirs.remove('.svn')
63                projects = glob(join(root, '*.csproj'))
64                if projects:
65                        if len(projects) > 1:
66                                print "NOTE: There is more than one project file in", root
67
68                        project_name = splitext(basename(projects[0]))[0]
69                        author = basename(personal_dir)
70
71                        success = build(projects[0])
72                        add_to_report(author, project_name, success)
73
74                        if success:
75                                dst_dir = join(output_dir, author)
76                                copy_game(project_name, root, dst_dir)
77                                print author + ": " + project_name
78                        else:
79                                projects_that_did_not_build.append(projects[0])
80
81
82def build(project_file_path):
83        build_cmd = 'msbuild /nologo /verbosity:quiet /p:XnaProfile=Reach /p:Configuration=Release /p:"ReferencePath={0}" /t:Build "{1}"'.format(lib_dir_x86, project_file_path)
84        return call(build_cmd, shell=True) == 0
85
86
87def copy_game(project_name, project_dir, dst_dir):
88        bin = join(project_dir, "bin\\x86\\Release")
89        if not exists(bin):
90                print "NO BIN DIR FOUND IN", project_dir
91        dst = join(dst_dir, project_name)
92        if exists(dst):
93                rmtree(dst)
94        copytree(bin, dst, ignore=shutil.ignore_patterns('.svn', '*.pdb', 'jypeli4.xml'))
95
96
97def initialize_report():
98        html = addElement(report, "html")
99
100        refresh_tag = addElement(html, "meta")
101        refresh_tag.setAttribute("http-equiv", "refresh")
102        refresh_tag.setAttribute("content", "30")
103
104        head = addElement(html, "head")
105        css_link = addElement(head, "link")
106        css_link.setAttribute("href", "build.css")
107        css_link.setAttribute("rel", "StyleSheet")
108        css_link.setAttribute("type", "text/css")
109        addTextElement(head, "title", "Build")
110
111        body = addElement(html, "body")
112        global table
113        table = addElement(body, "table")
114       
115
116def write_report():
117        with open(join(report_location, "build_report.html"), "w") as f:
118                f.write(report.toprettyxml())
119
120
121def main():
122        try:
123                initialize_report()
124                check_requirements()
125                create_output_directory()
126                build_games()
127                write_report()
128        except KeyboardInterrupt:
129                print "BUILD CANCELLED"
130        except Exception as e:
131                print
132                print "NOT SUCCESSFUL:", e
133                return 1
134
135        print
136        print 'Projects that did not build ({0}):'.format(len(projects_that_did_not_build))
137        for p in projects_that_did_not_build:
138                print p
139
140
141if __name__ == '__main__':
142        sys.exit(main())
Note: See TracBrowser for help on using the repository browser.