source: branches/anuga_1_2_1/create_distribution.py @ 8086

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

Updated

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