source: branches/anuga_1_2_1/create_distribution.py @ 8088

Last change on this file since 8088 was 8088, checked in by habili, 13 years ago

import get_revision_number directly

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