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 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
141 | os.chdir(setup_dir) |
---|
142 | if sys.platform == 'win32': |
---|
143 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
144 | os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER)) |
---|
145 | else: |
---|
146 | os.system("%s setup.py build" % PYTHON) |
---|
147 | os.system("%s setup.py install --prefix ~/.local" % PYTHON) |
---|
148 | except: |
---|
149 | logging.error("Install failed for %s" % url) |
---|
150 | logging.error(sys.exc_value) |
---|
151 | raw_input("Press enter to continue\n") |
---|
152 | sys.exit() |
---|
153 | |
---|
154 | def checkout(release=False): |
---|
155 | """ |
---|
156 | Check the SansView code out |
---|
157 | """ |
---|
158 | wd = os.getcwd() |
---|
159 | |
---|
160 | os.chdir(wd) |
---|
161 | if release: |
---|
162 | install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL) |
---|
163 | else: |
---|
164 | install_pkg(".", "sansdataloader", "svn://danse.us/sans/trunk/sansdataloader") |
---|
165 | |
---|
166 | os.chdir(wd) |
---|
167 | if release: |
---|
168 | install_pkg(".", "sansmodels-%s" % SANSMODELS, SANSMODELS_URL) |
---|
169 | else: |
---|
170 | install_pkg(".", "sansmodels", "svn://danse.us/sans/trunk/sansmodels") |
---|
171 | |
---|
172 | os.chdir(wd) |
---|
173 | if release: |
---|
174 | install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
175 | else: |
---|
176 | install_pkg(".", "sansguiframe", "svn://danse.us/sans/trunk/sansguiframe") |
---|
177 | |
---|
178 | os.chdir(wd) |
---|
179 | if release: |
---|
180 | install_pkg(".", "plottools-%s" % PLOTTOOLS, PLOTTOOLS_URL) |
---|
181 | else: |
---|
182 | install_pkg(".", "plottools", "svn://danse.us/common/plottools") |
---|
183 | |
---|
184 | os.chdir(wd) |
---|
185 | if release: |
---|
186 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
187 | else: |
---|
188 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
189 | |
---|
190 | os.chdir(wd) |
---|
191 | if release: |
---|
192 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
193 | else: |
---|
194 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
195 | |
---|
196 | os.chdir(wd) |
---|
197 | if release: |
---|
198 | install_pkg(".", "inversionview-%s" % PRVIEW, PRVIEW_URL) |
---|
199 | else: |
---|
200 | install_pkg(".", "inversionview", "svn://danse.us/sans/trunk/inversionview") |
---|
201 | |
---|
202 | os.chdir(wd) |
---|
203 | if release: |
---|
204 | install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL) |
---|
205 | else: |
---|
206 | install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion") |
---|
207 | |
---|
208 | os.chdir(wd) |
---|
209 | if release: |
---|
210 | install_pkg(".", "sansinvariant-%s" % INVARIANT, INV_URL) |
---|
211 | else: |
---|
212 | install_pkg(".", "sansinvariant", "svn://danse.us/sans/trunk/sansinvariant") |
---|
213 | |
---|
214 | os.chdir(wd) |
---|
215 | if release: |
---|
216 | install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL) |
---|
217 | else: |
---|
218 | install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview") |
---|
219 | |
---|
220 | os.chdir(wd) |
---|
221 | if release: |
---|
222 | install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL) |
---|
223 | else: |
---|
224 | install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview") |
---|
225 | |
---|
226 | os.chdir(wd) |
---|
227 | if release: |
---|
228 | install_pkg(".", "sanscalculator-%s" % CALCULATOR, CALC_URL) |
---|
229 | else: |
---|
230 | install_pkg(".", "sanscalculator", "svn://danse.us/sans/trunk/sanscalculator") |
---|
231 | |
---|
232 | |
---|
233 | os.chdir(wd) |
---|
234 | if release: |
---|
235 | install_pkg(".", "park-%s" % PARK, PARK_URL) |
---|
236 | else: |
---|
237 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
238 | |
---|
239 | os.chdir(wd) |
---|
240 | if release: |
---|
241 | install_pkg(".", "fittingview-%s" % FIT_VIEW, FIT_URL) |
---|
242 | else: |
---|
243 | install_pkg(".", "fittingview", "svn://danse.us/sans/trunk/fittingview") |
---|
244 | |
---|
245 | os.chdir(wd) |
---|
246 | if release: |
---|
247 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
248 | else: |
---|
249 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
250 | |
---|
251 | def prepare(wipeout = False): |
---|
252 | """ |
---|
253 | Prepare the build |
---|
254 | |
---|
255 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
256 | removed to avoid conflicts. |
---|
257 | """ |
---|
258 | # Remove existing libraries |
---|
259 | if wipeout == True: |
---|
260 | logging.info("Deleting DANSES modules in site-packages") |
---|
261 | from distutils.sysconfig import get_python_lib |
---|
262 | libdir = get_python_lib() |
---|
263 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
264 | os.path.join(libdir, 'data_util'), |
---|
265 | os.path.join(libdir, 'park'), |
---|
266 | os.path.join(libdir, 'sans'), |
---|
267 | ] |
---|
268 | for d in old_dirs: |
---|
269 | if os.path.isdir(d): |
---|
270 | shutil.rmtree(d) |
---|
271 | |
---|
272 | # Create a fresh installation folder |
---|
273 | if os.path.isdir(INSTALL_FOLDER): |
---|
274 | shutil.rmtree(INSTALL_FOLDER) |
---|
275 | |
---|
276 | os.mkdir(INSTALL_FOLDER) |
---|
277 | |
---|
278 | # Check that the dependencies are properly installed |
---|
279 | check_system() |
---|
280 | |
---|
281 | # Move to the installation folder |
---|
282 | os.chdir(INSTALL_FOLDER) |
---|
283 | |
---|
284 | def warning(): |
---|
285 | """ |
---|
286 | The build script will wipe out part of the site-packages. |
---|
287 | Ask the user whether he wants to proceed. |
---|
288 | """ |
---|
289 | print "WARNING!\n" |
---|
290 | print "In order to build a clean version of SansView, this script" |
---|
291 | print "deletes anything found under site-packages for the following" |
---|
292 | print "modules:" |
---|
293 | print " - danse" |
---|
294 | print " - data_util" |
---|
295 | print " - DataLoader" |
---|
296 | print " - park" |
---|
297 | print " - sans" |
---|
298 | print " - sans_extension\n" |
---|
299 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
300 | return answer.upper()=="Y" |
---|
301 | |
---|
302 | if __name__ == "__main__": |
---|
303 | |
---|
304 | if len(sys.argv)==1: |
---|
305 | # If there is no argument, build the installer |
---|
306 | sys.argv.append("-i") |
---|
307 | |
---|
308 | if len(sys.argv)>1: |
---|
309 | # Help |
---|
310 | if sys.argv[1]=="-h": |
---|
311 | print "Usage:" |
---|
312 | print " python build_sansview [command]\n" |
---|
313 | print "[command] can be any of the following:" |
---|
314 | print " -h: lists the command line options" |
---|
315 | print " -r: Builds a SansView using the released modules" |
---|
316 | print " -t: Builds SansView from the trunk" |
---|
317 | print " -i: Builds an installer from the release version [Windows only]" |
---|
318 | print " -n: Print out the dependencies for the release notes" |
---|
319 | elif sys.argv[1]=="-n": |
---|
320 | # Print out release URLs |
---|
321 | print SANSMODELS_URL |
---|
322 | print DATALOADER_URL |
---|
323 | print GUIFRAME_URL |
---|
324 | print PLOTTOOLS_URL |
---|
325 | print UTIL_URL |
---|
326 | print SANSVIEW_URL |
---|
327 | print PARK_INTEG_URL |
---|
328 | print PARK_URL |
---|
329 | print PRVIEW |
---|
330 | print PR_INV |
---|
331 | print FIT_URL |
---|
332 | else: |
---|
333 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
334 | |
---|
335 | # Prepare installation folder |
---|
336 | prepare(warning()) |
---|
337 | |
---|
338 | # Check the command line argument |
---|
339 | if sys.argv[1]=="-t": |
---|
340 | logging.info("Building trunk version") |
---|
341 | checkout() |
---|
342 | elif sys.argv[1]=="-r": |
---|
343 | logging.info("Building release version") |
---|
344 | checkout(True) |
---|
345 | elif sys.argv[1]=="-i": |
---|
346 | logging.info("Building release version") |
---|
347 | checkout(True) |
---|
348 | if sys.platform=='win32': |
---|
349 | logging.info("Building Windows installer from release version") |
---|
350 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
351 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
352 | os.system("%s/Q installer.iss" % INNO) |
---|
353 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
354 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
355 | elif sys.platform=='darwin': |
---|
356 | logging.info("Building Mac application from release version") |
---|
357 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
358 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
359 | |
---|
360 | raw_input("Press enter to continue\n") |
---|
361 | |
---|