source: 2011/26/build_games.py @ 2390

Revision 2390, 3.7 KB checked in by tekrjant, 12 years ago (diff)

Kellonajan formatointia.

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                formatted_time = time_of_update.strftime("%H:%M")
66                f.write(formatted_time+"\n")
67        counter += 1
68
69
70def build_games_in_personal_dir(personal_dir, time_of_update):
71        for root, dirs, files in os.walk(personal_dir):
72                if '.svn' in dirs:
73                        dirs.remove('.svn')
74                projects = glob(join(root, '*.csproj'))
75                if projects:
76                        if len(projects) > 1:
77                                print "NOTE: There is more than one project file in", root
78
79                        project_name = splitext(basename(projects[0]))[0]
80                        author = basename(personal_dir)
81
82                        success = build(projects[0])
83                        write_result(author, project_name, success, time_of_update)
84
85                        if success:
86                                dst_dir = join(output_dir, author)
87                                copy_game(project_name, root, dst_dir)
88                                print author + ": " + project_name
89                        else:
90                                projects_that_did_not_build.append(projects[0])
91
92
93def build(project_file_path):
94        build_cmd = msbuild + ' /nologo /verbosity:quiet /p:XnaProfile=Reach /p:Configuration=Release /p:"ReferencePath=%s" /t:Build "%s"' % (lib_dir_x86, project_file_path)
95        return call(build_cmd, shell=True) == 0
96
97
98def copy_game(project_name, project_dir, dst_dir):
99        bin = join(project_dir, "bin\\x86\\Release")
100        if not exists(bin):
101                print "NO BIN DIR FOUND IN", project_dir
102        dst = join(dst_dir, project_name)
103        if exists(dst):
104                rmtree(dst)
105        copytree(bin, dst, ignore=shutil.ignore_patterns('.svn', '*.pdb', 'jypeli4.xml'))
106
107
108
109def main():
110        try:
111                check_requirements()
112                create_output_directory()
113                create_build_result_directory()
114                build_games()
115        except KeyboardInterrupt:
116                print "BUILD CANCELLED"
117        except Exception, e:
118                print
119                print "NOT SUCCESSFUL:", e
120                return 1
121
122        print
123        print 'Projects that did not build (%d):' % len(projects_that_did_not_build)
124        for p in projects_that_did_not_build:
125                print p
126
127
128if __name__ == '__main__':
129        sys.exit(main())
Note: See TracBrowser for help on using the repository browser.