source: DVD_images/update_DVD_images.py @ 7349

Last change on this file since 7349 was 7349, checked in by Leharne, 15 years ago

updates to QLD section

  • Property svn:executable set to *
File size: 16.6 KB
Line 
1#!/usr/bin/env python
2
3'''
4Program to update a DVD jurisdiction 'anuga' directory from the
5original source directory.
6
7usage: update.py <source>
8
9where <source> is one of:
10                  Hobart
11                  BatemansBay
12                  Gosford
13                  GoldCoast
14ie, the name of one of the DVD jurisdiction staging directories
15(case-insensitive).
16'''
17
18import os
19import sys
20import shutil
21import time
22
23
24# common base path to all data and project files
25main_path = '/nas/gemd/georisk_models/inundation'
26
27# structures holding data for each jurisdiction
28#   data_src_path  : sub-path to data directory
29#   proj_src_path  : sub-path to project files
30#   data_dst_path  : where to copy data files to
31#   proj_dst_path  : where to copy project files to
32#   copy_data_dirs : data directories to completely copy
33#   make_dst_dirs  : make these data directories (may be left empty)
34#   copy_data_files: individual data files to copy to <data_dst_path>
35#   copy_proj_files: individual project files to copy to <proj_dst_path>
36hobart_data = \
37{'jurisdiction':    'Hobart',           # jurisdiction name
38
39 # paths to various source directories
40 'data_src_path':   'data/tasmania/hobart_tsunami_scenario_2009/anuga',
41 'arcgis_src_path': 'data/tasmania/hobart_tsunami_scenario_2009/ArcGIS',
42 'viz_src_path':    'data/tasmania/hobart_tsunami_scenario_2009/visualisations',
43 'proj_src_path':   'sandpits/kvanputten/ANUGA/anuga_work/production/hobart_2009/For_DVD',
44 'report_src_path': 'data/four_east_coast_communities_reporting',
45
46 # paths to destination directories (under 'jurisdiction' root)
47 'data_dst_path':   'data/tasmania/hobart_tsunami_scenario_2009/anuga',
48 'proj_dst_path':   'project',
49 'viz_dst_path':    'documents',
50 'arcgis_dst_path': 'data/tasmania/hobart_tsunami_scenario_2009/ArcGIS',
51 'report_dst_path': 'documents',
52 
53 # copy or create whole directories
54 'make_dst_dirs':   ['outputs', 'topographies'],
55 'copy_data_dirs':  ['gauges','boundaries', 'polygons'],
56
57 # copy 'data' files or directories
58 'copy_data_files': ['outputs/Event1_HAT',
59                     'outputs/Event1_MSL',
60                     'outputs/Event2_HAT',
61                     'outputs/Event2_MSL',
62                     'outputs/Event3_MSL',
63                     'topographies/hobart_combined_elevation.pts',
64                     'topographies/hobart_combined_elevation.txt'],
65
66 # copy 'project' files or directories
67 'copy_proj_files': ['build_elevation.py', 'project.py', 'run_model.py', 
68                     'export_results_max.py',  'get_timeseries.py',
69                     'setup_model.py', 'build_urs_boundary.py',
70                     'file_length.py'],
71
72 # copy 'visualisations' files or directories
73 'copy_viz_files': ['Figures'], 
74
75 # copy 'arcgis' files or directories
76 'copy_arc_files':  [],
77
78 # copy 'report' file
79 'copy_report_files':  ['professionalopinion_2009_modelling_FINAL_TAS.doc']
80}
81
82batemans_bay_data = \
83{'jurisdiction':    'BatemansBay',      # jurisdiction name
84
85 # paths to various source directories
86 'data_src_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
87 'arcgis_src_path': 'data/new_south_wales/batemans_bay_tsunami_scenario_2009/ArcGIS',
88 'viz_src_path':    'data/new_south_wales/batemans_bay_tsunami_scenario_2009/visualisations',
89 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/batemans_bay',
90 'report_src_path': 'data/four_east_coast_communities_reporting',
91
92 # paths to destination directories (under 'jurisdiction' root)
93 'data_dst_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
94 'proj_dst_path':   'project',
95 'viz_dst_path':    'documents',
96 'arcgis_dst_path': 'data/new_south_wales/batemans_bay_tsunami_scenario_2009/ArcGIS',
97 'report_dst_path': 'documents',
98
99 # copy or create whole directories
100 'make_dst_dirs':   ['boundaries', 'meshes', 'outputs', 'topographies'],
101 'copy_data_dirs':  ['polygons', 'gauges'],
102
103 # copy 'data' files or directories
104 'copy_data_files': ['topographies/batemans_bay_combined_elevation.pts',
105                     'outputs/Event1_HAT',
106                     'outputs/Event1_MSL',
107                     'outputs/Event2_HAT',
108                     'outputs/Event2_MSL',
109                     'outputs/Event3_MSL',
110                     'outputs/Puysegur_200yr',
111                     'outputs/Puysegur_500yr',
112                     'outputs/Puysegur_1000yr',
113                     'outputs/Puysegur_5000yr',
114                     'outputs/New_Hebrides_200yr',
115                     'outputs/New_Hebrides_500yr',
116                     'outputs/New_Hebrides_1000yr',
117                     'outputs/New_Hebrides_2000yr',
118                     'outputs/New_Hebrides_5000yr',
119                     'outputs/elevation',
120                     'boundaries/51077',
121                     'boundaries/51204',
122                     'boundaries/51292',
123                     'boundaries/51347',
124                     'boundaries/51378',
125                     'boundaries/51424',
126                     'boundaries/51436',
127                     'boundaries/51445',
128                     'boundaries/58115',
129                     'boundaries/58129',
130                     'boundaries/58226',
131                     'boundaries/58272',
132                     'boundaries/58284',
133                     'boundaries/58286',
134                     'boundaries/58346',
135                     'boundaries/58368',
136                     'boundaries/boundaries.gdb',
137                     'boundaries/landward_boundary_extend.csv',
138                     'boundaries/thinned_boundary_ordering_extend.csv'
139                     ],
140
141 # copy 'visualisations' files or directories
142 'copy_viz_files': ['Figures'], 
143
144 # copy 'project' files or directories
145 'copy_proj_files': ['project.py', 'run_model.py',
146                     'setup_model.py', 'build_elevation.py',
147                     'export_results_max.py',
148                     'file_length.py', 'build_urs_boundary.py'],
149
150 # copy 'arcgis' files or directories
151 'copy_arc_files':  ['BB_cbd_figure_template.mxd'],
152
153 # copy 'report' file
154 'copy_report_files':  ['professionalopinion_2009_modelling_FINAL_NSW.doc']
155
156}
157
158gosford_data = \
159{'jurisdiction':    'Gosford',          # jurisdiction name
160
161 # paths to various source directories
162 'data_src_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
163 'arcgis_src_path': 'data/new_south_wales/gosford_tsunami_scenario_2009/ArcGIS',
164 'viz_src_path':    'data/new_south_wales/gosford_tsunami_scenario_2009/visualisations',
165 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/gosford',
166 'report_src_path': 'data/four_east_coast_communities_reporting',
167 
168 # paths to destination directories (under 'jurisdiction' root)
169 'data_dst_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
170 'proj_dst_path':   'project',
171 'viz_dst_path':    'documents',
172 'arcgis_dst_path': 'data/new_south_wales/gosford_tsunami_scenario_2009/ArcGIS',
173 'report_dst_path': 'documents',
174 
175 # copy or create whole directories
176 'make_dst_dirs':   ['boundaries', 'meshes', 'outputs', 'topographies'],
177 'copy_data_dirs':  ['polygons',  'gauges'],
178
179 # copy 'data' files or directories
180 'copy_data_files': ['topographies/gosford_combined_elevation.pts',
181                     'outputs/Event1_HAT',
182                     'outputs/Event1_MSL',
183                     'outputs/Event2_HAT',
184                     'outputs/Event2_MSL',
185                     'outputs/Event3_MSL',
186                     'outputs/Puysegur_200yr',
187                     'outputs/Puysegur_500yr',
188                     'outputs/Puysegur_1000yr',
189                     'outputs/Puysegur_5000yr',
190                     'outputs/elevation',
191                     'boundaries/51436',
192                     'boundaries/58025',
193                     'boundaries/58113',
194                     'boundaries/58187',
195                     'boundaries/58242',
196                     'boundaries/58284',
197                     'boundaries/58349',
198                     'boundaries/boundaries.gdb',
199                     'boundaries/landward_boundary.csv',
200                     'boundaries/urs_order.csv'
201                    ],
202
203 # copy 'visualisations' files or directories
204 'copy_viz_files': ['Figures'], 
205
206 # copy 'project' files or directories
207 'copy_proj_files': ['export_results_max.py', 'file_length.py',
208                     'project.py', 'run_model.py', 'build_elevation.py',
209                     'get_timeseries.py', 'setup_model.py',
210                     'build_urs_boundary.py'
211                    ],
212
213 # copy 'arcgis' files or directories
214 'copy_arc_files':  ['G_umina_figure_template.mxd']
215}
216
217gold_coast_data = \
218{'jurisdiction':    'GoldCoast',        # jurisdiction name
219
220 # paths to various source directories
221 'data_src_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
222 'arcgis_src_path': 'data/queensland/gold_coast_tsunami_scenario_2009/ArcGIS',
223 'viz_src_path':    'data/queensland/gold_coast_tsunami_scenario_2009/visualisations',
224 'proj_src_path':   'sandpits/lfountain/anuga_work/production/gold_coast_2009/For_DVD',
225 'report_src_path': 'data/four_east_coast_communities_reporting',
226 'report_dst_path': 'documents',
227 
228 # paths to destination directories (under 'jurisdiction' root)
229 'data_dst_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
230 'proj_dst_path':   'project',
231 'viz_dst_path':    'documents',
232 'arcgis_dst_path': 'data/queensland/gold_coast_tsunami_scenario_2009/ArcGIS',
233
234 # copy or create whole directories
235 'make_dst_dirs':   ['outputs', 'topographies', 'boundaries'],
236 'copy_data_dirs':  ['polygons', 'gauges'],
237 
238 # copy 'data' files or directories
239 'copy_data_files': ['outputs/Event1_HAT', 'outputs/Event1_MSL',
240                     'outputs/Event2_HAT', 'outputs/Event2_MSL',
241                     'outputs/Event3_HAT', 'outputs/Event3_MSL',
242                     'boundaries/50863', 'boundaries/50994',
243                     'boundaries/51253', 'boundaries/51392',
244                     'boundaries/51423', 'boundaries/51469',
245                     'boundaries/62833','boundaries/events_chosen.xls',
246                     'boundaries/landward_boundary.csv',
247                     'boundaries/urs_order.csv',
248                     'gauges/gauges.csv',
249                     'gauges/gauges.gdb',
250                     'topographies/gold_coast_combined_elevation.pts'
251                    ],
252
253 # copy 'visualisations' files or directories
254 'copy_viz_files': ['Figures'], 
255
256 # copy 'project' files or directories
257 'copy_proj_files': ['build_elevation.py', 'export_results_max.py', 'file_length.py',
258                     'project.py', 'run_model.py', 'setup_model.py',
259                     'get_timeseries.py', 'build_urs_boundary.py'
260                    ],
261
262 # copy 'arcgis' files or directories
263 'copy_arc_files':  ['gold_coast.mxd', 'gold_coast.gdb'],
264
265 # copy 'report' file
266 'copy_report_files':  ['professionalopinion_2009_modelling_QLD.doc']
267}
268
269# dictionary mapping lower-case jurisdiction name to jurisdiction data dictionary
270source_jurisdiction_path = {'hobart': hobart_data,
271                            'batemansbay': batemans_bay_data,
272                            'gosford': gosford_data,
273                            'goldcoast': gold_coast_data
274                           }
275
276######
277# Routines to automate the script data above.
278######
279
280def log(msg=''):
281    print(msg)
282
283
284def dir_copy(src, dst):
285    cmd = 'cp -R %s %s' % (src, dst)
286    log('Doing: %s' % cmd)
287    fd = os.popen(cmd)
288    fd.close()
289
290def copy_file_or_dir(src, dst):
291    '''Copy a file or complete directory.'''
292
293    # could be a file or directory being copied
294    try:
295        shutil.copyfile(src, dst)
296    except IOError, e:
297        if 'Is a directory' in str(e):
298            shutil.copytree(src, dst)
299        else:
300            log('*' *72)
301            log('* %s' % str(e))
302            log('*' *72)
303
304def update_staging(jurisdiction):
305    # create a list of jurisdiction names
306    jurisdiction_names = []
307    for k in source_jurisdiction_path:
308        jurisdiction_names.append(source_jurisdiction_path[k]['jurisdiction'])
309
310    # get ready
311    j_dict = source_jurisdiction_path[jurisdiction]
312    j_name = j_dict['jurisdiction']
313    data_src_path = os.path.join(main_path, j_dict['data_src_path'])
314    data_dst_path = os.path.join(os.getcwd(), j_name, j_dict['data_dst_path'])
315    proj_src_path = os.path.join(main_path, j_dict['proj_src_path'])
316    proj_dst_path = os.path.join(os.getcwd(), j_name, j_dict['proj_dst_path'])
317    viz_src_path = os.path.join(main_path, j_dict['viz_src_path'])
318    viz_dst_path = os.path.join(os.getcwd(), j_name, j_dict['viz_dst_path'])
319    arcgis_src_path = os.path.join(main_path, j_dict['arcgis_src_path'])
320    arcgis_dst_path = os.path.join(os.getcwd(), j_name, j_dict['arcgis_dst_path'])
321    report_src_path = os.path.join(main_path, j_dict['report_src_path'])
322    report_dst_path = os.path.join(os.getcwd(), j_name, j_dict['report_dst_path'])
323   
324    # tell where all stuff is coming from
325    log('Getting data from: %s' % data_src_path)
326    log('Getting project from: %s' % proj_src_path)
327    log('Getting ArcGIS from: %s' % arcgis_src_path)
328    log('Getting report from: %s' % report_src_path)
329    log('')
330
331    # create new output directory, delete old if there
332    if os.path.exists(j_name):
333        log('Deleting existing staging directory: %s' % j_name)
334        shutil.rmtree(j_name)
335    log('Creating staging directory: %s' % j_name)
336    os.makedirs(j_name)
337
338    # create required directories
339    for dir in j_dict['make_dst_dirs']:
340        new_dir = os.path.join(data_dst_path, dir)
341        log('Creating directory: %s' % dir)
342        os.makedirs(new_dir)
343
344    # copy required full directories
345    for copy_dir in j_dict['copy_data_dirs']:
346        src_dir = os.path.join(data_src_path, copy_dir)
347        dst_dir = os.path.join(data_dst_path, copy_dir)
348        log('Copying directory: %s' % copy_dir)
349        copy_file_or_dir(src_dir, dst_dir)
350
351    # copy required data files
352    for copy_file in j_dict['copy_data_files']:
353        src_file = os.path.join(data_src_path, copy_file)
354        new_file = os.path.join(data_dst_path, copy_file)
355        log('Copying: %s' % copy_file)
356        copy_file_or_dir(src_file, new_file)
357
358    # copy required visualisation files
359    log('Creating directory: %s' % viz_dst_path)
360    os.makedirs(viz_dst_path)
361    for copy_file in j_dict['copy_viz_files']:
362        src_file = os.path.join(viz_src_path, copy_file)
363        new_file = os.path.join(viz_dst_path, copy_file)
364        log('Copying: %s' % copy_file)
365        copy_file_or_dir(src_file, new_file)
366
367    # copy required project files
368    log('Creating directory: %s' % proj_dst_path)
369    os.makedirs(proj_dst_path)
370    for copy_file in j_dict['copy_proj_files']:
371        src_file = os.path.join(proj_src_path, copy_file)
372        new_file = os.path.join(proj_dst_path, copy_file)
373        log('Copying: %s' % copy_file)
374        copy_file_or_dir(src_file, new_file)
375
376    # copy required ArcGIS files
377    log('Creating directory: %s' % arcgis_dst_path)
378    os.makedirs(arcgis_dst_path)
379    for copy_file in j_dict['copy_arc_files']:
380        src_file = os.path.join(arcgis_src_path, copy_file)
381        new_file = os.path.join(arcgis_dst_path, copy_file)
382        log('Copying: %s' % copy_file)
383        copy_file_or_dir(src_file, new_file)
384
385    # copy report
386    log('Creating directory: %s' % report_dst_path)
387    for copy_file in j_dict['copy_report_files']:
388        src_file = os.path.join(report_src_path, copy_file)
389        new_file = os.path.join(report_dst_path, copy_file)
390        log('Copying: %s' % copy_file)
391        copy_file_or_dir(src_file, new_file)
392
393    # now copy jurisdiction-specific DVD files
394    src_dir = 'extra_files/%s/*' % j_name
395    dst_dir = j_name
396    dir_copy(src_dir, dst_dir)
397
398    # copy the extra_files and special directories
399    src_dir = 'extra_files/browser_files'
400    dst_dir = j_name
401    dir_copy(src_dir, dst_dir)
402    src_dir = 'extra_files/documents'
403    dir_copy(src_dir, dst_dir)
404    src_file = 'extra_files/autorun.inf'
405    dir_copy(src_file, dst_dir)
406    src_dir = 'extra_files/.cache'
407    dir_copy(src_dir, dst_dir)
408
409    # get size of the staging directory
410    cmd = 'du -sh %s' % j_name
411    fd = os.popen(cmd, 'r')
412    res = fd.read()
413    fd.close()
414    (res, _) = res.split('\t', 1)
415    log('Staging directory %s has size %s' % (j_name, res))
416
417def usage():
418    print('usage: update.py <source>')
419    print('where <source> is one of the jurisdiction staging directories.')
420
421if sys.platform == 'win32':
422    print('Sorry, you can only run this script under Unix')
423    sys.exit(10)
424   
425if len(sys.argv) != 2:
426    usage()
427    sys.exit(10)
428
429jurisdiction = sys.argv[1].lower()
430# remove any trailing '/' - from TAB completion
431if jurisdiction.endswith('/'):
432    jurisdiction = jurisdiction[:-1]
433
434start_time = time.time()
435update_staging(jurisdiction)
436stop_time = time.time()
437elapsed_time = stop_time - start_time
438log('Elapsed time is %.1fs' % elapsed_time)
439print 'completed'
Note: See TracBrowser for help on using the repository browser.