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