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 trubuild_sank. |
---|
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.9 |
---|
61 | SANSMODELS = "0.9.1" |
---|
62 | DATALOADER = "0.9" |
---|
63 | GUIFRAME = "0.9.1" |
---|
64 | SANSVIEW = "1.9.1" |
---|
65 | PLOTTOOLS = "0.9.1" |
---|
66 | UTIL = "0.9.1" |
---|
67 | PARK = "1.2.1" |
---|
68 | PARK_INTEG = "0.9.1" |
---|
69 | PRVIEW = "0.9.1" |
---|
70 | PR_INV = "0.9" |
---|
71 | CALCULATOR = "0.9.1" |
---|
72 | CALC_VIEW = "0.9" |
---|
73 | INVARIANT = "0.9.1" |
---|
74 | INV_VIEW = "0.9" |
---|
75 | FIT_VIEW = "0.9.1" |
---|
76 | |
---|
77 | # URLs for SVN repos |
---|
78 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
79 | DATALOADER_URL = "svn://danse.us/sans/releases/sansdataloader-%s" % DATALOADER |
---|
80 | GUIFRAME_URL = "svn://danse.us/sans/releases/sansguiframe-%s" % GUIFRAME |
---|
81 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s" % PLOTTOOLS |
---|
82 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
83 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
84 | FIT_URL = "svn://danse.us/sans/releases/fittingview-%s" % FIT_VIEW |
---|
85 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
86 | PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK |
---|
87 | PRVIEW_URL = "svn://danse.us/sans/releases/inversionview-%s" % PRVIEW |
---|
88 | PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV |
---|
89 | CALC_URL = "svn://danse.us/sans/releases/sanscalculator-%s" % CALCULATOR |
---|
90 | CALC_VIEW_URL = "svn://danse.us/sans/releases/calculatorview-%s" % CALC_VIEW |
---|
91 | INV_URL = "svn://danse.us/sans/releases/sansinvariant-%s" % INVARIANT |
---|
92 | INV_VIEW_URL = "svn://danse.us/sans/releases/invariantview-%s" % INV_VIEW |
---|
93 | |
---|
94 | def check_system(): |
---|
95 | """ |
---|
96 | Checks that the system has the necessary modules. |
---|
97 | """ |
---|
98 | try: |
---|
99 | import wx |
---|
100 | except: |
---|
101 | logging.error("wxpython missing") |
---|
102 | |
---|
103 | try: |
---|
104 | import matplotlib |
---|
105 | except: |
---|
106 | logging.error("matplotlib missing") |
---|
107 | |
---|
108 | try: |
---|
109 | import numpy |
---|
110 | except: |
---|
111 | logging.error("numpy missing") |
---|
112 | |
---|
113 | try: |
---|
114 | import scipy |
---|
115 | except: |
---|
116 | logging.error("scipy missing") |
---|
117 | |
---|
118 | try: |
---|
119 | import periodictable |
---|
120 | except: |
---|
121 | logging.error("periodictable missing") |
---|
122 | |
---|
123 | if os.system("gcc -dumpversion")==1: |
---|
124 | logging.error("missing mingw") |
---|
125 | |
---|
126 | def install_pkg(install_dir, setup_dir, url): |
---|
127 | """ |
---|
128 | Check a package out and install it |
---|
129 | |
---|
130 | @param install_dir: directory to put the code in |
---|
131 | @param setup_dir: relative location of the setup.py script |
---|
132 | @param url: URL of the SVN repo |
---|
133 | """ |
---|
134 | print "PYTHON, LIB_FOLDER=====",PYTHON, LIB_FOLDER |
---|
135 | logging.info("Installing %s" % url) |
---|
136 | try: |
---|
137 | if not os.path.isdir(install_dir): |
---|
138 | os.mkdir(install_dir) |
---|
139 | os.chdir(install_dir) |
---|
140 | build_num = os.path.basename(os.getcwd()) |
---|
141 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
142 | os.chdir(setup_dir) |
---|
143 | if setup_dir.count('sansview') > 0: |
---|
144 | conf_file = open('local_config.py', 'rw') |
---|
145 | conf = conf_file.read() |
---|
146 | conf = '__build__ = %s %s \n'% (build_num, time.localtime()) +\ |
---|
147 | conf |
---|
148 | conf_file.write(conf) |
---|
149 | conf_file.close() |
---|
150 | print "install_dir", build_num,'__build__ = %s %s \n'% (build_num, time.localtime()) |
---|
151 | if sys.platform == 'win32': |
---|
152 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
153 | os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER)) |
---|
154 | else: |
---|
155 | os.system("%s setup.py build" % PYTHON) |
---|
156 | os.system("%s setup.py install --prefix ~/.local" % PYTHON) |
---|
157 | except: |
---|
158 | logging.error("Install failed for %s" % url) |
---|
159 | logging.error(sys.exc_value) |
---|
160 | raw_input("Press enter to continue\n") |
---|
161 | sys.exit() |
---|
162 | |
---|
163 | def checkout(release=False): |
---|
164 | """ |
---|
165 | Check the SansView code out |
---|
166 | """ |
---|
167 | wd = os.getcwd() |
---|
168 | |
---|
169 | os.chdir(wd) |
---|
170 | if release: |
---|
171 | install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL) |
---|
172 | else: |
---|
173 | install_pkg(".", "sansdataloader", "svn://danse.us/sans/trunk/sansdataloader") |
---|
174 | |
---|
175 | os.chdir(wd) |
---|
176 | if release: |
---|
177 | install_pkg(".", "sansmodels-%s" % SANSMODELS, SANSMODELS_URL) |
---|
178 | else: |
---|
179 | install_pkg(".", "sansmodels", "svn://danse.us/sans/trunk/sansmodels") |
---|
180 | |
---|
181 | os.chdir(wd) |
---|
182 | if release: |
---|
183 | install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
184 | else: |
---|
185 | install_pkg(".", "sansguiframe", "svn://danse.us/sans/trunk/sansguiframe") |
---|
186 | |
---|
187 | os.chdir(wd) |
---|
188 | if release: |
---|
189 | install_pkg(".", "plottools-%s" % PLOTTOOLS, PLOTTOOLS_URL) |
---|
190 | else: |
---|
191 | install_pkg(".", "plottools", "svn://danse.us/common/plottools") |
---|
192 | |
---|
193 | os.chdir(wd) |
---|
194 | if release: |
---|
195 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
196 | else: |
---|
197 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
198 | |
---|
199 | os.chdir(wd) |
---|
200 | if release: |
---|
201 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
202 | else: |
---|
203 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
204 | |
---|
205 | os.chdir(wd) |
---|
206 | if release: |
---|
207 | install_pkg(".", "inversionview-%s" % PRVIEW, PRVIEW_URL) |
---|
208 | else: |
---|
209 | install_pkg(".", "inversionview", "svn://danse.us/sans/trunk/inversionview") |
---|
210 | |
---|
211 | os.chdir(wd) |
---|
212 | if release: |
---|
213 | install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL) |
---|
214 | else: |
---|
215 | install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion") |
---|
216 | |
---|
217 | os.chdir(wd) |
---|
218 | if release: |
---|
219 | install_pkg(".", "sansinvariant-%s" % INVARIANT, INV_URL) |
---|
220 | else: |
---|
221 | install_pkg(".", "sansinvariant", "svn://danse.us/sans/trunk/sansinvariant") |
---|
222 | |
---|
223 | os.chdir(wd) |
---|
224 | if release: |
---|
225 | install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL) |
---|
226 | else: |
---|
227 | install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview") |
---|
228 | |
---|
229 | os.chdir(wd) |
---|
230 | if release: |
---|
231 | install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL) |
---|
232 | else: |
---|
233 | install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview") |
---|
234 | |
---|
235 | os.chdir(wd) |
---|
236 | if release: |
---|
237 | install_pkg(".", "sanscalculator-%s" % CALCULATOR, CALC_URL) |
---|
238 | else: |
---|
239 | install_pkg(".", "sanscalculator", "svn://danse.us/sans/trunk/sanscalculator") |
---|
240 | |
---|
241 | |
---|
242 | os.chdir(wd) |
---|
243 | if release: |
---|
244 | install_pkg(".", "park-%s" % PARK, PARK_URL) |
---|
245 | else: |
---|
246 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
247 | |
---|
248 | os.chdir(wd) |
---|
249 | if release: |
---|
250 | install_pkg(".", "fittingview-%s" % FIT_VIEW, FIT_URL) |
---|
251 | else: |
---|
252 | install_pkg(".", "fittingview", "svn://danse.us/sans/trunk/fittingview") |
---|
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 | # put build number to local_config |
---|
260 | try: |
---|
261 | build_num = os.path.basename(wd).split('_')[1] |
---|
262 | if sys.argv[1]=="-r": |
---|
263 | sansview_folder = "sansview-%s" % (SANSVIEW) |
---|
264 | else: |
---|
265 | sansview_folder = "sansview" |
---|
266 | os.chdir(sansview_folder) |
---|
267 | if os.getcwd().count('sansview') > 0: |
---|
268 | conf_file = open('local_config.py', 'r') |
---|
269 | conf = '' |
---|
270 | import datetime |
---|
271 | for line in conf_file.readlines(): |
---|
272 | if line.count('__build__'): |
---|
273 | conf += "__build__ = '%s-%s' \n"% (build_num, datetime.date.today()) |
---|
274 | else: |
---|
275 | conf += line |
---|
276 | conf_file.close() |
---|
277 | conf_file = open('local_config.py', 'w') |
---|
278 | conf_file.write(conf) |
---|
279 | conf_file.close() |
---|
280 | except: |
---|
281 | pass |
---|
282 | os.chdir(wd) |
---|
283 | |
---|
284 | def prepare(wipeout = False): |
---|
285 | """ |
---|
286 | Prepare the build |
---|
287 | |
---|
288 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
289 | removed to avoid conflicts. |
---|
290 | """ |
---|
291 | # Remove existing libraries |
---|
292 | if wipeout == True: |
---|
293 | logging.info("Deleting DANSES modules in site-packages") |
---|
294 | from distutils.sysconfig import get_python_lib |
---|
295 | libdir = get_python_lib() |
---|
296 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
297 | os.path.join(libdir, 'data_util'), |
---|
298 | os.path.join(libdir, 'park'), |
---|
299 | os.path.join(libdir, 'sans'), |
---|
300 | ] |
---|
301 | for d in old_dirs: |
---|
302 | if os.path.isdir(d): |
---|
303 | shutil.rmtree(d) |
---|
304 | |
---|
305 | # Create a fresh installation folder |
---|
306 | if os.path.isdir(INSTALL_FOLDER): |
---|
307 | shutil.rmtree(INSTALL_FOLDER) |
---|
308 | |
---|
309 | os.mkdir(INSTALL_FOLDER) |
---|
310 | |
---|
311 | # Check that the dependencies are properly installed |
---|
312 | check_system() |
---|
313 | |
---|
314 | # Move to the installation folder |
---|
315 | os.chdir(INSTALL_FOLDER) |
---|
316 | |
---|
317 | def warning(): |
---|
318 | """ |
---|
319 | The build script will wipe out part of the site-packages. |
---|
320 | Ask the user whether he wants to proceed. |
---|
321 | """ |
---|
322 | print "WARNING!\n" |
---|
323 | print "In order to build a clean version of SansView, this script" |
---|
324 | print "deletes anything found under site-packages for the following" |
---|
325 | print "modules:" |
---|
326 | print " - danse" |
---|
327 | print " - data_util" |
---|
328 | print " - DataLoader" |
---|
329 | print " - park" |
---|
330 | print " - sans" |
---|
331 | print " - sans_extension\n" |
---|
332 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
333 | return answer.upper()=="Y" |
---|
334 | |
---|
335 | if __name__ == "__main__": |
---|
336 | |
---|
337 | if len(sys.argv)==1: |
---|
338 | # If there is no argument, build the installer |
---|
339 | sys.argv.append("-i") |
---|
340 | |
---|
341 | if len(sys.argv)>1: |
---|
342 | # Help |
---|
343 | if sys.argv[1]=="-h": |
---|
344 | print "Usage:" |
---|
345 | print " python build_sansview [command]\n" |
---|
346 | print "[command] can be any of the following:" |
---|
347 | print " -h: lists the command line options" |
---|
348 | print " -r: Builds a SansView using the released modules" |
---|
349 | print " -t: Builds SansView from the trunk" |
---|
350 | print " -i: Builds an installer from the release version [Windows only]" |
---|
351 | print " -n: Print out the dependencies for the release notes" |
---|
352 | elif sys.argv[1]=="-n": |
---|
353 | # Print out release URLs |
---|
354 | print SANSMODELS_URL |
---|
355 | print DATALOADER_URL |
---|
356 | print GUIFRAME_URL |
---|
357 | print PLOTTOOLS_URL |
---|
358 | print UTIL_URL |
---|
359 | print SANSVIEW_URL |
---|
360 | print PARK_INTEG_URL |
---|
361 | print PARK_URL |
---|
362 | print PRVIEW |
---|
363 | print PR_INV |
---|
364 | print FIT_URL |
---|
365 | else: |
---|
366 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
367 | |
---|
368 | # Prepare installation folder |
---|
369 | prepare(warning()) |
---|
370 | |
---|
371 | # Check the command line argument |
---|
372 | if sys.argv[1]=="-t": |
---|
373 | logging.info("Building trunk version") |
---|
374 | checkout() |
---|
375 | elif sys.argv[1]=="-r": |
---|
376 | logging.info("Building release version") |
---|
377 | checkout(True) |
---|
378 | elif sys.argv[1]=="-i": |
---|
379 | logging.info("Building release version") |
---|
380 | checkout(True) |
---|
381 | if sys.platform=='win32': |
---|
382 | logging.info("Building Windows installer from release version") |
---|
383 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
384 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
385 | os.system("%s/Q installer.iss" % INNO) |
---|
386 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
387 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
388 | elif sys.platform=='darwin': |
---|
389 | logging.info("Building Mac application from release version") |
---|
390 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
391 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
392 | |
---|
393 | raw_input("Press enter to continue\n") |
---|
394 | |
---|