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 xlog(msg): |
---|
41 | """Log a message and print to console.""" |
---|
42 | |
---|
43 | print(msg) |
---|
44 | #log(msg) |
---|
45 | |
---|
46 | def do_cmd(cmd): |
---|
47 | """Execute command. Ignore errors.""" |
---|
48 | |
---|
49 | try: |
---|
50 | xlog(cmd) |
---|
51 | os.system(cmd) |
---|
52 | except: |
---|
53 | pass |
---|
54 | |
---|
55 | |
---|
56 | # line separator |
---|
57 | lsep = '-' * 72 |
---|
58 | |
---|
59 | |
---|
60 | ###### |
---|
61 | # Get svn revision number and create file with version info for release. |
---|
62 | # This will mean that the version currently checked out is the one which |
---|
63 | # will be released. |
---|
64 | ###### |
---|
65 | |
---|
66 | svn_revision = get_revision_number() |
---|
67 | revision = '%s_%s' % (major_revision, svn_revision) |
---|
68 | xlog('Creating ANUGA revision %s' % revision) |
---|
69 | |
---|
70 | anuga_release_name = 'anuga-%s' % revision |
---|
71 | distro_filename = '%s.tgz' % anuga_release_name |
---|
72 | |
---|
73 | ###### |
---|
74 | # Create directory for this release. |
---|
75 | # It will be named like |
---|
76 | # anuga_release_1.0beta_4824 |
---|
77 | ###### |
---|
78 | |
---|
79 | release_area = os.path.join('~', 'anuga_releases') |
---|
80 | release_area = os.path.expanduser(release_area) |
---|
81 | do_cmd('mkdir %s' % release_area) |
---|
82 | |
---|
83 | release_dir = os.path.join(release_area, anuga_release_name ) |
---|
84 | do_cmd('mkdir %s' % release_dir) |
---|
85 | |
---|
86 | ###### |
---|
87 | # Create temporary area for svn to export source files |
---|
88 | ###### |
---|
89 | |
---|
90 | distro_dir = tempfile.mktemp() |
---|
91 | do_cmd('mkdir %s' % distro_dir) |
---|
92 | |
---|
93 | ###### |
---|
94 | # Get the ANUGA directories flagged for distribution |
---|
95 | ###### |
---|
96 | |
---|
97 | for source in dirmap: |
---|
98 | destination = os.path.join(distro_dir, dirmap[source]) |
---|
99 | |
---|
100 | do_cmd('svn export -r %d --quiet %s %s' |
---|
101 | % (svn_revision, source, destination)) |
---|
102 | |
---|
103 | # Store file with revision info for use with get_revision_number |
---|
104 | store_version_info(destination_path=distro_dir+'/anuga', verbose=True) |
---|
105 | |
---|
106 | ###### |
---|
107 | # IP Data Audit |
---|
108 | ###### |
---|
109 | |
---|
110 | xlog('Verifying data IP') |
---|
111 | if not IP_verified(distro_dir, verbose=True): |
---|
112 | msg = ('Files have not been verified for IP.\n' |
---|
113 | 'Each data file must have a license file with it.') |
---|
114 | raise Exception(msg) |
---|
115 | |
---|
116 | ###### |
---|
117 | # Compile and bundle up the LaTeX documentation |
---|
118 | ###### |
---|
119 | |
---|
120 | print('') |
---|
121 | print(lsep) |
---|
122 | xlog('Preparing User Manual (see update_anuga_user_manual.log)') |
---|
123 | print(lsep) |
---|
124 | do_cmd('cd anuga_core/documentation/user_manual;' |
---|
125 | 'python update_anuga_user_manual.py --no_html ' |
---|
126 | '1>update_anuga_user_manual.log 2>/dev/null') |
---|
127 | |
---|
128 | # Copy to distro_dir to become part of one tarball |
---|
129 | release_name = 'anuga_user_manual-%s.pdf' % revision |
---|
130 | do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_user_manual.pdf ' |
---|
131 | '%s/%s' % (distro_dir, release_name)) |
---|
132 | |
---|
133 | release_name = 'anuga_installation_guide-%s.pdf' % revision |
---|
134 | do_cmd('/bin/mv anuga_core/documentation/user_manual/' |
---|
135 | 'anuga_installation_guide.pdf %s/%s' % (distro_dir, release_name) |
---|
136 | |
---|
137 | release_name = 'anuga_whats_new-%s.pdf' % revision |
---|
138 | do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_whats_new.pdf %s/%s' |
---|
139 | % (distro_dir, release_name) ) |
---|
140 | |
---|
141 | ###### |
---|
142 | # Zip everything up |
---|
143 | ###### |
---|
144 | |
---|
145 | do_cmd('cd %s;tar cvfz %s *' % (distro_dir, distro_filename)) |
---|
146 | |
---|
147 | ###### |
---|
148 | # Move distro to release area |
---|
149 | ###### |
---|
150 | |
---|
151 | do_cmd('/bin/mv %s/*.tgz %s' % (distro_dir, release_dir) ) |
---|
152 | |
---|
153 | ###### |
---|
154 | # Clean up |
---|
155 | ###### |
---|
156 | |
---|
157 | do_cmd('/bin/rm -rf %s/*' % distro_dir) |
---|
158 | |
---|
159 | ###### |
---|
160 | # Generate Windows installer |
---|
161 | ###### |
---|
162 | |
---|
163 | root = os.getcwd() |
---|
164 | from installation_files.windows.installer import create_config |
---|
165 | |
---|
166 | os.chdir('installation_files/windows') |
---|
167 | |
---|
168 | # Create ANUGA dir for NSI installer |
---|
169 | try: |
---|
170 | os.mkdir(os.path.join('files', anuga_release_name)) |
---|
171 | os.mkdir(os.path.join('files', 'anuga_viewer')) |
---|
172 | os.mkdir(os.path.join('files', 'prereqs')) |
---|
173 | os.mkdir(os.path.join('files', 'prereqs', 'netcdf')) |
---|
174 | except: |
---|
175 | pass |
---|
176 | |
---|
177 | # and unpack ANUGA into it |
---|
178 | do_cmd('cd files/%s; tar xvfz %s/%s' |
---|
179 | % (anuga_release_name, release_dir, distro_filename)) |
---|
180 | |
---|
181 | # Must be replaced by local folder to where SourceForge version is downloaded |
---|
182 | anuga_viewer_folder = 'anuga_viewer' |
---|
183 | python = 'python-2.5.4.msi' |
---|
184 | numpy = 'numpy-1.3.0-win32-superpack-python2.5.exe' |
---|
185 | scientific_python = 'ScientificPython-2.9.0.win32-py2.5.exe' |
---|
186 | matplotlib = 'matplotlib-0.99.0.win32-py2.5.exe' |
---|
187 | netcdf_folder = 'netcdf' |
---|
188 | mingw = 'MinGW-5.1.6.exe' |
---|
189 | |
---|
190 | # Generate NSI file |
---|
191 | create_config(revision, anuga_release_name, anuga_viewer_folder, python, |
---|
192 | numpy, scientific_python, matplotlib, netcdf_folder, mingw) |
---|
193 | |
---|
194 | # Package up files necessary to compile the installer on Windows and |
---|
195 | # move to release area |
---|
196 | # Cleanup in case there was something left from a previous attempt |
---|
197 | do_cmd('cd %s; /bin/rm -rf windows_installer' % release_dir) |
---|
198 | |
---|
199 | # Create subdirectories for windows installer |
---|
200 | do_cmd('cd %s; mkdir windows_installer; mkdir windows_installer/files' |
---|
201 | % release_dir) |
---|
202 | |
---|
203 | # Copy installion scrips and imagery across |
---|
204 | do_cmd('cp *.bmp *.nsh *.nsi *.ico %s/windows_installer' % release_dir) |
---|
205 | |
---|
206 | # Copy actual files used by Windows installer across |
---|
207 | do_cmd('cd files; cp -r * %s/windows_installer/files' % release_dir) |
---|
208 | |
---|
209 | # Come back to starting directory |
---|
210 | os.chdir(root) |
---|
211 | |
---|
212 | # Grab license file from anuga_core and copy to installer |
---|
213 | do_cmd('cp anuga_core/source/anuga/LICENSE.txt %s/windows_installer/files' |
---|
214 | % release_dir ) |
---|
215 | |
---|
216 | xlog('NSI installer created') |
---|
217 | |
---|
218 | ###### |
---|
219 | # Print list of release files |
---|
220 | ###### |
---|
221 | |
---|
222 | xlog('Done') |
---|
223 | print('') |
---|
224 | print('') |
---|
225 | print(lsep) |
---|
226 | xlog('The release files are in %s:' % release_dir) |
---|
227 | os.system('ls -la %s' % release_dir) |
---|
228 | print(lsep) |
---|
229 | print('') |
---|
230 | print('') |
---|
231 | |
---|
232 | |
---|
233 | ###### |
---|
234 | # Copy release to various destinations |
---|
235 | ###### |
---|
236 | # FIXME (Ole): I don't think this is the way any more |
---|
237 | # due to changes at SourceForge. |
---|
238 | |
---|
239 | answer = raw_input('Do you want to upload this to sourceforge? Y/N [Y]') |
---|
240 | if answer.lower() != 'n': |
---|
241 | |
---|
242 | print 'Uploading to sourceforge' |
---|
243 | |
---|
244 | import os, os.path |
---|
245 | release_dir = os.path.expanduser(release_dir) |
---|
246 | os.chdir(release_dir) |
---|
247 | print 'Reading from', os.getcwd() |
---|
248 | |
---|
249 | |
---|
250 | s = 'rsync -avP -e ssh *.* uniomni@frs.sourceforge.net:uploads/' |
---|
251 | print s |
---|
252 | os.system(s) |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | #from ftplib import FTP |
---|
257 | #ftp = FTP('upload.sourceforge.net') |
---|
258 | #print ftp.login() # Anonymous |
---|
259 | #print ftp.cwd('incoming') |
---|
260 | # |
---|
261 | #for filename in os.listdir('.'): |
---|
262 | # print 'Uploading %s... ' %filename, |
---|
263 | # sys.stdout.flush() |
---|
264 | # |
---|
265 | # fid=open(filename, 'rb') |
---|
266 | # print ftp.storbinary('STOR %s' %filename, fid) |
---|
267 | # fid.close() |
---|
268 | # |
---|
269 | #print 'FTP done' |
---|
270 | #print ftp.quit() |
---|
271 | |
---|
272 | print |
---|
273 | print lsep |
---|
274 | print ' ********************* NOTE *************************' |
---|
275 | print lsep |
---|
276 | print 'To complete this release you must log into' |
---|
277 | print 'http://sourceforge.net/projects/anuga as ANUGA admin' |
---|
278 | print 'and complete the process by selecting File Releases ' |
---|
279 | print 'in the admin menu there.' |
---|
280 | print lsep |
---|
281 | print |
---|
282 | print |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | # Copy to the ANU |
---|
287 | #s = 'rsync -avz %s/* ole@datamining.anu.edu.au:public_html/software/anuga/%s' %(release_dir, 'anuga_%s' %revision) |
---|
288 | s = 'scp -r %s ole@datamining.anu.edu.au:public_html/software/anuga' %(release_dir) |
---|
289 | print s |
---|
290 | os.system(s) |
---|
291 | |
---|
292 | |
---|
293 | ###### |
---|
294 | # Throw away code to drop all files into the RAMP download area |
---|
295 | # This is hardwired for Ole but shows how such a thing can be done |
---|
296 | # automatically. |
---|
297 | ###### |
---|
298 | |
---|
299 | if get_user_name() == 'ole' and get_host_name() == 'nautilus': |
---|
300 | answer = raw_input('Do you want to move this to the GA NAS? Y/N [Y]') |
---|
301 | if answer.lower() == 'n': |
---|
302 | import sys; sys.exit() |
---|
303 | |
---|
304 | print 'Attempt to rsync data to perlite and datamining' |
---|
305 | # Copy to Georisk |
---|
306 | s = 'rsync -avz %s/* onielsen@cyclone:georisk/downloads/ANUGA_install/%s' %(release_dir, 'anuga_%s' % revision) |
---|
307 | print s |
---|
308 | os.system(s) |
---|
309 | |
---|
310 | #os.system('scp %s/*.pdf onielsen@cyclone:/d/cit/1/cit/risk_assessment_methods_project/downloads/ANUGA_install' %release_dir)# |
---|
311 | |
---|
312 | print 'Remember to update' |
---|
313 | print ' anuga_whats_new.tex' |
---|
314 | print ' sourceforge' |
---|
315 | |
---|