Changeset 4170


Ignore:
Timestamp:
Jan 11, 2007, 2:38:03 PM (18 years ago)
Author:
ole
Message:

Implemented stored revision information for distributions and allowed get_revision_number to get that information from either stored file or svn as per ticket:125

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r4160 r4170  
    11531153        warnings.resetwarnings()
    11541154   
    1155     def test_get_version_info(self):
    1156         info = get_version_info()
    1157        
    1158         fields = info.split(':')
    1159         assert fields[0].startswith('Revision')
    1160 
    1161         try:
    1162             int(fields[1])
    1163         except:
    1164             msg = 'Revision number must be an integer. I got %s' %fields[1]
    1165             msg += 'Chech that the command svn is on the system path'
    1166             raise Exception(msg)               
     1155    def test_get_revision_number(self):
     1156        """test_get_revision_number(self):
     1157
     1158        Test that revision number can be retrieved.
     1159        """
     1160       
     1161        n = get_revision_number()
     1162        assert n>=0
     1163
     1164
    11671165       
    11681166    def test_add_directories(self):
     
    12071205
    12081206       
     1207    def test_add_directories(self):
     1208       
     1209        import tempfile
     1210        root_dir = tempfile.mkdtemp('_test_util', 'test_util_')
     1211        directories = ['ja','ne','ke']
     1212        kens_dir = add_directories(root_dir, directories)
     1213        assert kens_dir == root_dir + sep + 'ja' + sep + 'ne' + \
     1214               sep + 'ke'
     1215        assert access(root_dir,F_OK)
     1216
     1217        add_directories(root_dir, directories)
     1218        assert access(root_dir,F_OK)
     1219       
     1220        #clean up!
     1221        os.rmdir(kens_dir)
     1222        os.rmdir(root_dir + sep + 'ja' + sep + 'ne')
     1223        os.rmdir(root_dir + sep + 'ja')
     1224        os.rmdir(root_dir)
     1225
     1226    def test_add_directories_bad(self):
     1227       
     1228        import tempfile
     1229        root_dir = tempfile.mkdtemp('_test_util', 'test_util_')
     1230        directories = ['/\/!@#@#$%^%&*((*:*:','ne','ke']
     1231       
     1232        try:
     1233            kens_dir = add_directories(root_dir, directories)
     1234        except OSError:
     1235            pass
     1236        else:
     1237            msg = 'bad dir name should give OSError'
     1238            raise Exception(msg)   
     1239           
     1240        #clean up!
     1241        os.rmdir(root_dir)
     1242
     1243    def test_check_list(self):
     1244
     1245        check_list(['stage','xmomentum'])
     1246
    12091247       
    12101248#-------------------------------------------------------------
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4168 r4170  
    534534        fid.write(stuff)
    535535
    536 def get_version_info():
    537     """gets the version number of the SVN
     536def get_revision_number():
     537    """Get the version number of the SVN
    538538    NOTE: This requires that the command svn is on the system PATH
    539539    (simply aliasing svn to the binary will not work)
    540540    """
    541541
     542    # Create dummy info
     543    #info = 'Revision: Version info could not be obtained.'
     544    #info += 'A command line version of svn must be availbable '
     545    #info += 'on the system PATH, access to the subversion '
     546    #info += 'repository is necessary and the output must '
     547    #info += 'contain a line starting with "Revision:"'
     548   
     549
    542550    #FIXME (Ole): Change this so that svn info is attempted first.
    543551    # If that fails, try to read a stored file with that same info (this would be created by e.g. the release script). Failing that, throw an exception.
    544552
    545    
    546     import os, sys
    547 
    548     # Create dummy info
    549     info = 'Revision: Version info could not be obtained.'
    550     info += 'A command line version of svn must be availbable '
    551     info += 'on the system PATH, access to the subversion '
    552     info += 'repository is necessary and the output must '
    553     info += 'contain a line starting with "Revision:"'
     553    #FIXME (Ole): Move this and store_version_info to utilities
     554
     555
     556    try:
     557        from anuga.stored_version_info import version_info
     558    except:
     559       
     560        # No file available - try using Subversion
     561        try:
     562            fid = os.popen('svn info')
     563        except:
     564            msg = 'No version info stored and command "svn" is not '
     565            msg += 'recognised on the system PATH. What do you want me to do?'
     566            raise Exception(msg)
     567        else:
     568            #print 'Got version from svn'           
     569            version_info = fid.read()
     570    else:
     571        pass
     572        #print 'Got version from file'
     573
     574           
     575    for line in version_info.split('\n'):
     576        if line.startswith('Revision:'):
     577            break
     578
     579    fields = line.split(':')
     580    msg = 'Keyword "Revision" was not found anywhere in text: %s' %version_info
     581    assert fields[0].startswith('Revision'), msg           
     582
     583    try:
     584        revision_number = int(fields[1])
     585    except:
     586        msg = 'Revision number must be an integer. I got %s' %fields[1]
     587        msg += 'Check that the command svn is on the system path'
     588        raise Exception(msg)               
     589       
     590    return revision_number
     591
     592
     593def store_version_info(destination_path='.', verbose=False):
     594    """Obtain current version from Subversion and store it.
     595   
     596    Title: store_version_info()
     597
     598    Author: Ole Nielsen (Ole.Nielsen@ga.gov.au)
     599
     600    CreationDate: January 2006
     601
     602    Description:
     603        This function obtains current version from Subversion and stores it
     604        is a Python file named 'stored_version_info.py' for use with
     605        get_version_info()
     606
     607        If svn is not available on the system PATH, an Exception is thrown
     608    """
     609
     610    # Note (Ole): This function should not be unit tested as it will only
     611    # work when running out of the sandpit. End users downloading the
     612    # ANUGA distribution would see a failure.
     613    #
     614    # FIXME: This function should really only be used by developers (
     615    # (e.g. for creating new ANUGA releases), so maybe it should move
     616    # to somewhere else.
     617   
     618    import config
    554619
    555620    try:
    556621        fid = os.popen('svn info')
    557622    except:
    558         msg = 'svn is not recognised on the system PATH'
    559         warn(msg, UserWarning)
     623        msg = 'Command "svn" is not recognised on the system PATH'
     624        raise Exception(msg)
    560625    else:   
    561         lines = fid.readlines()
     626        txt = fid.read()
    562627        fid.close()
    563         for line in lines:
    564             if line.startswith('Revision:'):
    565                 info = line
    566                 break
    567        
    568     return info
     628
     629
     630        # Determine absolute filename
     631        if destination_path[-1] != os.sep:
     632            destination_path += os.sep
     633           
     634        filename = destination_path + config.version_filename
     635
     636        fid = open(filename, 'w')
     637
     638        docstring = 'Stored version info.\n\n'
     639        docstring += 'This file provides the version for distributions '
     640        docstring += 'that are not accessing Subversion directly.\n'
     641        docstring += 'The file is automatically generated and should not '
     642        docstring += 'be modified manually.\n'
     643        fid.write('"""%s"""\n\n' %docstring)
     644       
     645        fid.write('version_info = """\n%s"""' %txt)
     646        fid.close()
     647
     648
     649        if verbose is True:
     650            print 'Version info stored to %s' %filename
     651           
    569652   
    570653def sww2timeseries(swwfiles,
  • anuga_core/source/anuga/config.py

    r3876 r4170  
    8989
    9090pmesh_filename = '.\\pmesh'
     91version_filename = 'stored_version_info.py'
    9192
    9293
  • create_distribution.py

    r4168 r4170  
    33   This script is assumed to be run in the root directory of anuga
    44   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.
    519
    620   This script works only on Linux
     
    1125from sys import platform
    1226from anuga.utilities.system_tools import get_user_name, get_host_name
     27from anuga.abstract_2d_finite_volumes.util import get_revision_number
     28from anuga.abstract_2d_finite_volumes.util import store_version_info
    1329
    1430
     
    2339
    2440
    25 # Refresh sandit and retrieve svn revision number
     41# Refresh sandpit and retrieve svn revision number
    2642# from last line in svn update output
    27 
    28 # FIXME (Ole): Change this to use util.get_version_info() and create
     43#filename = mktemp() + '.txt'
     44#s = 'svn update > %s' %filename
     45#print s
     46#system(s)
     47#
     48#fid = open(filename)
     49#last_line = fid.readlines()[-1]
     50#remove(filename)
     51#if not (last_line.startswith('At revision') or\
     52#        last_line.startswith('Updated to revision')):
     53#    msg = 'Unexpected output from svn up: %s' %last_line
     54#    raise Exception, msg   
     55#
     56#fields = last_line.split()
     57#svn_revision = fields[-1][:-1]
     58
     59# Get revision number and create
    2960# file with version info for release.
    30 # This will also mean that the version currently checked out is
     61# This will mean that the version currently checked out is
    3162# the one which will be released.
    3263
    33 filename = mktemp() + '.txt'
    34 
    35 s = 'svn update > %s' %filename
    36 print s
    37 system(s)
    38 
    39 fid = open(filename)
    40 last_line = fid.readlines()[-1]
    41 remove(filename)
    42 if not (last_line.startswith('At revision') or\
    43         last_line.startswith('Updated to revision')):
    44     msg = 'Unexpected output from svn up: %s' %last_line
    45     raise Exception, msg   
    46 
    47 fields = last_line.split()
    48 svn_revision = fields[-1][:-1]
    49 
     64svn_revision = get_revision_number()
    5065revision = '%s_%s' %(major_revision, svn_revision)
    51 
    5266print 'Creating ANUGA revision %s' %revision
    5367
     
    5872s = 'mkdir %s' %release_dir
    5973try:
     74    print s   
    6075    system(s)
    6176except:
     
    6378
    6479
    65 # Export a clean directory tree from the working copy
     80# Export a clean directory tree from the working copy to a temporary dir
    6681distro_dir = mktemp()
    6782s = 'mkdir %s' %distro_dir
    68 print s
    69 system(s)
    70 
    71 s = 'svn export anuga_core/source/anuga %s/anuga' %(distro_dir)
    72 print s
    73 system(s)
     83print s   
     84system(s)
     85
     86
     87
     88s = 'svn export -r %d anuga_core/source/anuga %s/anuga' %(svn_revision,
     89                                                          distro_dir)
     90print s
     91system(s)
     92
     93
     94# Store file with revision info for use with get_revision_number
     95store_version_info(destination_path=distro_dir+'/anuga', verbose=True)
     96
     97import sys; sys.exit()
     98
     99
    74100
    75101# Zip it up
Note: See TracChangeset for help on using the changeset viewer.