Index: /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py
===================================================================
--- /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6638)
+++ /anuga_validation/automated_validation_tests/patong_validation/validate_patong.py	(revision 6639)
@@ -2,4 +2,7 @@
 Automatic verification that the ANUGA code validates against the patong
 dataset as expected.
+
+Required files are downloaded from the ANUGA servers if they are
+out of date or missing.
 '''
 
@@ -7,17 +10,92 @@
 import glob
 import unittest
+import logging
 import project
+from anuga.utilities.system_tools import get_web_file
+import anuga.utilities.log as log
 
+# set logging levels
+log.console_logging_level = logging.DEBUG
+log.log_logging_level = logging.DEBUG
+
+
+# path to the local data directory
+Local_Data_Directory = os.path.join('.', 'local_data')
+
+# path to the remote data directory
+Remote_Data_Directory = os.path.join('.', 'remote_data')
+
+# sequence of required local data objects
+Local_Data_Objects = ('patong.sww', 'anuga')
+
+# base URL for the remote ANUGA data
+ANUGA_URL = 'http://10.7.64.243/patong_validation_data/'
+
+def update_local_data():
+    
+    # update one data object
+    def update_object(obj, auth):
+        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'
+        
+        if not os.path.exists(local_digest):
+            # no object digest, download both digest and object
+            object_url = ANUGA_URL + obj + '.tgz.digest'
+            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)
+        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)
+            
+            # compare remote with local digest, refresh if necessary
+            fd = open(local_digest, 'r')
+            local_digest_data = fd.read()
+            fd.close()
+
+            fd = open(remote_digest, 'r')
+            remote_digest_data = fd.read()
+            fd.close()
+
+            if local_digest_data != remote_digest_data:
+                # refresh local digest & object
+                fd = open(local_digest, 'w')
+                fd.write(remote_digest_data)
+                fd.close()
+
+                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)
+        return auth
+
+    
+    # create local data directory if required
+    if not os.path.exists(Local_Data_Directory):
+        os.mkdir(Local_Data_Directory)
+
+    # create or clean out remote data copy directory
+    if not os.path.exists(Remote_Data_Directory):
+        os.mkdir(Remote_Data_Directory)
+    rem_files = glob.glob(os.path.join(Remote_Data_Directory, '*'))
+    for file in rem_files:
+        os.remove(file)
+
+    # refresh local files
+    auth = None
+    for data_object in Local_Data_Objects:
+        auth = update_object(data_object, auth)
+        
 
 class Test_Patong(unittest.TestCase):
     def setUp(self):
-        
-##        for file in glob.glob('./*.stdout'):
-##            os.remove(file)
-##        for file in glob.glob('./*.sww'):
-##            os.remove(file)
-##        for file in glob.glob('./*.msh'):
-##            os.remove(file)
-
         # Check that environment variables are defined.
         if os.getenv(project.ENV_INUNDATIONHOME) is None:
@@ -32,21 +110,26 @@
 
     def tearDown(self):
-        # delete all output necessary
         pass
 
     def test_that_output_is_as_expected(self):
-        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
+        # make sure local data is up to date
+        update_local_data()
+        print 'update done'
 
-        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
+##        # 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
 
 ################################################################################
