Index: /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py
===================================================================
--- /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6784)
+++ /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6785)
@@ -7,4 +7,5 @@
 '''
 
+import sys
 import os
 import glob
@@ -36,5 +37,5 @@
 OUTDIR_PREFIX = 'Make directory '
 
-# Name of SWW file produced by simulation
+# Name of SWW file produced by simulationvalidate_patong.py
 OUTPUT_SWW = 'patong.sww'
 
@@ -57,6 +58,11 @@
     # local function to update one data object
     def update_object(obj, auth):
-        '''Update object 'obj' using authentication tuple 'auth'.'''
-        
+        '''Update object 'obj' using authentication tuple 'auth'.
+        
+        Return updated auth object (success) or False (failure).
+        '''
+
+        log.info("Refreshing local object '%s'" % obj)
+
         # Get a unique date+time string to defeat caching.  The idea is to add
         # this to the end of any URL so proxy sees a different request.
@@ -77,14 +83,23 @@
         if not os.path.exists(local_digest) or not os.path.exists(local_file):
             # no digest or no object, download both digest and object
-            log.debug('Fetching remote file %s' % digest_url)
+            log.info('Fetching remote file %s' % digest_url)
             auth = get_web_file(digest_url+cache_defeat,
                                 local_digest, auth=auth)
-            log.debug('Fetching remote file %s' % object_url)
+            if auth == False:
+                print 'point 1'
+                return False
+            log.info('Fetching remote file %s' % object_url)
             auth = get_web_file(object_url+cache_defeat, local_file, auth=auth)
+            if auth == False:
+                print 'point 2'
+                return False
         else:
             # download object digest to remote data directory
-            log.debug('Fetching remote file %s' % object_url)
+            log.info('Fetching remote file %s' % digest_url)
             auth = get_web_file(digest_url+cache_defeat,
                                 remote_digest, auth=auth)
+            if auth == False:
+                print 'point 3'
+                return False
             
             # compare remote with local digest
@@ -99,16 +114,14 @@
             # if digests differ, refresh object
             if local_data_digest != remote_data_digest:
-                log.debug('Local file %s is out of date' % obj)
+                log.info('Local file %s is out of date' % obj)
                 fd = open(local_digest, 'w')
                 fd.write(remote_data_digest)
                 fd.close()
 
-                log.debug('Fetching remote file %s' % object_url)
+                log.info('Fetching remote file %s' % object_url)
                 auth = get_web_file(object_url+cache_defeat,
                                     local_file, auth=auth)
         return auth
 
-    log.debug('Refreshing local data ...')
-    
     # create local data directory if required
     if not os.path.exists(Local_Data_Directory):
@@ -123,12 +136,36 @@
     for data_object in Local_Data_Objects:
         auth = update_object(data_object, auth)
+        if auth == False:
+            return False
 
     # unpack *.tgz files
     for data_object in Local_Data_Objects:
         tar_path = os.path.join(Local_Data_Directory, data_object+'.tgz')
-        log.debug('Untarring %s in dir %s' % (tar_path, Local_Data_Directory))
+        log.info('Untarring %s in directory %s' % (tar_path, Local_Data_Directory))
         untar_file(tar_path, target_dir=Local_Data_Directory)
         
-    log.debug('Local data has been refreshed.')
+    log.info('Local data has been refreshed.')
+    return True
+
+
+def can_we_run():
+    '''Decide if we can run with the files we have.
+    
+    Return True if we *can* run, else False.
+    '''
+
+    for obj in Local_Data_Objects:
+        # if we don't have required object, can't run
+        obj_path = os.path.join(Local_Data_Directory, obj+'.tgz')
+        if os.path.exists(obj_path):
+            log.debug('Untarring %s in directory %s'
+                      % (obj_path, Local_Data_Directory))
+            untar_file(obj_path, target_dir=Local_Data_Directory)
+        else:
+            return False
+
+    log.critical('You appear to have the required files here, '
+                 'continuing the validation.')
+    return True
 
 
@@ -200,5 +237,8 @@
     # remove remote directory and stdout capture file
     shutil.rmtree(Remote_Data_Directory, ignore_errors=True)
-    os.remove(RUNMODEL_STDOUT)
+    try:
+        os.remove(RUNMODEL_STDOUT)
+    except OSError:
+        pass
             
 
@@ -208,9 +248,45 @@
 
 # set logging levels
-log.console_logging_level = log.DEBUG
+log.console_logging_level = log.INFO
 setup()
 
+# prepare user for what is about to happen
+log.critical('')
+log.critical('This validation requires a working internet connection to run.')
+log.critical('')
+log.critical('If you are behind a proxy server you will need to supply your '
+             'proxy details')
+log.critical('such as the proxy server address and your proxy username and '
+             'password.  These')
+log.critical('can be defined in one or more of the environment variables:')
+log.critical('\tHTTP_PROXY')
+log.critical('\tPROXY_USERNAME')
+log.critical('\tPROXY_PASSWORD')
+log.critical('if you wish.  If not supplied in environment variables, you '
+             'will be prompted for')
+log.critical('the details.')
+log.critical('')
+log.critical('You may still run this validation without an internet '
+             'connection if you have the')
+log.critical('required files.')
+log.critical('*'*80)
+log.critical('')
+
 # make sure local data is up to date
-update_local_data()
+if not update_local_data():
+    print 'update_local_data() returned False'
+    if not can_we_run():
+        print 'can_we_run() returned False'
+        log.critical('')
+        log.critical('*'*80)
+        log.critical("Can't connect via the internet and you don't have the "
+                     "required files.")
+        log.critical('Terminating the validation.')
+        log.critical('')
+        log.critical('If you get these files from %s:' % PATONG_DATA_URL)
+        for obj in Local_Data_Objects:
+            log.critical('    %s.tgz' % obj)
+        log.critical('then you can try to run the validation again.')
+        sys.exit(10)
 
 # run the simulation
