1 | """Create a distribution of ANUGA from latest revision |
---|
2 | |
---|
3 | This script is assumed to be run in the root directory of anuga |
---|
4 | from a working sandpit connected to svn |
---|
5 | |
---|
6 | It will create a distribution of ANUGA from the version which is |
---|
7 | currently checked out. |
---|
8 | |
---|
9 | To use the latest version run |
---|
10 | |
---|
11 | svn up |
---|
12 | |
---|
13 | before running this script. To use a specific revision (2187, say) run |
---|
14 | |
---|
15 | svn up -r 2187 |
---|
16 | |
---|
17 | first assuming that create_distribution.py (this script) and anything |
---|
18 | it depends on still work for that revision. |
---|
19 | |
---|
20 | This script works only on Linux! |
---|
21 | """ |
---|
22 | |
---|
23 | import sys |
---|
24 | import os |
---|
25 | import tempfile |
---|
26 | |
---|
27 | from anuga.utilities.system_tools import get_user_name, get_host_name |
---|
28 | from anuga.abstract_2d_finite_volumes.util import get_revision_number |
---|
29 | from anuga.abstract_2d_finite_volumes.util import store_version_info |
---|
30 | from anuga.config import major_revision |
---|
31 | from dirs_to_distribute import dirmap |
---|
32 | from anuga.utilities.data_audit_wrapper import IP_verified |
---|
33 | |
---|
34 | |
---|
35 | if sys.platform == 'win32': |
---|
36 | msg = ('This script is not written for Windows. ' |
---|
37 | 'Please run it on a Unix platform') |
---|
38 | raise Exception(msg) |
---|
39 | |
---|
40 | def do_cmd(cmd, blind=True): |
---|
41 | """Execute command. Ignore errors if blind=True.""" |
---|
42 | |
---|
43 | try: |
---|
44 | xlog(cmd) |
---|
45 | os.system(cmd) |
---|
46 | except: |
---|
47 | if not blind: |
---|
48 | raise |
---|
49 | |
---|
50 | |
---|
51 | def get_release_number(): |
---|
52 | """Get release information and create release name. |
---|
53 | |
---|
54 | Get release numbers from the current directory. |
---|
55 | |
---|
56 | Returns a string which is of the form 'anuga-X-Y-Z' where X is the |
---|
57 | major release number, Y is the minor and Z is the bug number. |
---|
58 | """ |
---|
59 | |
---|
60 | curr_dir = os.getcwd() |
---|
61 | curr_dir = os.path.basename(curr_dir) |
---|
62 | split_dir = curr_dir.split('_') |
---|
63 | if len(split_dir) < 2: |
---|
64 | abort('You must run this script in an ANUGA branch directory: ' |
---|
65 | 'anuga_X_Y[_Z].') |
---|
66 | if split_dir[0] != 'anuga': |
---|
67 | abort('You must run this script in an ANUGA branch directory: ' |
---|
68 | 'anuga_X_Y[_Z].') |
---|
69 | |
---|
70 | major = split_dir[1] |
---|
71 | if len(split_dir) < 3: |
---|
72 | minor = '0' |
---|
73 | else: |
---|
74 | minor = split_dir[2] |
---|
75 | |
---|
76 | if len(split_dir) < 4: |
---|
77 | bug = '0' |
---|
78 | else: |
---|
79 | bug = split_dir[3] |
---|
80 | |
---|
81 | return '%s.%s.%s' % (major, minor, bug) |
---|
82 | |
---|
83 | |
---|
84 | def xlog(msg): |
---|
85 | """Log a message and print to console.""" |
---|
86 | |
---|
87 | print(msg) |
---|
88 | #log(msg) |
---|
89 | |
---|
90 | |
---|
91 | # line separator |
---|
92 | lsep = '-' * 72 |
---|
93 | |
---|
94 | |
---|
95 | ###### |
---|
96 | # Get svn revision number and create file with version info for release. |
---|
97 | # This will mean that the version currently checked out is the one which |
---|
98 | # will be released. |
---|
99 | ###### |
---|
100 | |
---|
101 | svn_revision = get_revision_number() |
---|
102 | |
---|
103 | anuga_release_number = get_release_number() |
---|
104 | anuga_release_name = 'anuga-%s' % anuga_release_number |
---|
105 | |
---|
106 | distro_filename = '%s.tgz' % anuga_release_name |
---|
107 | |
---|
108 | xlog(lsep) |
---|
109 | xlog('Creating %s' % anuga_release_name) |
---|
110 | xlog(lsep) |
---|
111 | |
---|
112 | ###### |
---|
113 | # Create directory for this release. |
---|
114 | # It will be named like |
---|
115 | # anuga_release_1.2.3 |
---|
116 | ###### |
---|
117 | |
---|
118 | release_area = os.path.join('~', 'anuga_releases') |
---|
119 | release_area = os.path.expanduser(release_area) |
---|
120 | do_cmd('mkdir -p %s' % release_area) |
---|
121 | |
---|
122 | release_dir = os.path.join(release_area, anuga_release_name ) |
---|
123 | do_cmd('mkdir -p %s' % release_dir) |
---|
124 | |
---|
125 | ###### |
---|
126 | # Create temporary area for svn to export source files |
---|
127 | ###### |
---|
128 | |
---|
129 | distro_dir = tempfile.mktemp() |
---|
130 | do_cmd('mkdir -p %s' % distro_dir) |
---|
131 | |
---|
132 | ###### |
---|
133 | # Get the ANUGA directories flagged for distribution |
---|
134 | ###### |
---|
135 | |
---|
136 | for source in dirmap: |
---|
137 | destination = os.path.join(distro_dir, dirmap[source]) |
---|
138 | |
---|
139 | do_cmd('svn export -r %d --quiet %s %s' |
---|
140 | % (svn_revision, source, destination)) |
---|
141 | |
---|
142 | # Store file with revision info for use with get_revision_number |
---|
143 | store_version_info(destination_path=distro_dir+'/anuga', verbose=True) |
---|
144 | |
---|
145 | ###### |
---|
146 | # IP Data Audit |
---|
147 | ###### |
---|
148 | |
---|
149 | xlog('Verifying data IP') |
---|
150 | if not IP_verified(distro_dir, verbose=True): |
---|
151 | msg = ('Files have not been verified for IP.\n' |
---|
152 | 'Each data file must have a license file with it.') |
---|
153 | raise Exception(msg) |
---|
154 | |
---|
155 | ###### |
---|
156 | # Compile and bundle up the LaTeX documentation |
---|
157 | ###### |
---|
158 | |
---|
159 | print(lsep) |
---|
160 | xlog('Preparing User Manual (see update_anuga_user_manual.log)') |
---|
161 | print(lsep) |
---|
162 | do_cmd('cd anuga_core/documentation/user_manual; ' |
---|
163 | 'python update_anuga_user_manual.py --no_html ' |
---|
164 | '1>update_anuga_user_manual.log 2>/dev/null', blind=False) |
---|
165 | |
---|
166 | # Copy to distro_dir to become part of one tarball |
---|
167 | release_name = 'anuga_user_manual-%s.pdf' % anuga_release_number |
---|
168 | do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_user_manual.pdf ' |
---|
169 | '%s/%s' % (distro_dir, release_name)) |
---|
170 | |
---|
171 | release_name = 'anuga_installation_guide-%s.pdf' % anuga_release_number |
---|
172 | do_cmd('/bin/mv anuga_core/documentation/user_manual/' |
---|
173 | 'anuga_installation_guide.pdf %s/%s' % (distro_dir, release_name)) |
---|
174 | |
---|
175 | release_name = 'anuga_whats_new-%s.pdf' % anuga_release_number |
---|
176 | do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_whats_new.pdf %s/%s' |
---|
177 | % (distro_dir, release_name)) |
---|
178 | |
---|
179 | ###### |
---|
180 | # Zip everything up |
---|
181 | ###### |
---|
182 | |
---|
183 | do_cmd('cd %s; tar cfz %s *' % (distro_dir, distro_filename)) |
---|
184 | |
---|
185 | ###### |
---|
186 | # Move distro to release area |
---|
187 | ###### |
---|
188 | |
---|
189 | do_cmd('/bin/mv %s/*.tgz %s' % (distro_dir, release_dir) ) |
---|
190 | |
---|
191 | ###### |
---|
192 | # Clean up |
---|
193 | ###### |
---|
194 | |
---|
195 | # do_cmd('/bin/rm -rf %s/*' % distro_dir) |
---|
196 | |
---|
197 | ###### |
---|
198 | # Generate Windows installer config.sh |
---|
199 | ###### |
---|
200 | |
---|
201 | xlog('') |
---|
202 | xlog(lsep) |
---|
203 | xlog('Creating Windows installer files') |
---|
204 | xlog(lsep) |
---|
205 | |
---|
206 | root = os.getcwd() |
---|
207 | from installation_files.windows.installer import create_config |
---|
208 | |
---|
209 | os.chdir('installation_files/windows') |
---|
210 | |
---|
211 | # Create ANUGA dir for NSI installer |
---|
212 | try: |
---|
213 | os.mkdir(os.path.join('files', anuga_release_name)) |
---|
214 | os.mkdir(os.path.join('files', 'anuga_viewer')) |
---|
215 | os.mkdir(os.path.join('files', 'prereqs')) |
---|
216 | os.mkdir(os.path.join('files', 'prereqs', 'netcdf')) |
---|
217 | except: |
---|
218 | pass |
---|
219 | |
---|
220 | # and unpack ANUGA into it |
---|
221 | do_cmd('cd files/%s; tar xfz %s/%s' |
---|
222 | % (anuga_release_name, release_dir, distro_filename)) |
---|
223 | |
---|
224 | # Must be replaced by local folder to where SourceForge version is downloaded |
---|
225 | anuga_viewer_folder = 'anuga_viewer' |
---|
226 | python = 'python-2.5.4.msi' |
---|
227 | numpy = 'numpy-1.3.0-win32-superpack-python2.5.exe' |
---|
228 | scientific_python = 'ScientificPython-2.9.0.win32-py2.5.exe' |
---|
229 | matplotlib = 'matplotlib-0.99.0.win32-py2.5.exe' |
---|
230 | netcdf_folder = 'netcdf' |
---|
231 | mingw = 'MinGW-5.1.6.exe' |
---|
232 | |
---|
233 | # Generate NSI file |
---|
234 | create_config(anuga_release_number, anuga_release_name, anuga_viewer_folder, |
---|
235 | python, numpy, scientific_python, matplotlib, netcdf_folder, |
---|
236 | mingw) |
---|
237 | |
---|
238 | # Package up files necessary to compile the installer on Windows and |
---|
239 | # move to release area |
---|
240 | # Cleanup in case there was something left from a previous attempt |
---|
241 | do_cmd('cd %s; /bin/rm -rf windows_installer' % release_dir) |
---|
242 | |
---|
243 | # Create subdirectories for windows installer |
---|
244 | do_cmd('cd %s; mkdir -p windows_installer/files' % release_dir) |
---|
245 | |
---|
246 | # Copy installion scrips and imagery across |
---|
247 | do_cmd('cp *.bmp *.nsh *.nsi *.ico %s/windows_installer' % release_dir) |
---|
248 | |
---|
249 | # Copy actual files used by Windows installer across |
---|
250 | do_cmd('cd files; cp -r * %s/windows_installer/files' % release_dir) |
---|
251 | |
---|
252 | # Come back to starting directory |
---|
253 | os.chdir(root) |
---|
254 | |
---|
255 | # Grab license file from anuga_core and copy to installer |
---|
256 | do_cmd('cp anuga_core/source/anuga/LICENSE.txt %s/windows_installer/files' |
---|
257 | % release_dir) |
---|
258 | |
---|
259 | xlog('NSI installer created') |
---|
260 | |
---|
261 | ###### |
---|
262 | # Print list of release files |
---|
263 | ###### |
---|
264 | |
---|
265 | xlog('Done') |
---|
266 | print('') |
---|
267 | print('') |
---|
268 | print(lsep) |
---|
269 | xlog('The release files are in %s:' % release_dir) |
---|
270 | os.system('ls -la %s' % release_dir) |
---|
271 | print(lsep) |
---|
272 | print('') |
---|
273 | |
---|
274 | ###### |
---|
275 | # Copy release to various destinations |
---|
276 | ###### |
---|
277 | |
---|
278 | # # Copy to the ANU |
---|
279 | # #s = 'rsync -avz %s/* ole@datamining.anu.edu.au:public_html/software/anuga/%s' %(release_dir, 'anuga_%s' %revision) |
---|
280 | # s = 'scp -r %s ole@datamining.anu.edu.au:public_html/software/anuga' %(release_dir) |
---|
281 | # print s |
---|
282 | # os.system(s) |
---|
283 | |
---|
284 | ###### |
---|
285 | # Throw away code to drop all files into the RAMP download area |
---|
286 | # This is hardwired for Ole but shows how such a thing can be done |
---|
287 | # automatically. |
---|
288 | ###### |
---|
289 | |
---|
290 | if get_user_name() == 'ole' and get_host_name() == 'nautilus': |
---|
291 | answer = raw_input('Do you want to move this to the GA NAS? Y/N [Y]') |
---|
292 | if answer.lower() == 'n': |
---|
293 | import sys; sys.exit() |
---|
294 | |
---|
295 | print 'Attempt to rsync data to perlite and datamining' |
---|
296 | # Copy to Georisk |
---|
297 | s = ('rsync -avz %s/* onielsen@cyclone:georisk/downloads/ANUGA_install/%s' |
---|
298 | % (release_dir, 'anuga_%s' % anuga_release_number)) |
---|
299 | print s |
---|
300 | os.system(s) |
---|
301 | |
---|
302 | #os.system('scp %s/*.pdf onielsen@cyclone:/d/cit/1/cit/risk_assessment_methods_project/downloads/ANUGA_install' %release_dir)# |
---|
303 | |
---|
304 | ###### |
---|
305 | # Little reminders |
---|
306 | ###### |
---|
307 | |
---|
308 | xlog('Remember to update') |
---|
309 | xlog(' anuga_whats_new.tex') |
---|
310 | xlog(' sourceforge') |
---|
311 | xlog(' code.google.com') |
---|