"""Create a distribution of ANUGA from latest revision This script is assumed to be run in the root directory of anuga from a working sandpit connected to svn It will create a distribution of ANUGA from the version which is currently checked out. To use the latest version run svn up before running this script. To use a specific revision (2187, say) run svn up -r 2187 first assuming that create_distribution.py (this script) and anything it depends on still work for that revision. This script works only on Linux! """ import sys import os import tempfile from anuga.utilities.system_tools import get_user_name, get_host_name from anuga.abstract_2d_finite_volumes.util import get_revision_number from anuga.abstract_2d_finite_volumes.util import store_version_info from anuga.config import major_revision from dirs_to_distribute import dirmap from anuga.utilities.data_audit_wrapper import IP_verified if sys.platform == 'win32': msg = ('This script is not written for Windows. ' 'Please run it on a Unix platform') raise Exception(msg) def do_cmd(cmd, blind=True): """Execute command. Ignore errors if blind=True.""" try: xlog(cmd) os.system(cmd) except: if not blind: raise def get_release_number(): """Get release information and create release name. Get release numbers from the current directory. Returns a string which is of the form 'anuga-X-Y-Z' where X is the major release number, Y is the minor and Z is the bug number. """ curr_dir = os.getcwd() curr_dir = os.path.basename(curr_dir) split_dir = curr_dir.split('_') if len(split_dir) < 2: abort('You must run this script in an ANUGA branch directory: ' 'anuga_X_Y[_Z].') if split_dir[0] != 'anuga': abort('You must run this script in an ANUGA branch directory: ' 'anuga_X_Y[_Z].') major = split_dir[1] if len(split_dir) < 3: minor = '0' else: minor = split_dir[2] if len(split_dir) < 4: bug = '0' else: bug = split_dir[3] return '%s.%s.%s' % (major, minor, bug) def xlog(msg): """Log a message and print to console.""" print(msg) #log(msg) # line separator lsep = '-' * 72 ###### # Get svn revision number and create file with version info for release. # This will mean that the version currently checked out is the one which # will be released. ###### svn_revision = get_revision_number() anuga_release_number = get_release_number() anuga_release_name = 'anuga-%s' % anuga_release_number distro_filename = '%s.tgz' % anuga_release_name xlog(lsep) xlog('Creating %s' % anuga_release_name) xlog(lsep) ###### # Create directory for this release. # It will be named like # anuga_release_1.2.3 ###### release_area = os.path.join('~', 'anuga_releases') release_area = os.path.expanduser(release_area) do_cmd('mkdir -p %s' % release_area) release_dir = os.path.join(release_area, anuga_release_name ) do_cmd('mkdir -p %s' % release_dir) ###### # Create temporary area for svn to export source files ###### distro_dir = tempfile.mktemp() do_cmd('mkdir -p %s' % distro_dir) ###### # Get the ANUGA directories flagged for distribution ###### for source in dirmap: destination = os.path.join(distro_dir, dirmap[source]) do_cmd('svn export -r %d --quiet %s %s' % (svn_revision, source, destination)) # Store file with revision info for use with get_revision_number store_version_info(destination_path=distro_dir+'/anuga', verbose=True) ###### # IP Data Audit ###### xlog('Verifying data IP') if not IP_verified(distro_dir, verbose=True): msg = ('Files have not been verified for IP.\n' 'Each data file must have a license file with it.') raise Exception(msg) ###### # Compile and bundle up the LaTeX documentation ###### print(lsep) xlog('Preparing User Manual (see update_anuga_user_manual.log)') print(lsep) do_cmd('cd anuga_core/documentation/user_manual; ' 'python update_anuga_user_manual.py --no_html ' '1>update_anuga_user_manual.log 2>/dev/null', blind=False) # Copy to distro_dir to become part of one tarball release_name = 'anuga_user_manual-%s.pdf' % anuga_release_number do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_user_manual.pdf ' '%s/%s' % (distro_dir, release_name)) release_name = 'anuga_installation_guide-%s.pdf' % anuga_release_number do_cmd('/bin/mv anuga_core/documentation/user_manual/' 'anuga_installation_guide.pdf %s/%s' % (distro_dir, release_name)) release_name = 'anuga_whats_new-%s.pdf' % anuga_release_number do_cmd('/bin/mv anuga_core/documentation/user_manual/anuga_whats_new.pdf %s/%s' % (distro_dir, release_name)) ###### # Zip everything up ###### do_cmd('cd %s; tar cfz %s *' % (distro_dir, distro_filename)) ###### # Move distro to release area ###### do_cmd('/bin/mv %s/*.tgz %s' % (distro_dir, release_dir) ) ###### # Clean up ###### # do_cmd('/bin/rm -rf %s/*' % distro_dir) ###### # Generate Windows installer config.sh ###### xlog('') xlog(lsep) xlog('Creating Windows installer files') xlog(lsep) root = os.getcwd() from installation_files.windows.installer import create_config os.chdir('installation_files/windows') # Create ANUGA dir for NSI installer try: os.mkdir(os.path.join('files', anuga_release_name)) os.mkdir(os.path.join('files', 'anuga_viewer')) os.mkdir(os.path.join('files', 'prereqs')) os.mkdir(os.path.join('files', 'prereqs', 'netcdf')) except: pass # and unpack ANUGA into it do_cmd('cd files/%s; tar xfz %s/%s' % (anuga_release_name, release_dir, distro_filename)) # Must be replaced by local folder to where SourceForge version is downloaded anuga_viewer_folder = 'anuga_viewer' python = 'python-2.5.4.msi' numpy = 'numpy-1.3.0-win32-superpack-python2.5.exe' scientific_python = 'ScientificPython-2.9.0.win32-py2.5.exe' matplotlib = 'matplotlib-0.99.0.win32-py2.5.exe' netcdf_folder = 'netcdf' mingw = 'MinGW-5.1.6.exe' # Generate NSI file create_config(anuga_release_number, anuga_release_name, anuga_viewer_folder, python, numpy, scientific_python, matplotlib, netcdf_folder, mingw) # Package up files necessary to compile the installer on Windows and # move to release area # Cleanup in case there was something left from a previous attempt do_cmd('cd %s; /bin/rm -rf windows_installer' % release_dir) # Create subdirectories for windows installer do_cmd('cd %s; mkdir -p windows_installer/files' % release_dir) # Copy installion scrips and imagery across do_cmd('cp *.bmp *.nsh *.nsi *.ico %s/windows_installer' % release_dir) # Copy actual files used by Windows installer across do_cmd('cd files; cp -r * %s/windows_installer/files' % release_dir) # Come back to starting directory os.chdir(root) # Grab license file from anuga_core and copy to installer do_cmd('cp anuga_core/source/anuga/LICENSE.txt %s/windows_installer/files' % release_dir) xlog('NSI installer created') ###### # Print list of release files ###### xlog('Done') print('') print('') print(lsep) xlog('The release files are in %s:' % release_dir) os.system('ls -la %s' % release_dir) print(lsep) print('') ###### # Copy release to various destinations ###### # # Copy to the ANU # #s = 'rsync -avz %s/* ole@datamining.anu.edu.au:public_html/software/anuga/%s' %(release_dir, 'anuga_%s' %revision) # s = 'scp -r %s ole@datamining.anu.edu.au:public_html/software/anuga' %(release_dir) # print s # os.system(s) ###### # Throw away code to drop all files into the RAMP download area # This is hardwired for Ole but shows how such a thing can be done # automatically. ###### if get_user_name() == 'ole' and get_host_name() == 'nautilus': answer = raw_input('Do you want to move this to the GA NAS? Y/N [Y]') if answer.lower() == 'n': import sys; sys.exit() print 'Attempt to rsync data to perlite and datamining' # Copy to Georisk s = ('rsync -avz %s/* onielsen@cyclone:georisk/downloads/ANUGA_install/%s' % (release_dir, 'anuga_%s' % anuga_release_number)) print s os.system(s) #os.system('scp %s/*.pdf onielsen@cyclone:/d/cit/1/cit/risk_assessment_methods_project/downloads/ANUGA_install' %release_dir)# ###### # Little reminders ###### xlog('Remember to update') xlog(' anuga_whats_new.tex') xlog(' sourceforge') xlog(' code.google.com')