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 shutil |
---|
27 | import logging |
---|
28 | |
---|
29 | # Installation folder |
---|
30 | import time |
---|
31 | timestamp = int(time.time()) |
---|
32 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
33 | |
---|
34 | logging.basicConfig(level=logging.INFO, |
---|
35 | format='%(asctime)s %(levelname)s %(message)s', |
---|
36 | filename='build_%s.log' % str(timestamp), |
---|
37 | filemode='w') |
---|
38 | |
---|
39 | CWD = os.getcwd() |
---|
40 | PYTHON = "c:\python25\python" |
---|
41 | SVN = "svn" |
---|
42 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
43 | |
---|
44 | # Release version 0.1.0 |
---|
45 | SANSMODELS = "0.4.2" |
---|
46 | DATALOADER = "0.2.1" |
---|
47 | GUICOMM = "0.1.1" |
---|
48 | GUIFRAME = "0.1.4" |
---|
49 | SANSVIEW = "0.1.0" |
---|
50 | PLOTTOOLS = "0.1.3" |
---|
51 | UTIL = "0.1" |
---|
52 | PARK = "1.2.x" |
---|
53 | PARK_INTEG = "0.1.0" |
---|
54 | |
---|
55 | # URLs for SVN repos |
---|
56 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
57 | DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER |
---|
58 | GUICOMM_URL = "svn://danse.us/sans/releases/guicomm-%s" % GUICOMM |
---|
59 | GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME |
---|
60 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
61 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
62 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
63 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
64 | #TODO: need to use the release branch of PARK once it is created |
---|
65 | PARK_URL = "svn://danse.us/park/branches/park-1.2" |
---|
66 | |
---|
67 | |
---|
68 | def check_system(): |
---|
69 | """ |
---|
70 | Checks that the system has the necessary modules. |
---|
71 | """ |
---|
72 | try: |
---|
73 | import wx |
---|
74 | except: |
---|
75 | logging.error("wxpython missing") |
---|
76 | |
---|
77 | try: |
---|
78 | import matplotlib |
---|
79 | except: |
---|
80 | logging.error("matplotlib missing") |
---|
81 | |
---|
82 | try: |
---|
83 | import numpy |
---|
84 | except: |
---|
85 | logging.error("numpy missing") |
---|
86 | |
---|
87 | try: |
---|
88 | import scipy |
---|
89 | except: |
---|
90 | logging.error("scipy missing") |
---|
91 | |
---|
92 | if os.system("gcc -dumpversion")==1: |
---|
93 | logging.error("missing mingw") |
---|
94 | |
---|
95 | def install_pkg(install_dir, setup_dir, url): |
---|
96 | """ |
---|
97 | Check a package out and install it |
---|
98 | |
---|
99 | @param install_dir: directory to put the code in |
---|
100 | @param setup_dir: relative location of the setup.py script |
---|
101 | @param url: URL of the SVN repo |
---|
102 | """ |
---|
103 | if not os.path.isdir(install_dir): |
---|
104 | os.mkdir(install_dir) |
---|
105 | os.chdir(install_dir) |
---|
106 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
107 | os.chdir(setup_dir) |
---|
108 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
109 | os.system("%s setup.py -q install" % PYTHON) |
---|
110 | |
---|
111 | def checkout(release=False): |
---|
112 | """ |
---|
113 | Check the SansView code out |
---|
114 | """ |
---|
115 | wd = os.getcwd() |
---|
116 | |
---|
117 | os.chdir(wd) |
---|
118 | if release: |
---|
119 | install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL) |
---|
120 | else: |
---|
121 | install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels") |
---|
122 | |
---|
123 | os.chdir(wd) |
---|
124 | if release: |
---|
125 | install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL) |
---|
126 | else: |
---|
127 | install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader") |
---|
128 | |
---|
129 | os.chdir(wd) |
---|
130 | if release: |
---|
131 | install_pkg(".", "guicomm-%s" % GUICOMM, GUICOMM_URL) |
---|
132 | else: |
---|
133 | install_pkg(".", "guicomm", "svn://danse.us/sans/trunk/guicomm") |
---|
134 | |
---|
135 | os.chdir(wd) |
---|
136 | if release: |
---|
137 | install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
138 | else: |
---|
139 | install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe") |
---|
140 | |
---|
141 | os.chdir(wd) |
---|
142 | if release: |
---|
143 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
144 | else: |
---|
145 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
146 | |
---|
147 | os.chdir(wd) |
---|
148 | if release: |
---|
149 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
150 | else: |
---|
151 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
152 | |
---|
153 | os.chdir(wd) |
---|
154 | if release: |
---|
155 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
156 | else: |
---|
157 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
158 | |
---|
159 | #TODO: need a release version of PARK |
---|
160 | os.chdir(wd) |
---|
161 | if release: |
---|
162 | install_pkg(".", "park-1.2", PARK_URL) |
---|
163 | else: |
---|
164 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
165 | |
---|
166 | os.chdir(wd) |
---|
167 | if release: |
---|
168 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
169 | else: |
---|
170 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
171 | |
---|
172 | def prepare(): |
---|
173 | """ |
---|
174 | Prepare the build |
---|
175 | """ |
---|
176 | # Remove existing libraries |
---|
177 | from distutils.sysconfig import get_python_lib |
---|
178 | libdir = get_python_lib() |
---|
179 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
180 | os.path.join(libdir, 'data_util'), |
---|
181 | os.path.join(libdir, 'DataLoader'), |
---|
182 | os.path.join(libdir, 'park'), |
---|
183 | os.path.join(libdir, 'sans'), |
---|
184 | os.path.join(libdir, 'sans_extension'), |
---|
185 | ] |
---|
186 | for d in old_dirs: |
---|
187 | if os.path.isdir(d): |
---|
188 | shutil.rmtree(d) |
---|
189 | |
---|
190 | # Create a fresh installation folder |
---|
191 | if os.path.isdir(INSTALL_FOLDER): |
---|
192 | shutil.rmtree(INSTALL_FOLDER) |
---|
193 | |
---|
194 | os.mkdir(INSTALL_FOLDER) |
---|
195 | |
---|
196 | # Check that the dependencies are properly installed |
---|
197 | check_system() |
---|
198 | |
---|
199 | # Move to the installation folder |
---|
200 | os.chdir(INSTALL_FOLDER) |
---|
201 | |
---|
202 | if __name__ == "__main__": |
---|
203 | import sys |
---|
204 | |
---|
205 | print "Build script for SansView %s" % SANSVIEW |
---|
206 | |
---|
207 | if len(sys.argv)==1: |
---|
208 | # If there is no argument, build the installer |
---|
209 | sys.argv.append("-i") |
---|
210 | |
---|
211 | if len(sys.argv)>1: |
---|
212 | # Help |
---|
213 | if sys.argv[1]=="-h": |
---|
214 | print "Usage:" |
---|
215 | print " python build_sansview [command]\n" |
---|
216 | print "[command] can be any of the following:" |
---|
217 | print " -h: lists the command line options" |
---|
218 | print " -r: Builds a SansView using the released modules" |
---|
219 | print " -t: Builds SansView from the trunk" |
---|
220 | print " -i: Builds an installer from the release version" |
---|
221 | print " -n: Print out the dependencies for the release notes" |
---|
222 | elif sys.argv[1]=="-n": |
---|
223 | # Print out release URLs |
---|
224 | print SANSMODELS_URL |
---|
225 | print DATALOADER_URL |
---|
226 | print GUICOMM_URL |
---|
227 | print GUIFRAME_URL |
---|
228 | print PLOTTOOLS_URL |
---|
229 | print UTIL_URL |
---|
230 | print SANSVIEW_URL |
---|
231 | print PARK_INTEG |
---|
232 | print PARK_URL |
---|
233 | else: |
---|
234 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
235 | # Prepare installation folder |
---|
236 | prepare() |
---|
237 | |
---|
238 | # Check the command line argument |
---|
239 | if sys.argv[1]=="-t": |
---|
240 | logging.info("Building trunk version") |
---|
241 | checkout() |
---|
242 | elif sys.argv[1]=="-r": |
---|
243 | logging.info("Building release version") |
---|
244 | checkout(True) |
---|
245 | elif sys.argv[1]=="-i": |
---|
246 | logging.info("Building release version") |
---|
247 | checkout(True) |
---|
248 | logging.info("Building installer from release version") |
---|
249 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
250 | os.system("%s setup_exe.py -q py2exe" % PYTHON) |
---|
251 | os.system("%s/Q installer.iss" % INNO) |
---|
252 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
253 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
254 | |
---|
255 | |
---|