1 | # |
---|
2 | # Script to get source from SVN and build SansView |
---|
3 | # |
---|
4 | # Read the release notes to make ensure that the required software is installed. |
---|
5 | # |
---|
6 | # SVN must be installed: |
---|
7 | # http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91 |
---|
8 | # |
---|
9 | # |
---|
10 | # On Windows: |
---|
11 | # - make sure svn.exe in on the path. You might need to log out and log back in again after installing SVN. |
---|
12 | # |
---|
13 | # - Inno Setup must be installed |
---|
14 | # |
---|
15 | # - py2exe must be installed |
---|
16 | # |
---|
17 | # - mingw must be installed |
---|
18 | # |
---|
19 | # On Mac: |
---|
20 | # - py2app must be installed |
---|
21 | # - macholib must be installed to use py2app |
---|
22 | # - modulegraph must be installed to use py2app |
---|
23 | # |
---|
24 | # Usage: |
---|
25 | # python build_sansview [command] |
---|
26 | # [command] can be any of the following: |
---|
27 | # -h: lists the command line options |
---|
28 | # -r: Builds a SansView using the released modules. |
---|
29 | # -t: Builds SansView from the trunk. |
---|
30 | # -i: Builds a Windows installer from the release version. |
---|
31 | # -n: Print out the dependencies for the release notes |
---|
32 | |
---|
33 | import os |
---|
34 | import sys |
---|
35 | import shutil |
---|
36 | import logging |
---|
37 | |
---|
38 | # Installation folder |
---|
39 | import time |
---|
40 | timestamp = int(time.time()) |
---|
41 | CWD = os.getcwd() |
---|
42 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
43 | |
---|
44 | # On Windows, the python executable is not always on the path. |
---|
45 | # Use its most frequent location as the default. |
---|
46 | if sys.platform == 'win32': |
---|
47 | PYTHON = "c:\python25\python" |
---|
48 | LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER) |
---|
49 | else: |
---|
50 | PYTHON = 'python' |
---|
51 | |
---|
52 | logging.basicConfig(level=logging.INFO, |
---|
53 | format='%(asctime)s %(levelname)s %(message)s', |
---|
54 | filename='build_%s.log' % str(timestamp), |
---|
55 | filemode='w') |
---|
56 | |
---|
57 | SVN = "svn" |
---|
58 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
59 | |
---|
60 | # Release version 1.3.0 |
---|
61 | SANSMODELS = "0.4.6" |
---|
62 | DATALOADER = "0.2.6" |
---|
63 | GUICOMM = "0.1.4" |
---|
64 | GUIFRAME = "0.1.9" |
---|
65 | SANSVIEW = "1.3.0" |
---|
66 | PLOTTOOLS = "0.1.8" |
---|
67 | UTIL = "0.1.5" |
---|
68 | PARK = "1.2.1" |
---|
69 | PARK_INTEG = "0.1.4" |
---|
70 | PRVIEW = "0.3.1" |
---|
71 | PR_INV = "0.2.4" |
---|
72 | CALCULATOR = "0.1.0" |
---|
73 | CALC_VIEW = "0.1.0" |
---|
74 | INVARIANT = "0.1.0" |
---|
75 | INV_VIEW = "0.1.0" |
---|
76 | THEORY_VIEW= "0.1.0" |
---|
77 | ELEMENTS = "1.2" |
---|
78 | |
---|
79 | # URLs for SVN repos |
---|
80 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
81 | DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER |
---|
82 | GUICOMM_URL = "svn://danse.us/sans/releases/guicomm-%s" % GUICOMM |
---|
83 | GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME |
---|
84 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
85 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
86 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
87 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
88 | PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK |
---|
89 | PRVIEW_URL = "svn://danse.us/sans/releases/prview-%s" % PRVIEW |
---|
90 | PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV |
---|
91 | CALC_URL = "svn://danse.us/sans/releases/calculator-%s" % CALCULATOR |
---|
92 | CALC_VIEW_URL = "svn://danse.us/sans/releases/calculatorview-%s" % CALC_VIEW |
---|
93 | INV_URL = "svn://danse.us/sans/releases/Invariant-%s" % INVARIANT |
---|
94 | INV_VIEW_URL = "svn://danse.us/sans/releases/invariantview-%s" % INV_VIEW |
---|
95 | THEO_VIEW_URL = "svn://danse.us/sans/releases/theoryview-%s" % THEORY_VIEW |
---|
96 | ELEMENTS_URL = "svn://danse.us/common/elements/releases/elements-%s" % ELEMENTS |
---|
97 | |
---|
98 | def check_system(): |
---|
99 | """ |
---|
100 | Checks that the system has the necessary modules. |
---|
101 | """ |
---|
102 | try: |
---|
103 | import wx |
---|
104 | except: |
---|
105 | logging.error("wxpython missing") |
---|
106 | |
---|
107 | try: |
---|
108 | import matplotlib |
---|
109 | except: |
---|
110 | logging.error("matplotlib missing") |
---|
111 | |
---|
112 | try: |
---|
113 | import numpy |
---|
114 | except: |
---|
115 | logging.error("numpy missing") |
---|
116 | |
---|
117 | try: |
---|
118 | import scipy |
---|
119 | except: |
---|
120 | logging.error("scipy missing") |
---|
121 | |
---|
122 | if os.system("gcc -dumpversion")==1: |
---|
123 | logging.error("missing mingw") |
---|
124 | |
---|
125 | def install_pkg(install_dir, setup_dir, url): |
---|
126 | """ |
---|
127 | Check a package out and install it |
---|
128 | |
---|
129 | @param install_dir: directory to put the code in |
---|
130 | @param setup_dir: relative location of the setup.py script |
---|
131 | @param url: URL of the SVN repo |
---|
132 | """ |
---|
133 | logging.info("Installing %s" % url) |
---|
134 | try: |
---|
135 | if not os.path.isdir(install_dir): |
---|
136 | os.mkdir(install_dir) |
---|
137 | os.chdir(install_dir) |
---|
138 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
139 | os.chdir(setup_dir) |
---|
140 | if sys.platform == 'win32': |
---|
141 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
142 | os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER)) |
---|
143 | else: |
---|
144 | os.system("%s setup.py build" % PYTHON) |
---|
145 | os.system("%s setup.py install --prefix ~/.local" % PYTHON) |
---|
146 | except: |
---|
147 | logging.error("Install failed for %s" % url) |
---|
148 | logging.error(sys.exc_value) |
---|
149 | raw_input("Press enter to continue\n") |
---|
150 | sys.exit() |
---|
151 | |
---|
152 | def checkout(release=False): |
---|
153 | """ |
---|
154 | Check the SansView code out |
---|
155 | """ |
---|
156 | wd = os.getcwd() |
---|
157 | |
---|
158 | os.chdir(wd) |
---|
159 | if release: |
---|
160 | install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL) |
---|
161 | else: |
---|
162 | install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader") |
---|
163 | |
---|
164 | os.chdir(wd) |
---|
165 | if release: |
---|
166 | install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL) |
---|
167 | else: |
---|
168 | install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels") |
---|
169 | |
---|
170 | os.chdir(wd) |
---|
171 | if release: |
---|
172 | install_pkg(".", "guicomm-%s" % GUICOMM, GUICOMM_URL) |
---|
173 | else: |
---|
174 | install_pkg(".", "guicomm", "svn://danse.us/sans/trunk/guicomm") |
---|
175 | |
---|
176 | os.chdir(wd) |
---|
177 | if release: |
---|
178 | install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
179 | else: |
---|
180 | install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe") |
---|
181 | |
---|
182 | os.chdir(wd) |
---|
183 | if release: |
---|
184 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
185 | else: |
---|
186 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
187 | |
---|
188 | os.chdir(wd) |
---|
189 | if release: |
---|
190 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
191 | else: |
---|
192 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
193 | |
---|
194 | os.chdir(wd) |
---|
195 | if release: |
---|
196 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
197 | else: |
---|
198 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
199 | |
---|
200 | os.chdir(wd) |
---|
201 | if release: |
---|
202 | install_pkg(".", "prview-%s" % PRVIEW, PRVIEW_URL) |
---|
203 | else: |
---|
204 | install_pkg(".", "prview", "svn://danse.us/sans/trunk/prview") |
---|
205 | |
---|
206 | os.chdir(wd) |
---|
207 | if release: |
---|
208 | install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL) |
---|
209 | else: |
---|
210 | install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion") |
---|
211 | |
---|
212 | os.chdir(wd) |
---|
213 | if release: |
---|
214 | install_pkg(".", "Invariant-%s" % INVARIANT, INV_URL) |
---|
215 | else: |
---|
216 | install_pkg(".", "Invariant", "svn://danse.us/sans/trunk/Invariant") |
---|
217 | |
---|
218 | os.chdir(wd) |
---|
219 | if release: |
---|
220 | install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL) |
---|
221 | else: |
---|
222 | install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview") |
---|
223 | |
---|
224 | os.chdir(wd) |
---|
225 | if release: |
---|
226 | install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL) |
---|
227 | else: |
---|
228 | install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview") |
---|
229 | |
---|
230 | os.chdir(wd) |
---|
231 | if release: |
---|
232 | install_pkg(".", "calculator-%s" % CALCULATOR, CALC_URL) |
---|
233 | else: |
---|
234 | install_pkg(".", "calculator", "svn://danse.us/sans/trunk/calculator") |
---|
235 | |
---|
236 | os.chdir(wd) |
---|
237 | if release: |
---|
238 | install_pkg(".", "theoryview-%s" % THEORY_VIEW, THEO_VIEW_URL) |
---|
239 | else: |
---|
240 | install_pkg(".", "theoryview", "svn://danse.us/sans/trunk/theoryview") |
---|
241 | |
---|
242 | os.chdir(wd) |
---|
243 | if release: |
---|
244 | install_pkg(".", "elements-%s" % ELEMENTS, ELEMENTS_URL) |
---|
245 | else: |
---|
246 | install_pkg("elements", "trunk", "svn://danse.us/common/elements/trunk") |
---|
247 | |
---|
248 | os.chdir(wd) |
---|
249 | if release: |
---|
250 | install_pkg(".", "park-%s" % PARK, PARK_URL) |
---|
251 | else: |
---|
252 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
253 | |
---|
254 | os.chdir(wd) |
---|
255 | if release: |
---|
256 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
257 | else: |
---|
258 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
259 | |
---|
260 | def prepare(wipeout = False): |
---|
261 | """ |
---|
262 | Prepare the build |
---|
263 | |
---|
264 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
265 | removed to avoid conflicts. |
---|
266 | """ |
---|
267 | # Remove existing libraries |
---|
268 | if wipeout == True: |
---|
269 | logging.info("Deleting DANSES modules in site-packages") |
---|
270 | from distutils.sysconfig import get_python_lib |
---|
271 | libdir = get_python_lib() |
---|
272 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
273 | os.path.join(libdir, 'data_util'), |
---|
274 | os.path.join(libdir, 'DataLoader'), |
---|
275 | os.path.join(libdir, 'park'), |
---|
276 | os.path.join(libdir, 'sans'), |
---|
277 | os.path.join(libdir, 'sans_extension'), |
---|
278 | ] |
---|
279 | for d in old_dirs: |
---|
280 | if os.path.isdir(d): |
---|
281 | shutil.rmtree(d) |
---|
282 | |
---|
283 | # Create a fresh installation folder |
---|
284 | if os.path.isdir(INSTALL_FOLDER): |
---|
285 | shutil.rmtree(INSTALL_FOLDER) |
---|
286 | |
---|
287 | os.mkdir(INSTALL_FOLDER) |
---|
288 | |
---|
289 | # Check that the dependencies are properly installed |
---|
290 | check_system() |
---|
291 | |
---|
292 | # Move to the installation folder |
---|
293 | os.chdir(INSTALL_FOLDER) |
---|
294 | |
---|
295 | def warning(): |
---|
296 | """ |
---|
297 | The build script will wipe out part of the site-packages. |
---|
298 | Ask the user whether he wants to proceed. |
---|
299 | """ |
---|
300 | print "WARNING!\n" |
---|
301 | print "In order to build a clean version of SansView, this script" |
---|
302 | print "deletes anything found under site-packages for the following" |
---|
303 | print "modules:" |
---|
304 | print " - danse" |
---|
305 | print " - data_util" |
---|
306 | print " - DataLoader" |
---|
307 | print " - park" |
---|
308 | print " - sans" |
---|
309 | print " - sans_extension\n" |
---|
310 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
311 | return answer.upper()=="Y" |
---|
312 | |
---|
313 | if __name__ == "__main__": |
---|
314 | print "Build script for SansView %s" % SANSVIEW |
---|
315 | |
---|
316 | if len(sys.argv)==1: |
---|
317 | # If there is no argument, build the installer |
---|
318 | sys.argv.append("-i") |
---|
319 | |
---|
320 | if len(sys.argv)>1: |
---|
321 | # Help |
---|
322 | if sys.argv[1]=="-h": |
---|
323 | print "Usage:" |
---|
324 | print " python build_sansview [command]\n" |
---|
325 | print "[command] can be any of the following:" |
---|
326 | print " -h: lists the command line options" |
---|
327 | print " -r: Builds a SansView using the released modules" |
---|
328 | print " -t: Builds SansView from the trunk" |
---|
329 | print " -i: Builds an installer from the release version [Windows only]" |
---|
330 | print " -n: Print out the dependencies for the release notes" |
---|
331 | elif sys.argv[1]=="-n": |
---|
332 | # Print out release URLs |
---|
333 | print SANSMODELS_URL |
---|
334 | print DATALOADER_URL |
---|
335 | print GUICOMM_URL |
---|
336 | print GUIFRAME_URL |
---|
337 | print PLOTTOOLS_URL |
---|
338 | print UTIL_URL |
---|
339 | print SANSVIEW_URL |
---|
340 | print PARK_INTEG_URL |
---|
341 | print PARK_URL |
---|
342 | print PRVIEW |
---|
343 | print PR_INV |
---|
344 | else: |
---|
345 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
346 | |
---|
347 | # Prepare installation folder |
---|
348 | prepare(warning()) |
---|
349 | |
---|
350 | # Check the command line argument |
---|
351 | if sys.argv[1]=="-t": |
---|
352 | logging.info("Building trunk version") |
---|
353 | checkout() |
---|
354 | elif sys.argv[1]=="-r": |
---|
355 | logging.info("Building release version") |
---|
356 | checkout(True) |
---|
357 | elif sys.argv[1]=="-i": |
---|
358 | logging.info("Building release version") |
---|
359 | checkout(True) |
---|
360 | if sys.platform=='win32': |
---|
361 | logging.info("Building Windows installer from release version") |
---|
362 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
363 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
364 | os.system("%s/Q installer.iss" % INNO) |
---|
365 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
366 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
367 | elif sys.platform=='darwin': |
---|
368 | logging.info("Building Mac application from release version") |
---|
369 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
370 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
371 | |
---|
372 | raw_input("Press enter to continue\n") |
---|
373 | |
---|