create-archive.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/usr/bin/env python
  2. import glob
  3. import optparse
  4. import os
  5. import platform
  6. import re
  7. import shutil
  8. import string
  9. import sys
  10. import tempfile
  11. import types
  12. import pdb
  13. ## CONSTANTS
  14. scriptDir = os.path.join(sys.path[0])
  15. rootDir = os.path.abspath(os.path.join(scriptDir, "..", ".."))
  16. contribDir = os.path.join("contrib", "src")
  17. dirsToCopy = ["art", "build", "demos", "distrib/mac", "docs", "include", "interface", "lib",
  18. "locale", "samples", "src", "tests", "utils"]
  19. dirsToIgnore = [".svn", "CVS"]
  20. excludeExtensions = [".rej", ".orig", ".mine", ".tmp"]
  21. option_dict = {
  22. "compression" : ("gzip", "Compression to use. Values are: gzip, bzip, zip, all (default: gzip)"),
  23. "docs" : ("html", "Doc formats to build. Comma separated. Values are: none, html (default: html)"),
  24. "name" : ("wxWidgets", "Name given to the tarball created (default: wxWidgets)"),
  25. "postfix" : ("", "String appended to the version to indicate a special release (default: none)"),
  26. "wxpython" : (False, "Produce wxPython source tarball (name defaults to wxPython-src)")
  27. }
  28. mswProjectFiles = [ ".vcproj", ".sln", ".dsp", ".dsw", ".vc", ".bat"]
  29. nativeLineEndingFiles = [".cpp", ".h", ".c", ".txt"]
  30. ## PARSE OPTIONS
  31. usage="""usage: %prog [options] <output directory>\n
  32. Create a wxWidgets archive and store it in <output directory>.
  33. The output directory must be an absolute, existing path.
  34. Type %prog --help for options.
  35. """
  36. parser = optparse.OptionParser(usage, version="%prog 1.0")
  37. for opt in option_dict:
  38. default = option_dict[opt][0]
  39. action = "store"
  40. if type(default) == types.BooleanType:
  41. action = "store_true"
  42. parser.add_option("--" + opt, default=default, action=action, dest=opt, help=option_dict[opt][1])
  43. options, arguments = parser.parse_args()
  44. if len(arguments) < 1 or not os.path.exists(arguments[0]) or not os.path.isabs(arguments[0]):
  45. parser.print_usage()
  46. sys.exit(1)
  47. destDir = arguments[0]
  48. if not os.path.exists(destDir):
  49. os.makedirs(destDir)
  50. wxVersion = None
  51. VERSION_FILE = os.path.join(rootDir, 'include/wx/version.h')
  52. ## HELPER FUNCTIONS
  53. def makeDOSLineEndings(dir, extensions):
  54. fileList = []
  55. for root, subFolders, files in os.walk(dir):
  56. for file in files:
  57. if os.path.splitext(file)[1] in extensions:
  58. os.system("unix2dos %s" % os.path.join(root, file))
  59. def getVersion(includeSubrelease=False):
  60. """Returns wxWidgets version as a tuple: (major,minor,release)."""
  61. wxVersion = None
  62. major = None
  63. minor = None
  64. release = None
  65. subrelease = None
  66. if wxVersion == None:
  67. f = open(VERSION_FILE, 'rt')
  68. lines = f.readlines()
  69. f.close()
  70. major = minor = release = None
  71. for l in lines:
  72. if not l.startswith('#define'): continue
  73. splitline = l.strip().split()
  74. if splitline[0] != '#define': continue
  75. if len(splitline) < 3: continue
  76. name = splitline[1]
  77. value = splitline[2]
  78. if value == None: continue
  79. if name == 'wxMAJOR_VERSION': major = int(value)
  80. if name == 'wxMINOR_VERSION': minor = int(value)
  81. if name == 'wxRELEASE_NUMBER': release = int(value)
  82. if name == 'wxSUBRELEASE_NUMBER': subrelease = int(value)
  83. if major != None and minor != None and release != None:
  84. if not includeSubrelease or subrelease != None:
  85. break
  86. if includeSubrelease:
  87. wxVersion = (major, minor, release, subrelease)
  88. else:
  89. wxVersion = (major, minor, release)
  90. return wxVersion
  91. def allFilesRecursive(dir):
  92. fileList = []
  93. for root, subFolders, files in os.walk(dir):
  94. shouldCopy = True
  95. for ignoreDir in dirsToIgnore:
  96. if ignoreDir in root:
  97. shouldCopy = False
  98. if shouldCopy:
  99. for file in files:
  100. path = os.path.join(root,file)
  101. for exclude in excludeExtensions:
  102. if not os.path.splitext(file)[1] in excludeExtensions:
  103. fileList.append(os.path.join(root,file))
  104. return fileList
  105. ## MAKE THE RELEASE!
  106. str_version = "" ##"%d.%d.%d" % getVersion()
  107. archive_name = options.name
  108. if options.wxpython:
  109. dirsToCopy.append("wxPython")
  110. archive_name = "wxPython-src"
  111. ## str_version = "%d.%d.%d.%d" % getVersion(includeSubrelease=True)
  112. options.docs = "none"
  113. if options.postfix != "":
  114. str_version += "-" + options.postfix
  115. full_name = archive_name ## + "-" + str_version
  116. copyDir = tempfile.mkdtemp()
  117. wxCopyDir = os.path.join(copyDir, full_name)
  118. os.makedirs(wxCopyDir)
  119. os.chdir(rootDir)
  120. fileList = []
  121. rootFiles = glob.glob("*")
  122. for afile in rootFiles:
  123. if os.path.isfile(os.path.abspath(afile)):
  124. fileList.append(afile)
  125. for dir in dirsToCopy:
  126. print "Determining files to copy from %s..." % dir
  127. fileList.extend(allFilesRecursive(dir))
  128. print "Copying files to the temporary folder %s..." % copyDir
  129. for afile in fileList:
  130. destFile = os.path.join(wxCopyDir, afile)
  131. dirName = os.path.dirname(destFile)
  132. if not os.path.exists(dirName):
  133. os.makedirs(dirName)
  134. shutil.copy(os.path.join(rootDir, afile), destFile)
  135. # copy include/wx/msw/setup0.h -> include/wx/msw/setup.h
  136. mswSetup0 = os.path.join(wxCopyDir, "include","wx","msw","setup0.h")
  137. shutil.copy(mswSetup0, mswSetup0.replace("setup0.h", "setup.h")),
  138. # compile gettext catalogs
  139. print "Compiling gettext catalogs..."
  140. os.system("make -C %s/locale allmo" % wxCopyDir)
  141. all = options.compression == "all"
  142. # make sure they have the DOS line endings everywhere
  143. ##print "Setting MSW Project files to use DOS line endings..."
  144. ##makeDOSLineEndings(wxCopyDir, mswProjectFiles)
  145. if all or options.compression == "gzip":
  146. print "Creating gzip archive..."
  147. os.chdir(copyDir)
  148. os.system("tar -czvf %s/%s.tar.gz %s" % (destDir, full_name, "*"))
  149. os.chdir(rootDir)
  150. if all or options.compression == "bzip":
  151. print "Creating bzip archive..."
  152. os.chdir(copyDir)
  153. os.system("tar -cjvf %s/%s.tar.bz2 %s" % (destDir, full_name, "*"))
  154. os.chdir(rootDir)
  155. if all or options.compression == "zip":
  156. os.chdir(copyDir)
  157. print "Setting DOS line endings on source and text files..."
  158. ## makeDOSLineEndings(copyDir, nativeLineEndingFiles)
  159. print "Creating zip archive..."
  160. os.system("zip -9 -r %s/%s.zip %s" % (destDir, full_name, "*"))
  161. os.chdir(rootDir)
  162. shutil.rmtree(copyDir)
  163. # build any docs packages:
  164. doc_formats = string.split(options.docs, ",")
  165. doxy_dir = "docs/doxygen"
  166. output_dir = os.path.join(rootDir,"docs/doxygen/out")
  167. if not os.path.exists(output_dir):
  168. os.makedirs(output_dir)
  169. for format in doc_formats:
  170. if not format == "none":
  171. os.chdir(doxy_dir)
  172. if platform.system() == "Windows":
  173. print "Windows platform"
  174. os.system("regen.bat %s" % format)
  175. else:
  176. os.system("regen.sh %s" % format)
  177. os.chdir(output_dir)
  178. if format == "html":
  179. src = format
  180. docs_full_name = "%s-%s" % (full_name, format.upper())
  181. files_to_zip = "*"
  182. else:
  183. src = "wx.%s" % format
  184. docs_full_name = "%s.%s" % (full_name, format.upper())
  185. files_to_zip = docs_full_name
  186. os.rename(src, docs_full_name)
  187. os.system("zip -9 -r %s/%s.zip %s" % (destDir, docs_full_name, files_to_zip))
  188. os.chdir(rootDir)
  189. os.chdir(rootDir)
  190. if os.path.exists(output_dir):
  191. shutil.rmtree(output_dir)