build-game.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #! python2.7
  2. import compileall
  3. from logging import *
  4. import os
  5. from os import mkdir, chdir, listdir, popen, popen2, popen3
  6. from os.path import exists, join
  7. import re
  8. from shutil import *
  9. import sys
  10. SRC_DIR = os.getcwd()
  11. TMP_DIR = os.environ["TMP"]
  12. VERSION_TXT = open("version.txt").read().strip()
  13. VERSION = re.search('VERSION = "([^"]+)"', open("soundrts/version.py").read()).group(1)
  14. if VERSION != VERSION_TXT:
  15. print "different versions: %s (version.txt) and %s (Python files)" % (VERSION_TXT, VERSION)
  16. raw_input("[press ENTER to exit]")
  17. sys.exit()
  18. else:
  19. print VERSION
  20. def not_a_duplicate(dstname):
  21. return not (dstname.endswith(".ogg") and
  22. exists(re.sub(r"[/\\]res[/\\]ui[/\\]", "/res/ui-%s/" % p, dstname)))
  23. def _d(path):
  24. return os.path.join(TMP_DIR, "soundrts/build", path)
  25. def my_mkdir(path):
  26. if not exists(path):
  27. os.makedirs(path)
  28. def my_copy(src, ext, dest):
  29. if src == "": src = "."
  30. my_mkdir(dest)
  31. for n in listdir(src):
  32. if n.endswith(ext):
  33. copy(join(src, n), dest)
  34. def my_copytree(src, dest, *args, **kwargs):
  35. if exists(dest):
  36. rmtree(dest)
  37. copytree(src, dest, *args, **kwargs)
  38. def my_execute(cmd):
  39. stdin, stdout, stderr = popen3(cmd)
  40. while True:
  41. s = stdout.readline()
  42. if s:
  43. print s.rstrip()
  44. else:
  45. break
  46. while True:
  47. s = stderr.readline()
  48. if s:
  49. print s.rstrip()
  50. else:
  51. break
  52. print "updating list of maps..."
  53. import buildmultimapslist
  54. assert open("cfg/official_maps.txt").read()
  55. my_copytree("soundrts", _d("bin/soundrts"),
  56. ignore=ignore_patterns("tests", "*.pyc"))
  57. copy("install/setup.py", _d("bin"))
  58. copy("soundrts.py", _d("bin"))
  59. copy("server.py", _d("bin"))
  60. chdir(_d("bin"))
  61. cmd = "c:\\python27\\python.exe setup.py -q py2exe"
  62. # cmd = "c:\\python27\\python.exe -OO setup.py -q py2exe" # and add "optimize: 2" to setup.py
  63. print "py2exe... (%s)" % cmd
  64. my_execute(cmd)
  65. os.remove("setup.py")
  66. print "multiplatform version"
  67. my_copy("", "soundrts.py", "multi")
  68. my_copy("", "server.py", "multi")
  69. my_copytree("soundrts", "multi/soundrts")
  70. chdir("multi")
  71. pythonver = 7
  72. print "compiling all using 2.%s..." % pythonver
  73. my_execute("c:\\python2%s\\python.exe -m compileall -q soundrts" % pythonver)
  74. # remove the *.py source files
  75. for dirpath, dirnames, filenames in os.walk("soundrts"):
  76. for name in filenames:
  77. if name.endswith(".py"):
  78. os.remove(os.path.join(dirpath, name))
  79. chdir(SRC_DIR)
  80. copy("doc/multiplatform/readme.txt", _d("bin/multi"))
  81. print "copying build_tts lib..."
  82. my_copy("", ".dll", _d("bin/dist"))
  83. for n in ("version.txt", "version-name.txt", "cfg/stage.txt",
  84. "stage-name.txt",
  85. "install/soundrts.iss", "install/ChineseSimp-12-5.1.11.isl"):
  86. copy(n, _d(""))
  87. try:
  88. print "copying Windows version..."
  89. my_copytree(_d("bin/dist"), _d("soundrts-%s-windows/" % (VERSION,)))
  90. print "copying multiplatform version..."
  91. multi = _d("soundrts-%s/" % (VERSION,))
  92. my_copytree(_d("bin/multi"), multi)
  93. print "copying data files..."
  94. for dest in (_d("soundrts-%s-windows/" % (VERSION,)), multi):
  95. print dest
  96. my_mkdir(dest + "user")
  97. my_copytree("res", dest + "res")
  98. my_copytree("single", dest + "single")
  99. my_copytree("multi", dest + "multi")
  100. my_copy("res", ".txt", dest + "res")
  101. my_copytree("mods", dest + "mods")
  102. my_copytree("cfg", dest + "cfg")
  103. open(dest + "cfg/language.txt", "w").write("")
  104. my_copytree("mods", dest + "mods")
  105. my_copytree(_d("doc"), dest + "doc")
  106. for e in [".php", ".txt"]:
  107. my_copy("metaserver", e, dest + "metaserver")
  108. except:
  109. exception("error")
  110. raw_input("[press ENTER to exit]")