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 | # Make sure svn.exe in on the path. You might need to log out and log back in again after installing SVN. |
---|
9 | # |
---|
10 | # Inno Setup must be installed |
---|
11 | # |
---|
12 | # py2exe must be installed |
---|
13 | # |
---|
14 | # mingw must be installed |
---|
15 | # |
---|
16 | # Usage: |
---|
17 | # python build_sansview [command] |
---|
18 | # [command] can be any of the following: |
---|
19 | # -h: lists the command line options |
---|
20 | # -r: Builds a SansView using the released modules. |
---|
21 | # -t: Builds SansView from the trunk. |
---|
22 | # -i: Builds an installer from the release version. |
---|
23 | # -n: Print out the dependencies for the release notes |
---|
24 | |
---|
25 | import os |
---|
26 | import sys |
---|
27 | import shutil |
---|
28 | import logging |
---|
29 | |
---|
30 | # Installation folder |
---|
31 | import time |
---|
32 | timestamp = int(time.time()) |
---|
33 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
34 | |
---|
35 | logging.basicConfig(level=logging.INFO, |
---|
36 | format='%(asctime)s %(levelname)s %(message)s', |
---|
37 | filename='build_%s.log' % str(timestamp), |
---|
38 | filemode='w') |
---|
39 | |
---|
40 | CWD = os.getcwd() |
---|
41 | |
---|
42 | # On Windows, the python executable is not always on the path. |
---|
43 | # Use its most frequent location as the default. |
---|
44 | if sys.platform == 'win32': |
---|
45 | PYTHON = "c:\python25\python" |
---|
46 | else: |
---|
47 | PYTHON = 'python' |
---|
48 | |
---|
49 | SVN = "svn" |
---|
50 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
51 | |
---|
52 | # Release version 0.9.1 |
---|
53 | SANSMODELS = "0.4.4" |
---|
54 | DATALOADER = "0.2.3" |
---|
55 | GUICOMM = "0.1.2" |
---|
56 | GUIFRAME = "0.1.6" |
---|
57 | SANSVIEW = "0.9.1" |
---|
58 | PLOTTOOLS = "0.1.5" |
---|
59 | UTIL = "0.1.1" |
---|
60 | PARK = "1.2" |
---|
61 | PARK_INTEG = "0.1.2" |
---|
62 | |
---|
63 | # URLs for SVN repos |
---|
64 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
65 | DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER |
---|
66 | GUICOMM_URL = "svn://danse.us/sans/releases/guicomm-%s" % GUICOMM |
---|
67 | GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME |
---|
68 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
69 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
70 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
71 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
72 | PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK |
---|
73 | |
---|
74 | |
---|
75 | def check_system(): |
---|
76 | """ |
---|
77 | Checks that the system has the necessary modules. |
---|
78 | """ |
---|
79 | try: |
---|
80 | import wx |
---|
81 | except: |
---|
82 | logging.error("wxpython missing") |
---|
83 | |
---|
84 | try: |
---|
85 | import matplotlib |
---|
86 | except: |
---|
87 | logging.error("matplotlib missing") |
---|
88 | |
---|
89 | try: |
---|
90 | import numpy |
---|
91 | except: |
---|
92 | logging.error("numpy missing") |
---|
93 | |
---|
94 | try: |
---|
95 | import scipy |
---|
96 | except: |
---|
97 | logging.error("scipy missing") |
---|
98 | |
---|
99 | if os.system("gcc -dumpversion")==1: |
---|
100 | logging.error("missing mingw") |
---|
101 | |
---|
102 | def install_pkg(install_dir, setup_dir, url): |
---|
103 | """ |
---|
104 | Check a package out and install it |
---|
105 | |
---|
106 | @param install_dir: directory to put the code in |
---|
107 | @param setup_dir: relative location of the setup.py script |
---|
108 | @param url: URL of the SVN repo |
---|
109 | """ |
---|
110 | if not os.path.isdir(install_dir): |
---|
111 | os.mkdir(install_dir) |
---|
112 | os.chdir(install_dir) |
---|
113 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
114 | os.chdir(setup_dir) |
---|
115 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
116 | os.system("%s setup.py -q install" % PYTHON) |
---|
117 | |
---|
118 | def checkout(release=False): |
---|
119 | """ |
---|
120 | Check the SansView code out |
---|
121 | """ |
---|
122 | wd = os.getcwd() |
---|
123 | |
---|
124 | os.chdir(wd) |
---|
125 | if release: |
---|
126 | install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL) |
---|
127 | else: |
---|
128 | install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels") |
---|
129 | |
---|
130 | os.chdir(wd) |
---|
131 | if release: |
---|
132 | install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL) |
---|
133 | else: |
---|
134 | install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader") |
---|
135 | |
---|
136 | os.chdir(wd) |
---|
137 | if release: |
---|
138 | install_pkg(".", "guicomm-%s" % GUICOMM, GUICOMM_URL) |
---|
139 | else: |
---|
140 | install_pkg(".", "guicomm", "svn://danse.us/sans/trunk/guicomm") |
---|
141 | |
---|
142 | os.chdir(wd) |
---|
143 | if release: |
---|
144 | install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
145 | else: |
---|
146 | install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe") |
---|
147 | |
---|
148 | os.chdir(wd) |
---|
149 | if release: |
---|
150 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
151 | else: |
---|
152 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
153 | |
---|
154 | os.chdir(wd) |
---|
155 | if release: |
---|
156 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
157 | else: |
---|
158 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
159 | |
---|
160 | os.chdir(wd) |
---|
161 | if release: |
---|
162 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
163 | else: |
---|
164 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
165 | |
---|
166 | #TODO: need a release version of PARK |
---|
167 | os.chdir(wd) |
---|
168 | if release: |
---|
169 | install_pkg(".", "park-1.2", PARK_URL) |
---|
170 | else: |
---|
171 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
172 | |
---|
173 | os.chdir(wd) |
---|
174 | if release: |
---|
175 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
176 | else: |
---|
177 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
178 | |
---|
179 | def prepare(wipeout = False): |
---|
180 | """ |
---|
181 | Prepare the build |
---|
182 | """ |
---|
183 | # Remove existing libraries |
---|
184 | if wipeout == True: |
---|
185 | print "Deleting old modules" |
---|
186 | from distutils.sysconfig import get_python_lib |
---|
187 | libdir = get_python_lib() |
---|
188 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
189 | os.path.join(libdir, 'data_util'), |
---|
190 | os.path.join(libdir, 'DataLoader'), |
---|
191 | os.path.join(libdir, 'park'), |
---|
192 | os.path.join(libdir, 'sans'), |
---|
193 | os.path.join(libdir, 'sans_extension'), |
---|
194 | ] |
---|
195 | for d in old_dirs: |
---|
196 | if os.path.isdir(d): |
---|
197 | shutil.rmtree(d) |
---|
198 | |
---|
199 | # Create a fresh installation folder |
---|
200 | if os.path.isdir(INSTALL_FOLDER): |
---|
201 | shutil.rmtree(INSTALL_FOLDER) |
---|
202 | |
---|
203 | os.mkdir(INSTALL_FOLDER) |
---|
204 | |
---|
205 | # Check that the dependencies are properly installed |
---|
206 | check_system() |
---|
207 | |
---|
208 | # Move to the installation folder |
---|
209 | os.chdir(INSTALL_FOLDER) |
---|
210 | |
---|
211 | def warning(): |
---|
212 | """ |
---|
213 | The build script will wipe out part of the site-packages. |
---|
214 | Ask the user whether he wants to proceed. |
---|
215 | """ |
---|
216 | print "WARNING!\n" |
---|
217 | print "In order to build a clean version of SansView, this script" |
---|
218 | print "deletes anything found under site-packages for the following" |
---|
219 | print "modules:" |
---|
220 | print " - danse" |
---|
221 | print " - data_util" |
---|
222 | print " - DataLoader" |
---|
223 | print " - park" |
---|
224 | print " - sans" |
---|
225 | print " - sans_extension\n" |
---|
226 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
227 | return answer.upper()=="Y" |
---|
228 | |
---|
229 | if __name__ == "__main__": |
---|
230 | print "Build script for SansView %s" % SANSVIEW |
---|
231 | |
---|
232 | if len(sys.argv)==1: |
---|
233 | # If there is no argument, build the installer |
---|
234 | sys.argv.append("-i") |
---|
235 | |
---|
236 | if len(sys.argv)>1: |
---|
237 | # Help |
---|
238 | if sys.argv[1]=="-h": |
---|
239 | print "Usage:" |
---|
240 | print " python build_sansview [command]\n" |
---|
241 | print "[command] can be any of the following:" |
---|
242 | print " -h: lists the command line options" |
---|
243 | print " -r: Builds a SansView using the released modules" |
---|
244 | print " -t: Builds SansView from the trunk" |
---|
245 | print " -i: Builds an installer from the release version [Windows only]" |
---|
246 | print " -n: Print out the dependencies for the release notes" |
---|
247 | elif sys.argv[1]=="-n": |
---|
248 | # Print out release URLs |
---|
249 | print SANSMODELS_URL |
---|
250 | print DATALOADER_URL |
---|
251 | print GUICOMM_URL |
---|
252 | print GUIFRAME_URL |
---|
253 | print PLOTTOOLS_URL |
---|
254 | print UTIL_URL |
---|
255 | print SANSVIEW_URL |
---|
256 | print PARK_INTEG_URL |
---|
257 | print PARK_URL |
---|
258 | else: |
---|
259 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
260 | |
---|
261 | # Prepare installation folder |
---|
262 | prepare(warning()) |
---|
263 | |
---|
264 | # Check the command line argument |
---|
265 | if sys.argv[1]=="-t": |
---|
266 | logging.info("Building trunk version") |
---|
267 | checkout() |
---|
268 | elif sys.argv[1]=="-r": |
---|
269 | logging.info("Building release version") |
---|
270 | checkout(True) |
---|
271 | elif sys.argv[1]=="-i": |
---|
272 | logging.info("Building release version") |
---|
273 | checkout(True) |
---|
274 | if sys.platform=='win32': |
---|
275 | logging.info("Building installer from release version") |
---|
276 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
277 | os.system("%s setup_exe.py -q py2exe" % PYTHON) |
---|
278 | os.system("%s/Q installer.iss" % INNO) |
---|
279 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
280 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
281 | |
---|
282 | |
---|