forked from soundmud/soundrts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-game.py
155 lines (135 loc) · 4.73 KB
/
build-game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import compileall
from logging import *
import os
from os import mkdir, chdir, listdir, popen, popen2, popen3
from os.path import exists, join
import re
from shutil import *
import sys
SRC_DIR = os.getcwd()
TMP_DIR = os.environ["TMP"]
VERSION_TXT = open("version.txt").read().strip()
VERSION = re.search('VERSION = "([^"]+)"', open("soundrts/version.py").read()).group(1)
if VERSION != VERSION_TXT:
print "different versions: %s (version.txt) and %s (Python files)" % (VERSION_TXT, VERSION)
raw_input("[press ENTER to exit]")
sys.exit()
else:
print VERSION
def not_a_duplicate(dstname):
return not (dstname.endswith(".ogg") and
exists(re.sub(r"[/\\]res[/\\]ui[/\\]", "/res/ui-%s/" % p, dstname)))
def _d(path):
return os.path.join(TMP_DIR, "soundrts/build", path)
def my_mkdir(path):
if not exists(path):
os.makedirs(path)
def my_copy(src, ext, dest):
if src == "": src = "."
my_mkdir(dest)
for n in listdir(src):
if n.endswith(ext):
copy(join(src, n), dest)
def my_copytree(src, dest, no_duplicate=False):
if exists(dest):
rmtree(dest)
_copytree(src, dest, no_duplicate=no_duplicate)
def _copytree(src, dst, symlinks=False, no_duplicate=False):
names = os.listdir(src)
my_mkdir(dst)
errors = []
for name in names:
if name == ".svn":
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
_copytree(srcname, dstname, symlinks, no_duplicate)
elif not no_duplicate or not_a_duplicate(dstname):
copy2(srcname, dstname)
# XXX What about devices, sockets etc.?
except (IOError, os.error), why:
errors.append((srcname, dstname, why))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
errors.extend(err.args[0])
if errors:
raise Error, errors
def my_execute(cmd):
stdin, stdout, stderr = popen3(cmd)
while True:
s = stdout.readline()
if s:
print s.rstrip()
else:
break
while True:
s = stderr.readline()
if s:
print s.rstrip()
else:
break
print "updating list of maps..."
import buildmultimapslist
assert open("cfg/official_maps.txt").read()
my_copy("soundrts", ".py", _d("bin/soundrts"))
my_copy("soundrts/lib", ".py", _d("bin/soundrts/lib"))
copy("install/setup.py", _d("bin"))
copy("soundrts.py", _d("bin"))
copy("server.py", _d("bin"))
chdir(_d("bin"))
cmd = "c:\\python27\\python.exe setup.py -q py2exe"
# cmd = "c:\\python27\\python.exe -OO setup.py -q py2exe" # and add "optimize: 2" to setup.py
print "py2exe... (%s)" % cmd
my_execute(cmd)
os.remove("setup.py")
print "multiplatform version"
my_copy("", "soundrts.py", "multi")
my_copy("", "server.py", "multi")
my_copytree("soundrts", "multi/soundrts")
chdir("multi")
pythonver = 7
print "compiling all using 2.%s..." % pythonver
my_execute("c:\\python2%s\\python.exe -m compileall -ql soundrts soundrts/lib" % pythonver)
# remove the *.py source files
for base in ("soundrts", "soundrts/lib"):
for nf in os.listdir(base):
if nf[-3:] == ".py": # and nf not in ("soundrts.py", "server.py"):
os.remove(os.path.join(base, nf))
chdir(SRC_DIR)
copy("doc/readme.txt", _d("bin/multi"))
print "copying build_tts lib..."
my_copy("", ".dll", _d("bin/dist"))
for n in ("version.txt", "version-name.txt", "cfg/stage.txt",
"stage-name.txt",
"install/soundrts.iss", "install/ChineseSimp-12-5.1.11.isl"):
copy(n, _d(""))
try:
print "copying Windows version..."
my_copytree(_d("bin/dist"), _d("soundrts-%s-windows/" % (VERSION,)))
print "copying multiplatform version..."
multi = _d("soundrts-%s/" % (VERSION,))
my_copytree(_d("bin/multi"), multi)
print "copying data files..."
for dest in (_d("soundrts-%s-windows/" % (VERSION,)), multi):
print dest
my_mkdir(dest + "user")
my_copytree("res", dest + "res")
my_copytree("single", dest + "single")
my_copytree("multi", dest + "multi")
my_copy("res", ".txt", dest + "res")
my_copytree("mods", dest + "mods")
my_copytree("cfg", dest + "cfg")
open(dest + "cfg/language.txt", "w").write("")
my_copytree("mods", dest + "mods")
my_copy(_d("doc"), "", dest + "doc")
for e in [".php", ".txt"]:
my_copy("metaserver", e, dest + "metaserver")
except:
exception("error")
raw_input("[press ENTER to exit]")