source: trunk/create_distribution.py @ 8697

Last change on this file since 8697 was 7901, checked in by wilsonr, 14 years ago

Changes to match the windows installer creator.

File size: 8.3 KB
Line 
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
23import sys
24import os
25import tempfile
26
27from anuga.utilities.system_tools import get_user_name, get_host_name
28from anuga.abstract_2d_finite_volumes.util import get_revision_number
29from anuga.abstract_2d_finite_volumes.util import store_version_info
30from anuga.config import major_revision
31from dirs_to_distribute import dirmap
32from anuga.utilities.data_audit_wrapper import IP_verified
33
34
35if 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
40def 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
51def 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
84def xlog(msg):
85    """Log a message and print to console."""
86
87    print(msg)
88    #log(msg)
89
90
91# line separator
92lsep = '-' * 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
101svn_revision = get_revision_number()
102
103anuga_release_number = get_release_number()
104anuga_release_name = 'anuga-%s' % anuga_release_number
105
106distro_filename = '%s.tgz' % anuga_release_name
107
108xlog(lsep)
109xlog('Creating %s' % anuga_release_name)
110xlog(lsep)
111
112######
113# Create directory for this release.
114# It will be named like
115#        anuga_release_1.2.3
116######
117
118release_area = os.path.join('~', 'anuga_releases')
119release_area = os.path.expanduser(release_area)
120do_cmd('mkdir -p %s' % release_area)
121
122release_dir = os.path.join(release_area, anuga_release_name )
123do_cmd('mkdir -p %s' % release_dir)
124
125######
126# Create temporary area for svn to export source files
127######
128
129distro_dir = tempfile.mktemp()
130do_cmd('mkdir -p %s' % distro_dir)
131
132######
133# Get the ANUGA directories flagged for distribution
134######
135
136for 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
143store_version_info(destination_path=distro_dir+'/anuga', verbose=True)
144
145######
146# IP Data Audit
147######
148
149xlog('Verifying data IP')
150if 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
159print(lsep)
160xlog('Preparing User Manual (see update_anuga_user_manual.log)')
161print(lsep)
162do_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
167release_name = 'anuga_user_manual-%s.pdf' % anuga_release_number
168do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_user_manual.pdf '
169           '%s/%s' % (distro_dir, release_name))
170
171release_name = 'anuga_installation_guide-%s.pdf' % anuga_release_number
172do_cmd('/bin/mv anuga_core/documentation/user_manual/'
173           'anuga_installation_guide.pdf %s/%s' % (distro_dir, release_name))
174
175release_name = 'anuga_whats_new-%s.pdf' % anuga_release_number
176do_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
183do_cmd('cd %s; tar cfz %s *' % (distro_dir, distro_filename))
184
185######
186# Move distro to release area
187######
188
189do_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
201xlog('')
202xlog(lsep)
203xlog('Creating Windows installer files')
204xlog(lsep)
205
206root = os.getcwd()
207from installation_files.windows.installer import create_config
208
209os.chdir('installation_files/windows')
210
211# Create ANUGA dir for NSI installer
212try:
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'))
217except:
218    pass
219
220# and unpack ANUGA into it
221do_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
225anuga_viewer_folder = 'anuga_viewer'
226python = 'python-2.5.4.msi'
227numpy = 'numpy-1.3.0-win32-superpack-python2.5.exe'
228scientific_python = 'ScientificPython-2.9.0.win32-py2.5.exe'
229matplotlib = 'matplotlib-0.99.0.win32-py2.5.exe'
230netcdf_folder = 'netcdf'
231mingw = 'MinGW-5.1.6.exe'
232
233# Generate NSI file
234create_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
241do_cmd('cd %s; /bin/rm -rf windows_installer' % release_dir)
242
243# Create subdirectories for windows installer
244do_cmd('cd %s; mkdir -p windows_installer/files' % release_dir)
245
246# Copy installion scrips and imagery across
247do_cmd('cp *.bmp *.nsh *.nsi *.ico %s/windows_installer' % release_dir)
248
249# Copy actual files used by Windows installer across
250do_cmd('cd files; cp -r * %s/windows_installer/files' % release_dir)
251
252# Come back to starting directory
253os.chdir(root)
254
255# Grab license file from anuga_core and copy to installer
256do_cmd('cp anuga_core/source/anuga/LICENSE.txt %s/windows_installer/files'
257       % release_dir)
258
259xlog('NSI installer created')
260
261######
262# Print list of release files
263######
264
265xlog('Done')
266print('')
267print('')
268print(lsep)
269xlog('The release files are in %s:' % release_dir)
270os.system('ls -la %s' % release_dir)
271print(lsep)
272print('')
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
290if 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
308xlog('Remember to update')
309xlog('    anuga_whats_new.tex')
310xlog('    sourceforge')
311xlog('    code.google.com')
Note: See TracBrowser for help on using the repository browser.