source: branches/anuga_1_2_1/create_distribution.py @ 9737

Last change on this file since 9737 was 8090, checked in by habili, 14 years ago

Fix to create correct directories

File size: 8.2 KB
RevLine 
[3892]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
[4170]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
[5018]20   This script works only on Linux!
[3892]21"""
22
[7889]23import sys
[7489]24import os
[7889]25import tempfile
26
[8088]27from anuga.utilities.system_tools import get_user_name, get_host_name, get_revision_number
[4170]28from anuga.abstract_2d_finite_volumes.util import store_version_info
[5068]29from dirs_to_distribute import dirmap
[5018]30from anuga.utilities.data_audit_wrapper import IP_verified
[3892]31
[7506]32
[7889]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)
[3892]37
[8086]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
[7889]82def xlog(msg):
83    """Log a message and print to console."""
[3892]84
[7889]85    print(msg)
86    #log(msg)
87
88
[8086]89# line separator
[7889]90lsep = '-' * 72
[3892]91
[4168]92
[7889]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######
[4168]98
[4170]99svn_revision = get_revision_number()
[3934]100
[8086]101anuga_release_number = get_release_number()
102anuga_release_name = 'anuga-%s' % anuga_release_number
103
[7489]104distro_filename = '%s.tgz' % anuga_release_name
[3892]105
[8086]106xlog(lsep)
107xlog('Creating %s' % anuga_release_name)
108xlog(lsep)
109
[7889]110######
[4837]111# Create directory for this release.
112# It will be named like
[8086]113#        anuga_release_1.2.3
[7889]114######
[5540]115
[7889]116release_area = os.path.join('~', 'anuga_releases')
117release_area = os.path.expanduser(release_area)
[8086]118do_cmd('mkdir -p %s' % release_area)
119
[7889]120release_dir = os.path.join(release_area, anuga_release_name )
[8086]121do_cmd('mkdir -p %s' % release_dir)
[5540]122
[7889]123######
[4837]124# Create temporary area for svn to export source files
[7889]125######
[3892]126
[7889]127distro_dir = tempfile.mktemp()
[8086]128do_cmd('mkdir -p %s' % distro_dir)
[3892]129
[7889]130######
[5068]131# Get the ANUGA directories flagged for distribution
[7889]132######
[5068]133
134for source in dirmap:
[7889]135    destination = os.path.join(distro_dir, dirmap[source])
[8086]136
[7889]137    do_cmd('svn export -r %d --quiet %s %s'
138           % (svn_revision, source, destination))
[5068]139
[5016]140# Store file with revision info for use with get_revision_number
141store_version_info(destination_path=distro_dir+'/anuga', verbose=True)
[4865]142
[7889]143######
144# IP Data Audit
145######
[4865]146
[7889]147xlog('Verifying data IP')
[5028]148if not IP_verified(distro_dir, verbose=True):
[7889]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)
[5016]152
[7889]153######
[8086]154# Compile and bundle up the LaTeX documentation
[7889]155######
[5016]156
[7889]157print(lsep)
158xlog('Preparing User Manual (see update_anuga_user_manual.log)')
159print(lsep)
[8086]160do_cmd('cd anuga_core/documentation/user_manual; '
[7889]161       'python update_anuga_user_manual.py --no_html '
[8086]162           '1>update_anuga_user_manual.log 2>/dev/null', blind=False)
[7607]163
164# Copy to distro_dir to become part of one tarball
[8086]165release_name = 'anuga_user_manual-%s.pdf' % anuga_release_number
[8090]166do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_user_manual.pdf %s/%s'
167           % (distro_dir, release_name))
[7607]168
[8086]169release_name = 'anuga_installation_guide-%s.pdf' % anuga_release_number
[8090]170do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_installation_guide.pdf %s/%s'
171           % (distro_dir, release_name))
[7607]172
[8086]173release_name = 'anuga_whats_new-%s.pdf' % anuga_release_number
[7889]174do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_whats_new.pdf %s/%s'
[8090]175           % (distro_dir, release_name))
[8086]176
[7889]177######
[4802]178# Zip everything up
[7889]179######
[3987]180
[8086]181do_cmd('cd %s; tar cfz %s *' % (distro_dir, distro_filename))
[7889]182
183######
[3987]184# Move distro to release area
[7889]185######
[3987]186
[7889]187do_cmd('/bin/mv %s/*.tgz %s' % (distro_dir, release_dir) )
188
189######
[3987]190# Clean up
[7889]191######
[3987]192
[8086]193# do_cmd('/bin/rm -rf %s/*' % distro_dir)
[3987]194
[7889]195######
[8086]196# Generate Windows installer config.sh
[7889]197######
[3892]198
[8086]199xlog('')
200xlog(lsep)
201xlog('Creating Windows installer files')
202xlog(lsep)
203
[7489]204root = os.getcwd()
205from installation_files.windows.installer import create_config
[3902]206
[7489]207os.chdir('installation_files/windows')
[4531]208
[7489]209# Create ANUGA dir for NSI installer
210try:
[7889]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'))
[7489]215except:
216    pass
[4531]217
[7489]218# and unpack ANUGA into it
[8086]219do_cmd('cd files/%s; tar xfz %s/%s'
[7889]220       % (anuga_release_name, release_dir, distro_filename))
[7489]221
222# Must be replaced by local folder to where SourceForge version is downloaded
[7506]223anuga_viewer_folder = 'anuga_viewer'
[7489]224python = 'python-2.5.4.msi'
[7506]225numpy = 'numpy-1.3.0-win32-superpack-python2.5.exe'
226scientific_python = 'ScientificPython-2.9.0.win32-py2.5.exe'
[7513]227matplotlib = 'matplotlib-0.99.0.win32-py2.5.exe'
[7506]228netcdf_folder = 'netcdf'
[7610]229mingw = 'MinGW-5.1.6.exe'
[7489]230
231# Generate NSI file
[8086]232create_config(anuga_release_number, anuga_release_name, anuga_viewer_folder,
233              python, numpy, scientific_python, matplotlib, netcdf_folder,
234              mingw)
[7489]235
[8086]236# Package up files necessary to compile the installer on Windows and
[7489]237# move to release area
[7889]238# Cleanup in case there was something left from a previous attempt
239do_cmd('cd %s; /bin/rm -rf windows_installer' % release_dir)
[8086]240
[7489]241# Create subdirectories for windows installer
[8086]242do_cmd('cd %s; mkdir -p windows_installer/files' % release_dir)
[7489]243
244# Copy installion scrips and imagery across
[7889]245do_cmd('cp *.bmp *.nsh *.nsi *.ico %s/windows_installer' % release_dir)
[7489]246
247# Copy actual files used by Windows installer across
[7889]248do_cmd('cd files; cp -r * %s/windows_installer/files' % release_dir)
[7489]249
250# Come back to starting directory
251os.chdir(root)
[8086]252
[7489]253# Grab license file from anuga_core and copy to installer
[7889]254do_cmd('cp anuga_core/source/anuga/LICENSE.txt %s/windows_installer/files'
[8086]255       % release_dir)
[7489]256
[7889]257xlog('NSI installer created')
[7489]258
[7889]259######
260# Print list of release files
261######
[7489]262
[7889]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('')
[3922]271
[7889]272######
[4837]273# Copy release to various destinations
[7889]274######
[7489]275
[8086]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)
[3934]281
[7889]282######
[3934]283# Throw away code to drop all files into the RAMP download area
[4532]284# This is hardwired for Ole but shows how such a thing can be done
285# automatically.
[7889]286######
[3934]287
[3937]288if get_user_name() == 'ole' and get_host_name() == 'nautilus':
[6426]289    answer = raw_input('Do you want to move this to the GA NAS? Y/N [Y]')
[4802]290    if answer.lower() == 'n':
291        import sys; sys.exit()
292
[4531]293    print 'Attempt to rsync data to perlite and datamining'
[5746]294    # Copy to Georisk
[8086]295    s = ('rsync -avz %s/* onielsen@cyclone:georisk/downloads/ANUGA_install/%s'
296         % (release_dir, 'anuga_%s' % anuga_release_number))
[3937]297    print s
[7889]298    os.system(s)
[8086]299
[7889]300    #os.system('scp %s/*.pdf onielsen@cyclone:/d/cit/1/cit/risk_assessment_methods_project/downloads/ANUGA_install' %release_dir)#
[8086]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.