source: 2011/26/build_games.py @ 2387

Revision 2387, 3.6 KB checked in by tekrjant, 12 years ago (diff)

Toinen skripti joka tekee raportin, jotta voidaan päivittää tiheämmin.

Line 
1from __future__ import with_statement
2import sys
3import os
4from os.path import *
5import shutil
6from shutil import *
7from glob import *
8from subprocess import *
9from datetime import *
10
11
12output_dir = abspath("pelit")
13build_result_dir = abspath("build")
14lib_dir_x86 = abspath('lib\\x86')
15personal_dirs = [d for d in os.listdir(".") if isdir(d) and d not in ("lib", basename(output_dir), ".svn")]
16projects_that_did_not_build = []
17msbuild = "msbuild"
18
19
20
21def check_requirements():
22        global msbuild
23        if not exists("lib\\x86\\Jypeli4.dll"):
24                raise Exception("lib\\x86\\Jypeli4.dll expected")
25        return_code = call(msbuild + " /? 1> NUL 2> NUL", shell=True)
26        if return_code != 0:
27                msbuild = join(os.getenv("SystemRoot"), "Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe")
28                if not exists(msbuild):
29                        raise Exception("MSBuild not found in " + msbuild)
30
31
32def create_output_directory():
33        if not exists(output_dir):
34                os.mkdir(output_dir)
35        for d in personal_dirs:
36                if not exists(join(output_dir, d)):
37                        os.mkdir(join(output_dir, d))
38
39def create_build_result_directory():
40        if not exists(build_result_dir):
41                os.mkdir(build_result_dir)
42
43
44def build_games():
45        for d in personal_dirs:
46                path = abspath(d)
47                time_of_update = datetime.now()
48                if exists(join(path, ".svn")):
49                        call("svn update " + path, shell=True)
50                build_games_in_personal_dir(path, time_of_update)
51
52
53counter = 1
54
55
56def write_result(author, name, success, time_of_update):
57        global counter
58        with open(join(build_result_dir, str(counter)+".txt"), "w") as f:
59                f.write(author+"\n")
60                f.write(name+"\n")
61                result = "success"
62                if not success:
63                        result = "fail"
64                f.write(result+"\n")
65                f.write(str(time_of_update)+"\n")
66        counter += 1
67
68
69def build_games_in_personal_dir(personal_dir, time_of_update):
70        for root, dirs, files in os.walk(personal_dir):
71                if '.svn' in dirs:
72                        dirs.remove('.svn')
73                projects = glob(join(root, '*.csproj'))
74                if projects:
75                        if len(projects) > 1:
76                                print "NOTE: There is more than one project file in", root
77
78                        project_name = splitext(basename(projects[0]))[0]
79                        author = basename(personal_dir)
80
81                        success = build(projects[0])
82                        write_result(author, project_name, success, time_of_update)
83
84                        if success:
85                                dst_dir = join(output_dir, author)
86                                copy_game(project_name, root, dst_dir)
87                                print author + ": " + project_name
88                        else:
89                                projects_that_did_not_build.append(projects[0])
90
91
92def build(project_file_path):
93        build_cmd = msbuild + ' /nologo /verbosity:quiet /p:XnaProfile=Reach /p:Configuration=Release /p:"ReferencePath=%s" /t:Build "%s"' % (lib_dir_x86, project_file_path)
94        return call(build_cmd, shell=True) == 0
95
96
97def copy_game(project_name, project_dir, dst_dir):
98        bin = join(project_dir, "bin\\x86\\Release")
99        if not exists(bin):
100                print "NO BIN DIR FOUND IN", project_dir
101        dst = join(dst_dir, project_name)
102        if exists(dst):
103                rmtree(dst)
104        copytree(bin, dst, ignore=shutil.ignore_patterns('.svn', '*.pdb', 'jypeli4.xml'))
105
106
107
108def main():
109        try:
110                check_requirements()
111                create_output_directory()
112                create_build_result_directory()
113                build_games()
114        except KeyboardInterrupt:
115                print "BUILD CANCELLED"
116        except Exception, e:
117                print
118                print "NOT SUCCESSFUL:", e
119                return 1
120
121        print
122        print 'Projects that did not build (%d):' % len(projects_that_did_not_build)
123        for p in projects_that_did_not_build:
124                print p
125
126
127if __name__ == '__main__':
128        sys.exit(main())
Note: See TracBrowser for help on using the repository browser.