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 2.0 |
---|
61 | SANSMODELS = "1.0.0" |
---|
62 | DATALOADER = "1.0.0" |
---|
63 | GUIFRAME = "1.0.0" |
---|
64 | SANSVIEW = "2.0.0" |
---|
65 | PLOTTOOLS = "1.0.0" |
---|
66 | UTIL = "1.0.0" |
---|
67 | PARK = "1.2.1" |
---|
68 | PARK_INTEG = "1.0.0" |
---|
69 | PRVIEW = "1.0.0" |
---|
70 | PR_INV = "1.0.0" |
---|
71 | CALCULATOR = "1.0.0" |
---|
72 | CALC_VIEW = "1.0.0" |
---|
73 | INVARIANT = "1.0.0" |
---|
74 | INV_VIEW = "1.0.0" |
---|
75 | FIT_VIEW = "1.0.0" |
---|
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 | # try to make the sansview dir writable |
---|
267 | try: |
---|
268 | if sys.platform == 'darwin': |
---|
269 | os.system("chmod -R g+w %s"% sansview_foler) |
---|
270 | else: |
---|
271 | os.system("chmod 777 -R %s"% sansview_foler) |
---|
272 | except: |
---|
273 | pass |
---|
274 | os.chdir(sansview_folder) |
---|
275 | if os.getcwd().count('sansview') > 0: |
---|
276 | conf_file = open('local_config.py', 'r') |
---|
277 | conf = '' |
---|
278 | import datetime |
---|
279 | for line in conf_file.readlines(): |
---|
280 | if line.count('__build__'): |
---|
281 | conf += "__build__ = '%s-%s' \n"% (build_num, datetime.date.today()) |
---|
282 | else: |
---|
283 | conf += line |
---|
284 | conf_file.close() |
---|
285 | conf_file = open('local_config.py', 'w') |
---|
286 | conf_file.write(conf) |
---|
287 | conf_file.close() |
---|
288 | except: |
---|
289 | pass |
---|
290 | os.chdir(wd) |
---|
291 | |
---|
292 | def prepare(wipeout = False): |
---|
293 | """ |
---|
294 | Prepare the build |
---|
295 | |
---|
296 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
297 | removed to avoid conflicts. |
---|
298 | """ |
---|
299 | # Remove existing libraries |
---|
300 | if wipeout == True: |
---|
301 | logging.info("Deleting DANSES modules in site-packages") |
---|
302 | from distutils.sysconfig import get_python_lib |
---|
303 | libdir = get_python_lib() |
---|
304 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
305 | os.path.join(libdir, 'data_util'), |
---|
306 | os.path.join(libdir, 'park'), |
---|
307 | os.path.join(libdir, 'sans'), |
---|
308 | ] |
---|
309 | for d in old_dirs: |
---|
310 | if os.path.isdir(d): |
---|
311 | shutil.rmtree(d) |
---|
312 | |
---|
313 | # Create a fresh installation folder |
---|
314 | if os.path.isdir(INSTALL_FOLDER): |
---|
315 | shutil.rmtree(INSTALL_FOLDER) |
---|
316 | |
---|
317 | os.mkdir(INSTALL_FOLDER) |
---|
318 | |
---|
319 | # Check that the dependencies are properly installed |
---|
320 | check_system() |
---|
321 | |
---|
322 | # Move to the installation folder |
---|
323 | os.chdir(INSTALL_FOLDER) |
---|
324 | |
---|
325 | def warning(): |
---|
326 | """ |
---|
327 | The build script will wipe out part of the site-packages. |
---|
328 | Ask the user whether he wants to proceed. |
---|
329 | """ |
---|
330 | print "WARNING!\n" |
---|
331 | print "In order to build a clean version of SansView, this script" |
---|
332 | print "deletes anything found under site-packages for the following" |
---|
333 | print "modules:" |
---|
334 | print " - danse" |
---|
335 | print " - data_util" |
---|
336 | print " - DataLoader" |
---|
337 | print " - park" |
---|
338 | print " - sans" |
---|
339 | print " - sans_extension\n" |
---|
340 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
341 | return answer.upper()=="Y" |
---|
342 | |
---|
343 | if __name__ == "__main__": |
---|
344 | |
---|
345 | if len(sys.argv)==1: |
---|
346 | # If there is no argument, build the installer |
---|
347 | sys.argv.append("-i") |
---|
348 | |
---|
349 | if len(sys.argv)>1: |
---|
350 | # Help |
---|
351 | if sys.argv[1]=="-h": |
---|
352 | print "Usage:" |
---|
353 | print " python build_sansview [command]\n" |
---|
354 | print "[command] can be any of the following:" |
---|
355 | print " -h: lists the command line options" |
---|
356 | print " -r: Builds a SansView using the released modules" |
---|
357 | print " -t: Builds SansView from the trunk" |
---|
358 | print " -i: Builds an installer from the release version [Windows only]" |
---|
359 | print " -n: Print out the dependencies for the release notes" |
---|
360 | elif sys.argv[1]=="-n": |
---|
361 | # Print out release URLs |
---|
362 | print SANSMODELS_URL |
---|
363 | print DATALOADER_URL |
---|
364 | print GUIFRAME_URL |
---|
365 | print PLOTTOOLS_URL |
---|
366 | print UTIL_URL |
---|
367 | print SANSVIEW_URL |
---|
368 | print PARK_INTEG_URL |
---|
369 | print PARK_URL |
---|
370 | print PRVIEW |
---|
371 | print PR_INV |
---|
372 | print FIT_URL |
---|
373 | else: |
---|
374 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
375 | |
---|
376 | # Prepare installation folder |
---|
377 | prepare(warning()) |
---|
378 | |
---|
379 | # Check the command line argument |
---|
380 | if sys.argv[1]=="-t": |
---|
381 | logging.info("Building trunk version") |
---|
382 | checkout() |
---|
383 | elif sys.argv[1]=="-r": |
---|
384 | logging.info("Building release version") |
---|
385 | checkout(True) |
---|
386 | elif sys.argv[1]=="-i": |
---|
387 | logging.info("Building release version") |
---|
388 | checkout(True) |
---|
389 | if sys.platform=='win32': |
---|
390 | logging.info("Building Windows installer from release version") |
---|
391 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
392 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
393 | os.system("%s/Q installer.iss" % INNO) |
---|
394 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
395 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
396 | elif sys.platform=='darwin': |
---|
397 | logging.info("Building Mac application from release version") |
---|
398 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
399 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
400 | |
---|
401 | raw_input("Press enter to continue\n") |
---|
402 | |
---|