Changeset 6785


Ignore:
Timestamp:
Apr 14, 2009, 12:07:52 PM (16 years ago)
Author:
rwilson
Message:

Changes to handle not having an internet connection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_validation/automated_validation_tests/patong_validation/validate_patong.py

    r6782 r6785  
    77'''
    88
     9import sys
    910import os
    1011import glob
     
    3637OUTDIR_PREFIX = 'Make directory '
    3738
    38 # Name of SWW file produced by simulation
     39# Name of SWW file produced by simulationvalidate_patong.py
    3940OUTPUT_SWW = 'patong.sww'
    4041
     
    5758    # local function to update one data object
    5859    def update_object(obj, auth):
    59         '''Update object 'obj' using authentication tuple 'auth'.'''
    60        
     60        '''Update object 'obj' using authentication tuple 'auth'.
     61       
     62        Return updated auth object (success) or False (failure).
     63        '''
     64
     65        log.info("Refreshing local object '%s'" % obj)
     66
    6167        # Get a unique date+time string to defeat caching.  The idea is to add
    6268        # this to the end of any URL so proxy sees a different request.
     
    7783        if not os.path.exists(local_digest) or not os.path.exists(local_file):
    7884            # no digest or no object, download both digest and object
    79             log.debug('Fetching remote file %s' % digest_url)
     85            log.info('Fetching remote file %s' % digest_url)
    8086            auth = get_web_file(digest_url+cache_defeat,
    8187                                local_digest, auth=auth)
    82             log.debug('Fetching remote file %s' % object_url)
     88            if auth == False:
     89                print 'point 1'
     90                return False
     91            log.info('Fetching remote file %s' % object_url)
    8392            auth = get_web_file(object_url+cache_defeat, local_file, auth=auth)
     93            if auth == False:
     94                print 'point 2'
     95                return False
    8496        else:
    8597            # download object digest to remote data directory
    86             log.debug('Fetching remote file %s' % object_url)
     98            log.info('Fetching remote file %s' % digest_url)
    8799            auth = get_web_file(digest_url+cache_defeat,
    88100                                remote_digest, auth=auth)
     101            if auth == False:
     102                print 'point 3'
     103                return False
    89104           
    90105            # compare remote with local digest
     
    99114            # if digests differ, refresh object
    100115            if local_data_digest != remote_data_digest:
    101                 log.debug('Local file %s is out of date' % obj)
     116                log.info('Local file %s is out of date' % obj)
    102117                fd = open(local_digest, 'w')
    103118                fd.write(remote_data_digest)
    104119                fd.close()
    105120
    106                 log.debug('Fetching remote file %s' % object_url)
     121                log.info('Fetching remote file %s' % object_url)
    107122                auth = get_web_file(object_url+cache_defeat,
    108123                                    local_file, auth=auth)
    109124        return auth
    110125
    111     log.debug('Refreshing local data ...')
    112    
    113126    # create local data directory if required
    114127    if not os.path.exists(Local_Data_Directory):
     
    123136    for data_object in Local_Data_Objects:
    124137        auth = update_object(data_object, auth)
     138        if auth == False:
     139            return False
    125140
    126141    # unpack *.tgz files
    127142    for data_object in Local_Data_Objects:
    128143        tar_path = os.path.join(Local_Data_Directory, data_object+'.tgz')
    129         log.debug('Untarring %s in dir %s' % (tar_path, Local_Data_Directory))
     144        log.info('Untarring %s in directory %s' % (tar_path, Local_Data_Directory))
    130145        untar_file(tar_path, target_dir=Local_Data_Directory)
    131146       
    132     log.debug('Local data has been refreshed.')
     147    log.info('Local data has been refreshed.')
     148    return True
     149
     150
     151def can_we_run():
     152    '''Decide if we can run with the files we have.
     153   
     154    Return True if we *can* run, else False.
     155    '''
     156
     157    for obj in Local_Data_Objects:
     158        # if we don't have required object, can't run
     159        obj_path = os.path.join(Local_Data_Directory, obj+'.tgz')
     160        if os.path.exists(obj_path):
     161            log.debug('Untarring %s in directory %s'
     162                      % (obj_path, Local_Data_Directory))
     163            untar_file(obj_path, target_dir=Local_Data_Directory)
     164        else:
     165            return False
     166
     167    log.critical('You appear to have the required files here, '
     168                 'continuing the validation.')
     169    return True
    133170
    134171
     
    200237    # remove remote directory and stdout capture file
    201238    shutil.rmtree(Remote_Data_Directory, ignore_errors=True)
    202     os.remove(RUNMODEL_STDOUT)
     239    try:
     240        os.remove(RUNMODEL_STDOUT)
     241    except OSError:
     242        pass
    203243           
    204244
     
    208248
    209249# set logging levels
    210 log.console_logging_level = log.DEBUG
     250log.console_logging_level = log.INFO
    211251setup()
    212252
     253# prepare user for what is about to happen
     254log.critical('')
     255log.critical('This validation requires a working internet connection to run.')
     256log.critical('')
     257log.critical('If you are behind a proxy server you will need to supply your '
     258             'proxy details')
     259log.critical('such as the proxy server address and your proxy username and '
     260             'password.  These')
     261log.critical('can be defined in one or more of the environment variables:')
     262log.critical('\tHTTP_PROXY')
     263log.critical('\tPROXY_USERNAME')
     264log.critical('\tPROXY_PASSWORD')
     265log.critical('if you wish.  If not supplied in environment variables, you '
     266             'will be prompted for')
     267log.critical('the details.')
     268log.critical('')
     269log.critical('You may still run this validation without an internet '
     270             'connection if you have the')
     271log.critical('required files.')
     272log.critical('*'*80)
     273log.critical('')
     274
    213275# make sure local data is up to date
    214 update_local_data()
     276if not update_local_data():
     277    print 'update_local_data() returned False'
     278    if not can_we_run():
     279        print 'can_we_run() returned False'
     280        log.critical('')
     281        log.critical('*'*80)
     282        log.critical("Can't connect via the internet and you don't have the "
     283                     "required files.")
     284        log.critical('Terminating the validation.')
     285        log.critical('')
     286        log.critical('If you get these files from %s:' % PATONG_DATA_URL)
     287        for obj in Local_Data_Objects:
     288            log.critical('    %s.tgz' % obj)
     289        log.critical('then you can try to run the validation again.')
     290        sys.exit(10)
    215291
    216292# run the simulation
Note: See TracChangeset for help on using the changeset viewer.