Changeset 6785
- Timestamp:
- Apr 14, 2009, 12:07:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_validation/automated_validation_tests/patong_validation/validate_patong.py
r6782 r6785 7 7 ''' 8 8 9 import sys 9 10 import os 10 11 import glob … … 36 37 OUTDIR_PREFIX = 'Make directory ' 37 38 38 # Name of SWW file produced by simulation 39 # Name of SWW file produced by simulationvalidate_patong.py 39 40 OUTPUT_SWW = 'patong.sww' 40 41 … … 57 58 # local function to update one data object 58 59 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 61 67 # Get a unique date+time string to defeat caching. The idea is to add 62 68 # this to the end of any URL so proxy sees a different request. … … 77 83 if not os.path.exists(local_digest) or not os.path.exists(local_file): 78 84 # 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) 80 86 auth = get_web_file(digest_url+cache_defeat, 81 87 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) 83 92 auth = get_web_file(object_url+cache_defeat, local_file, auth=auth) 93 if auth == False: 94 print 'point 2' 95 return False 84 96 else: 85 97 # 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) 87 99 auth = get_web_file(digest_url+cache_defeat, 88 100 remote_digest, auth=auth) 101 if auth == False: 102 print 'point 3' 103 return False 89 104 90 105 # compare remote with local digest … … 99 114 # if digests differ, refresh object 100 115 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) 102 117 fd = open(local_digest, 'w') 103 118 fd.write(remote_data_digest) 104 119 fd.close() 105 120 106 log. debug('Fetching remote file %s' % object_url)121 log.info('Fetching remote file %s' % object_url) 107 122 auth = get_web_file(object_url+cache_defeat, 108 123 local_file, auth=auth) 109 124 return auth 110 125 111 log.debug('Refreshing local data ...')112 113 126 # create local data directory if required 114 127 if not os.path.exists(Local_Data_Directory): … … 123 136 for data_object in Local_Data_Objects: 124 137 auth = update_object(data_object, auth) 138 if auth == False: 139 return False 125 140 126 141 # unpack *.tgz files 127 142 for data_object in Local_Data_Objects: 128 143 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)) 130 145 untar_file(tar_path, target_dir=Local_Data_Directory) 131 146 132 log.debug('Local data has been refreshed.') 147 log.info('Local data has been refreshed.') 148 return True 149 150 151 def 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 133 170 134 171 … … 200 237 # remove remote directory and stdout capture file 201 238 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 203 243 204 244 … … 208 248 209 249 # set logging levels 210 log.console_logging_level = log. DEBUG250 log.console_logging_level = log.INFO 211 251 setup() 212 252 253 # prepare user for what is about to happen 254 log.critical('') 255 log.critical('This validation requires a working internet connection to run.') 256 log.critical('') 257 log.critical('If you are behind a proxy server you will need to supply your ' 258 'proxy details') 259 log.critical('such as the proxy server address and your proxy username and ' 260 'password. These') 261 log.critical('can be defined in one or more of the environment variables:') 262 log.critical('\tHTTP_PROXY') 263 log.critical('\tPROXY_USERNAME') 264 log.critical('\tPROXY_PASSWORD') 265 log.critical('if you wish. If not supplied in environment variables, you ' 266 'will be prompted for') 267 log.critical('the details.') 268 log.critical('') 269 log.critical('You may still run this validation without an internet ' 270 'connection if you have the') 271 log.critical('required files.') 272 log.critical('*'*80) 273 log.critical('') 274 213 275 # make sure local data is up to date 214 update_local_data() 276 if 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) 215 291 216 292 # run the simulation
Note: See TracChangeset
for help on using the changeset viewer.