Index: anuga_validation/automated_validation_tests/patong_validation/validate_patong.py
===================================================================
--- anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6639)
+++ anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6649)
@@ -10,12 +10,9 @@
 import glob
 import unittest
-import logging
+#import logging
+import time
 import project
-from anuga.utilities.system_tools import get_web_file
+from anuga.utilities.system_tools import get_web_file, untar_file
 import anuga.utilities.log as log
-
-# set logging levels
-log.console_logging_level = logging.DEBUG
-log.log_logging_level = logging.DEBUG
 
 
@@ -33,29 +30,37 @@
 
 def update_local_data():
-    
     # update one data object
     def update_object(obj, auth):
+        # 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.
+        cache_defeat = '?' + time.strftime('%Y%m%d%H%M%S')
+
+        # create local and remote paths, URLs, etc.
         remote_path = os.path.join(Remote_Data_Directory, obj)
         remote_digest = remote_path + '.tgz.digest'
         
         local_path = os.path.join(Local_Data_Directory, obj)
-        local_digest = local_path + '.tgz.digest'
+        local_file = local_path + '.tgz'
+        local_digest = local_file + '.digest'
         
-        if not os.path.exists(local_digest):
-            # no object digest, download both digest and object
-            object_url = ANUGA_URL + obj + '.tgz.digest'
+        object_url = ANUGA_URL + obj + '.tgz'
+        digest_url = object_url + '.digest'
+
+        # see if have both digest and object .tgz
+        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)
+            auth = get_web_file(digest_url+cache_defeat,
+                                local_digest, auth=auth)
             log.debug('Fetching remote file %s' % object_url)
-            auth = get_web_file(object_url, local_digest, auth=auth)
-            object_url = ANUGA_URL + obj + '.tgz'
-            local_file = local_path + '.tgz'
-            log.debug('Fetching remote file %s' % object_url)
-            auth = get_web_file(object_url, local_file, auth=auth)
+            auth = get_web_file(object_url+cache_defeat, local_file, auth=auth)
         else:
             # download object digest to remote data directory
             object_url = ANUGA_URL + obj + '.tgz.digest'
             log.debug('Fetching remote file %s' % object_url)
-            auth = get_web_file(object_url, remote_digest, auth=auth)
+            auth = get_web_file(object_url+cache_defeat,
+                                remote_digest, auth=auth)
             
-            # compare remote with local digest, refresh if necessary
+            # compare remote with local digest
             fd = open(local_digest, 'r')
             local_digest_data = fd.read()
@@ -66,6 +71,7 @@
             fd.close()
 
+            # if local digest != remote digest, refresh object
             if local_digest_data != remote_digest_data:
-                # refresh local digest & object
+                log.debug('Local file %s is out of date' % obj)
                 fd = open(local_digest, 'w')
                 fd.write(remote_digest_data)
@@ -75,5 +81,6 @@
                 local_file = local_path + '.tgz'
                 log.debug('Fetching remote file %s' % object_url)
-                auth = get_web_file(object_url, local_file, auth=auth)
+                auth = get_web_file(object_url+cache_defeat,
+                                    local_file, auth=auth)
         return auth
 
@@ -94,4 +101,10 @@
     for data_object in Local_Data_Objects:
         auth = update_object(data_object, auth)
+
+    # 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))
+        untar_file(tar_path, target_dir=Local_Data_Directory)
         
 
@@ -111,4 +124,12 @@
     def tearDown(self):
         pass
+##        # clear all data objects from local data directory
+##        for data_object in Local_Data_Objects:
+##            try:
+##                log.debug('Deleting %s' % os.path.join(Local_Data_Directory,
+##                                                       data_object))
+##                os.remove(os.path.join(Local_Data_Directory, data_object))
+##            except IOError:
+##                pass
 
     def test_that_output_is_as_expected(self):
@@ -117,23 +138,46 @@
         print 'update done'
 
-##        # run the simulation, produce SWW file
-##        s = 'run_model.py'
-##        cmd = 'python %s > %s.stdout' % (s, s)
-##        print 'cmd=%s' % cmd
-##        res = os.system(cmd)
-##        print 'res=%s' % str(res)
-##        assert res == 0
-##
-##        # is SWW file as expected?
-##        print 'About to run compare_output_with_expected.py'
-##        s = 'compare_output_with_expected.py'
-##        res = os.system('python %s > %s.stdout'
-##                        % (s, s))
-##        print 'Result from %s is %d' % (s, res)
-##        assert res == 0
+        # modify environment so we use the local data
+        # INUNDATIONHOME points into the 'anuga' local data directory
+        # N:\georisk_models\inundation\data\thailand\patong_tsunami_scenario\anuga
+        old_inundationhome = os.getenv(project.ENV_INUNDATIONHOME)
+        os.putenv(project.ENV_INUNDATIONHOME,
+                  os.path.join(Local_Data_Directory, 'anuga'))
+        # MUXHOME isn't used, but must exist
+        undo_muxhome = False
+        if os.getenv(project.ENV_MUXHOME) is None:
+            os.putenv(project.ENV_MUXHOME,
+                      os.path.join(Local_Data_Directory, 'data'))
+            undo_muxhome = True
+        
+        # run the simulation, produce SWW file
+        s = 'run_model.py'
+        cmd = 'python %s > %s.stdout' % (s, s)
+        print 'cmd=%s' % cmd
+        res = os.system(cmd)
+        print 'res=%s' % str(res)
+        assert res == 0
+
+        # is SWW file as expected?
+        print 'About to run compare_output_with_expected.py'
+        s = 'compare_output_with_expected.py'
+        res = os.system('python %s > %s.stdout'
+                        % (s, s))
+        print 'Result from %s is %d' % (s, res)
+        assert res == 0
+
+        # undo environment changes
+        if old_inundationhome:
+            os.putenv(project.ENV_INUNDATIONHOME, old_inundationhome)
+        if undo_muxhome:
+            os.putenv(project.ENV_MUXHOME, None)
 
 ################################################################################
 
 if __name__ == "__main__":
+    # set logging levels
+    #log.console_logging_level = log.CRITICAL   # no console logging
+    log.console_logging_level = log.DEBUG
+
     suite = unittest.makeSuite(Test_Patong, 'test')
     runner = unittest.TextTestRunner(verbosity=2)
