Changeset 4787


Ignore:
Timestamp:
Nov 5, 2007, 3:24:05 PM (16 years ago)
Author:
ole
Message:

Moved version functions to system_tools

Location:
anuga_core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/documentation/user_manual/update_anuga_user_manual.py

    r4786 r4787  
    3131from os import system, chdir
    3232from os.path import expanduser
    33 from anuga.abstract_2d_finite_volumes.util import get_revision_number
     33from anuga.utilities.system_tools import get_revision_number
    3434from anuga.anuga_config import major_revision
    3535from sys import argv
  • anuga_core/documentation/user_manual/version.tex

    r4786 r4787  
    77% release version; this is used to define the
    88% \version macro
    9 \release{1.0beta\_4785}
     9\release{1.0beta\_4786}
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4775 r4787  
    1818   
    1919from anuga.geospatial_data.geospatial_data import ensure_absolute
     20
     21
     22
     23# FIXME (Ole): Temporary short cuts - remove and update scripts where they are used
     24from anuga.utilities.system_tools import get_revision_number
     25from anuga.utilities.system_tools import store_version_info
     26
    2027
    2128def file_function(filename,
     
    564571                         print_to_screen=False, verbose=False)
    565572
    566 def get_revision_number():
    567     """Get the version number of the SVN
    568     NOTE: This requires that the command svn is on the system PATH
    569     (simply aliasing svn to the binary will not work)
    570     """
    571 
    572     # Create dummy info
    573     #info = 'Revision: Version info could not be obtained.'
    574     #info += 'A command line version of svn must be availbable '
    575     #info += 'on the system PATH, access to the subversion '
    576     #info += 'repository is necessary and the output must '
    577     #info += 'contain a line starting with "Revision:"'
    578    
    579 
    580     #FIXME (Ole): Change this so that svn info is attempted first.
    581     # 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.
    582 
    583     #FIXME (Ole): Move this and store_version_info to utilities
    584 
    585 
    586     try:
    587         from anuga.stored_version_info import version_info
    588     except:
    589         msg = 'No version info stored and command "svn" is not '
    590         msg += 'recognised on the system PATH.\n\n'
    591         msg += 'If ANUGA has been installed from a distribution e.g. as '
    592         msg += 'obtained from SourceForge,\n'
    593         msg += 'the version info should be '
    594         msg += 'available in the automatically generated file '
    595         msg += 'stored_version_info.py\n'
    596         msg += 'in the anuga root directory.\n'
    597         msg += 'If run from a Subversion sandpit, '
    598         msg += 'ANUGA will try to obtain the version info '
    599         msg += 'by using the command: "svn info".\n'
    600         msg += 'In this case, make sure svn is accessible on the system path. '
    601         msg += 'Simply aliasing svn to the binary will not work. '
    602         msg += 'Good luck!'
    603 
    604         # No file available - try using Subversion
    605         try:
    606             # The null stuff is so this section fails quitly.
    607             # This could cause the svn info command to fail due to
    608             # the redirection being bad on some platforms.
    609             # If that occurs then change this code.
    610             if sys.platform[0:3] == 'win':
    611                 fid = os.popen('svn info 2> null')
    612             else:
    613                 fid = os.popen('svn info 2>/dev/null')
    614        
    615         except:
    616             raise Exception(msg)
    617         else:
    618             #print 'Got version from svn'           
    619             version_info = fid.read()
    620            
    621             if version_info == '':
    622                 raise Exception(msg)   
    623     else:
    624         pass
    625         #print 'Got version from file'
    626 
    627            
    628     for line in version_info.split('\n'):
    629         if line.startswith('Revision:'):
    630             break
    631 
    632     fields = line.split(':')
    633     msg = 'Keyword "Revision" was not found anywhere in text: %s' %version_info
    634     assert fields[0].startswith('Revision'), msg           
    635 
    636     try:
    637         revision_number = int(fields[1])
    638     except:
    639         msg = 'Revision number must be an integer. I got %s' %fields[1]
    640         msg += 'Check that the command svn is on the system path'
    641         raise Exception(msg)               
    642        
    643     return revision_number
    644 
    645 
    646 def store_version_info(destination_path='.', verbose=False):
    647     """Obtain current version from Subversion and store it.
    648    
    649     Title: store_version_info()
    650 
    651     Author: Ole Nielsen (Ole.Nielsen@ga.gov.au)
    652 
    653     CreationDate: January 2006
    654 
    655     Description:
    656         This function obtains current version from Subversion and stores it
    657         is a Python file named 'stored_version_info.py' for use with
    658         get_version_info()
    659 
    660         If svn is not available on the system PATH, an Exception is thrown
    661     """
    662 
    663     # Note (Ole): This function should not be unit tested as it will only
    664     # work when running out of the sandpit. End users downloading the
    665     # ANUGA distribution would see a failure.
    666     #
    667     # FIXME: This function should really only be used by developers (
    668     # (e.g. for creating new ANUGA releases), so maybe it should move
    669     # to somewhere else.
    670    
    671     import config
    672 
    673     try:
    674         fid = os.popen('svn info')
    675     except:
    676         msg = 'Command "svn" is not recognised on the system PATH'
    677         raise Exception(msg)
    678     else:   
    679         txt = fid.read()
    680         fid.close()
    681 
    682 
    683         # Determine absolute filename
    684         if destination_path[-1] != os.sep:
    685             destination_path += os.sep
    686            
    687         filename = destination_path + config.version_filename
    688 
    689         fid = open(filename, 'w')
    690 
    691         docstring = 'Stored version info.\n\n'
    692         docstring += 'This file provides the version for distributions '
    693         docstring += 'that are not accessing Subversion directly.\n'
    694         docstring += 'The file is automatically generated and should not '
    695         docstring += 'be modified manually.\n'
    696         fid.write('"""%s"""\n\n' %docstring)
    697        
    698         fid.write('version_info = """\n%s"""' %txt)
    699         fid.close()
    700 
    701 
    702         if verbose is True:
    703             print 'Version info stored to %s' %filename
    704            
    705    
     573
    706574def sww2timeseries(swwfiles,
    707575                   gauge_filename,
     
    19281796
    19291797
     1798
    19301799def get_runup_data_for_locations_from_file(gauge_filename,
    19311800                                           sww_filename,
     
    19781847        file.write(temp)
    19791848        file.close()
     1849
     1850
     1851           
     1852
     1853   
     1854       
  • anuga_core/source/anuga/utilities/system_tools.py

    r3937 r4787  
    3131
    3232    return host   
     33
     34def get_revision_number():
     35    """Get the version number of the SVN
     36    NOTE: This requires that the command svn is on the system PATH
     37    (simply aliasing svn to the binary will not work)
     38    """
     39
     40    # Create dummy info
     41    #info = 'Revision: Version info could not be obtained.'
     42    #info += 'A command line version of svn must be availbable '
     43    #info += 'on the system PATH, access to the subversion '
     44    #info += 'repository is necessary and the output must '
     45    #info += 'contain a line starting with "Revision:"'
     46   
     47
     48    #FIXME (Ole): Change this so that svn info is attempted first.
     49    # 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.
     50
     51    #FIXME (Ole): Move this and store_version_info to utilities
     52
     53
     54    try:
     55        from anuga.stored_version_info import version_info
     56    except:
     57        msg = 'No version info stored and command "svn" is not '
     58        msg += 'recognised on the system PATH.\n\n'
     59        msg += 'If ANUGA has been installed from a distribution e.g. as '
     60        msg += 'obtained from SourceForge,\n'
     61        msg += 'the version info should be '
     62        msg += 'available in the automatically generated file '
     63        msg += 'stored_version_info.py\n'
     64        msg += 'in the anuga root directory.\n'
     65        msg += 'If run from a Subversion sandpit, '
     66        msg += 'ANUGA will try to obtain the version info '
     67        msg += 'by using the command: "svn info".\n'
     68        msg += 'In this case, make sure svn is accessible on the system path. '
     69        msg += 'Simply aliasing svn to the binary will not work. '
     70        msg += 'Good luck!'
     71
     72        # No file available - try using Subversion
     73        try:
     74            # The null stuff is so this section fails quitly.
     75            # This could cause the svn info command to fail due to
     76            # the redirection being bad on some platforms.
     77            # If that occurs then change this code.
     78            if sys.platform[0:3] == 'win':
     79                fid = os.popen('svn info 2> null')
     80            else:
     81                fid = os.popen('svn info 2>/dev/null')
     82       
     83        except:
     84            raise Exception(msg)
     85        else:
     86            #print 'Got version from svn'           
     87            version_info = fid.read()
     88           
     89            if version_info == '':
     90                raise Exception(msg)   
     91    else:
     92        pass
     93        #print 'Got version from file'
     94
     95           
     96    for line in version_info.split('\n'):
     97        if line.startswith('Revision:'):
     98            break
     99
     100    fields = line.split(':')
     101    msg = 'Keyword "Revision" was not found anywhere in text: %s' %version_info
     102    assert fields[0].startswith('Revision'), msg           
     103
     104    try:
     105        revision_number = int(fields[1])
     106    except:
     107        msg = 'Revision number must be an integer. I got %s' %fields[1]
     108        msg += 'Check that the command svn is on the system path'
     109        raise Exception(msg)               
     110       
     111    return revision_number
     112
     113
     114def store_version_info(destination_path='.', verbose=False):
     115    """Obtain current version from Subversion and store it.
     116   
     117    Title: store_version_info()
     118
     119    Author: Ole Nielsen (Ole.Nielsen@ga.gov.au)
     120
     121    CreationDate: January 2006
     122
     123    Description:
     124        This function obtains current version from Subversion and stores it
     125        is a Python file named 'stored_version_info.py' for use with
     126        get_version_info()
     127
     128        If svn is not available on the system PATH, an Exception is thrown
     129    """
     130
     131    # Note (Ole): This function should not be unit tested as it will only
     132    # work when running out of the sandpit. End users downloading the
     133    # ANUGA distribution would see a failure.
     134    #
     135    # FIXME: This function should really only be used by developers (
     136    # (e.g. for creating new ANUGA releases), so maybe it should move
     137    # to somewhere else.
     138   
     139    import config
     140
     141    try:
     142        fid = os.popen('svn info')
     143    except:
     144        msg = 'Command "svn" is not recognised on the system PATH'
     145        raise Exception(msg)
     146    else:   
     147        txt = fid.read()
     148        fid.close()
     149
     150
     151        # Determine absolute filename
     152        if destination_path[-1] != os.sep:
     153            destination_path += os.sep
     154           
     155        filename = destination_path + config.version_filename
     156
     157        fid = open(filename, 'w')
     158
     159        docstring = 'Stored version info.\n\n'
     160        docstring += 'This file provides the version for distributions '
     161        docstring += 'that are not accessing Subversion directly.\n'
     162        docstring += 'The file is automatically generated and should not '
     163        docstring += 'be modified manually.\n'
     164        fid.write('"""%s"""\n\n' %docstring)
     165       
     166        fid.write('version_info = """\n%s"""' %txt)
     167        fid.close()
     168
     169
     170        if verbose is True:
     171            print 'Version info stored to %s' %filename
     172           
Note: See TracChangeset for help on using the changeset viewer.