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