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