source: DVD_images/update_DVD_images.py @ 7322

Last change on this file since 7322 was 7322, checked in by rwilson, 15 years ago

Removed .cache dir, made update_DVD_images.py NOT run under windows!

  • Property svn:executable set to *
File size: 14.0 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
45 # paths to destination directories (under 'jurisdiction' root)
46 'data_dst_path':   'data/tasmania/hobart_tsunami_scenario_2009/anuga',
47 'proj_dst_path':   'project',
48 'viz_dst_path':    'documents',
49 'arcgis_dst_path': 'data/tasmania/hobart_tsunami_scenario_2009/ArcGIS',
50
51 # copy or create whole directories
52 'make_dst_dirs':   ['outputs', 'topographies'],
53 'copy_data_dirs':  ['gauges','boundaries', 'polygons'],
54
55 # copy 'data' files or directories
56 'copy_data_files': ['outputs/Event1_HAT',
57                     'outputs/Event1_MSL',
58                     'outputs/Event2_HAT',
59                     'outputs/Event2_MSL',
60                     'outputs/Event3_MSL',
61                     'topographies/hobart_combined_elevation.pts',
62                     'topographies/hobart_combined_elevation.txt'],
63
64 # copy 'project' files or directories
65 'copy_proj_files': ['build_elevation.py', 'project.py', 'run_model.py', 
66                     'export_results_max.py',  'get_timeseries.py',
67                     'setup_model.py', 'build_urs_boundary.py',
68                     'file_length.py'],
69
70 # copy 'visualisations' files or directories
71 'copy_viz_files': ['Figures'], 
72
73 # copy 'arcgis' files or directories
74 'copy_arc_files':  []
75}
76
77batemans_bay_data = \
78{'jurisdiction':    'BatemansBay',      # jurisdiction name
79
80 # paths to various source directories
81 'data_src_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
82 'arcgis_src_path': 'data/new_south_wales/batemans_bay_tsunami_scenario_2009/ArcGIS',
83 'viz_src_path':    'data/new_south_wales/batemans_bay_tsunami_scenario_2009/visualisations',
84 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/batemans_bay',
85
86 # paths to destination directories (under 'jurisdiction' root)
87 'data_dst_path':   'data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga',
88 'proj_dst_path':   'project',
89 'viz_dst_path':    'documents',
90 'arcgis_dst_path': 'data/new_south_wales/batemans_bay_tsunami_scenario_2009/ArcGIS',
91
92 # copy or create whole directories
93 'make_dst_dirs':   ['meshes', 'outputs', 'topographies'],
94 'copy_data_dirs':  ['boundaries', 'polygons', 'gauges'],
95
96 # copy 'data' files or directories
97 'copy_data_files': ['topographies/batemans_bay_combined_elevation.pts',
98                     'outputs/Event1_HAT',
99                     'outputs/Event1_MSL',
100                     'outputs/Event2_HAT',
101                     'outputs/Event2_MSL',
102                     'outputs/Event3_MSL',
103                     'outputs/Puysegur_200yr',
104                     'outputs/Puysegur_500yr',
105                     'outputs/Puysegur_1000yr',
106                     'outputs/Puysegur_5000yr',
107                     'outputs/New_Hebrides_200yr',
108                     'outputs/New_Hebrides_500yr',
109                     'outputs/New_Hebrides_1000yr',
110                     'outputs/New_Hebrides_2000yr',
111                     'outputs/New_Hebrides_5000yr',
112                     'outputs/elevation'],
113
114 # copy 'visualisations' files or directories
115 'copy_viz_files': ['Figures'], 
116
117 # copy 'project' files or directories
118 'copy_proj_files': ['project.py', 'run_model.py',
119                     'setup_model.py', 'build_elevation.py',
120                     'export_results_max.py',
121                     'file_length.py', 'build_urs_boundary.py'],
122
123 # copy 'arcgis' files or directories
124 'copy_arc_files':  ['BB_cbd_figure_template.mxd']
125}
126
127gosford_data = \
128{'jurisdiction':    'Gosford',          # jurisdiction name
129
130 # paths to various source directories
131 'data_src_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
132 'arcgis_src_path': 'data/new_south_wales/gosford_tsunami_scenario_2009/ArcGIS',
133 'viz_src_path':    'data/new_south_wales/gosford_tsunami_scenario_2009/visualisations',
134 'proj_src_path':   'sandpits/jgriffin/ANUGA/anuga_work/production/new_south_wales/gosford',
135
136 # paths to destination directories (under 'jurisdiction' root)
137 'data_dst_path':   'data/new_south_wales/gosford_tsunami_scenario_2009/anuga',
138 'proj_dst_path':   'project',
139 'viz_dst_path':    'documents',
140 'arcgis_dst_path': 'data/new_south_wales/gosford_tsunami_scenario_2009/ArcGIS',
141
142 # copy or create whole directories
143 'make_dst_dirs':   ['meshes', 'outputs', 'topographies',  'gauges'],
144 'copy_data_dirs':  ['boundaries', 'polygons'],
145
146 # copy 'data' files or directories
147 'copy_data_files': ['topographies/gosford_combined_elevation.pts',
148                     'outputs/Event1_HAT',
149                     'outputs/Event1_MSL',
150                     'outputs/Event2_HAT',
151                     'outputs/Event2_MSL',
152                     'outputs/Event3_MSL',
153                     'outputs/Puysegur_200yr',
154                     'outputs/Puysegur_500yr',
155                     'outputs/Puysegur_1000yr',
156                     'outputs/Puysegur_5000yr',
157                     'outputs/elevation'
158                    ],
159
160 # copy 'visualisations' files or directories
161 'copy_viz_files': ['Figures'], 
162
163 # copy 'project' files or directories
164 'copy_proj_files': ['export_results_max.py', 'file_length.py',
165                     'project.py', 'run_model.py', 'build_elevation.py',
166                     'get_timeseries.py', 'setup_model.py',
167                     'build_urs_boundary.py'
168                    ],
169
170 # copy 'arcgis' files or directories
171 'copy_arc_files':  ['G_umina_figure_template.mxd']
172}
173
174gold_coast_data = \
175{'jurisdiction':    'GoldCoast',        # jurisdiction name
176
177 # paths to various source directories
178 'data_src_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
179 'arcgis_src_path': 'data/queensland/gold_coast_tsunami_scenario_2009/ArcGIS',
180 'viz_src_path':    'data/queensland/gold_coast_tsunami_scenario_2009/visualisations',
181 'proj_src_path':   'sandpits/lfountain/anuga_work/production/gold_coast_2009/For_DVD',
182
183 # paths to destination directories (under 'jurisdiction' root)
184 'data_dst_path':   'data/queensland/gold_coast_tsunami_scenario_2009/anuga',
185 'proj_dst_path':   'project',
186 'viz_dst_path':    'documents',
187 'arcgis_dst_path': 'data/queensland/gold_coast_tsunami_scenario_2009/ArcGIS',
188
189 # copy or create whole directories
190 'make_dst_dirs':   ['outputs', 'polygons', 'topographies', 'gauges'],
191 'copy_data_dirs':  ['boundaries'],
192
193 # copy 'data' files or directories
194 'copy_data_files': ['outputs/Event1_HAT', 'outputs/Event1_MSL',
195                     'outputs/Event2_HAT', 'outputs/Event2_MSL',
196                     'outputs/Event3_HAT', 'outputs/Event3_MSL',
197                     'polygons/bounding_polygon.csv',
198                     'polygons/area_of_interest.csv',
199                     'polygons/intermediate.csv',
200                     'polygons/initial_conditions.csv',
201                     'gauges/gauges.csv',
202                     'polygons/images.csv',
203                     'topographies/gold_coast_combined_elevation.pts'
204                    ],
205
206 # copy 'visualisations' files or directories
207 'copy_viz_files': ['Figures'], 
208
209 # copy 'project' files or directories
210 'copy_proj_files': ['build_elevation.py', 'export_results_max.py', 'file_length.py',
211                     'project.py', 'run_model.py', 'setup_model.py',
212                     'get_timeseries.py', 'build_urs_boundary.py'
213                    ],
214
215 # copy 'arcgis' files or directories
216 'copy_arc_files':  ['gold_coast.mxd', 'gold_coast.gdb']
217}
218
219# dictionary mapping lower-case jurisdiction name to jurisdiction data dictionary
220source_jurisdiction_path = {'hobart': hobart_data,
221                            'batemansbay': batemans_bay_data,
222                            'gosford': gosford_data,
223                            'goldcoast': gold_coast_data
224                           }
225
226######
227# Routines to automate the script data above.
228######
229
230def log(msg=''):
231    print(msg)
232
233
234def dir_copy(src, dst):
235    cmd = 'cp -R %s %s' % (src, dst)
236    log('Doing: %s' % cmd)
237    fd = os.popen(cmd)
238    fd.close()
239
240def copy_file_or_dir(src, dst):
241    '''Copy a file or complete directory.'''
242
243    # could be a file or directory being copied
244    try:
245        shutil.copyfile(src, dst)
246    except IOError, e:
247        if 'Is a directory' in str(e):
248            shutil.copytree(src, dst)
249        else:
250            log('*' *72)
251            log('* %s' % str(e))
252            log('*' *72)
253
254def update_staging(jurisdiction):
255    # create a list of jurisdiction names
256    jurisdiction_names = []
257    for k in source_jurisdiction_path:
258        jurisdiction_names.append(source_jurisdiction_path[k]['jurisdiction'])
259
260    # get ready
261    j_dict = source_jurisdiction_path[jurisdiction]
262    j_name = j_dict['jurisdiction']
263    data_src_path = os.path.join(main_path, j_dict['data_src_path'])
264    data_dst_path = os.path.join(os.getcwd(), j_name, j_dict['data_dst_path'])
265    proj_src_path = os.path.join(main_path, j_dict['proj_src_path'])
266    proj_dst_path = os.path.join(os.getcwd(), j_name, j_dict['proj_dst_path'])
267    viz_src_path = os.path.join(main_path, j_dict['viz_src_path'])
268    viz_dst_path = os.path.join(os.getcwd(), j_name, j_dict['viz_dst_path'])
269    arcgis_src_path = os.path.join(main_path, j_dict['arcgis_src_path'])
270    arcgis_dst_path = os.path.join(os.getcwd(), j_name, j_dict['arcgis_dst_path'])
271
272    # tell where all stuff is coming from
273    log('Getting data from: %s' % data_src_path)
274    log('Getting project from: %s' % proj_src_path)
275    log('Getting ArcGIS from: %s' % arcgis_src_path)
276    log('')
277
278    # create new output directory, delete old if there
279    if os.path.exists(j_name):
280        log('Deleting existing staging directory: %s' % j_name)
281        shutil.rmtree(j_name)
282    log('Creating staging directory: %s' % j_name)
283    os.makedirs(j_name)
284
285    # create required directories
286    for dir in j_dict['make_dst_dirs']:
287        new_dir = os.path.join(data_dst_path, dir)
288        log('Creating directory: %s' % dir)
289        os.makedirs(new_dir)
290
291    # copy required full directories
292    for copy_dir in j_dict['copy_data_dirs']:
293        src_dir = os.path.join(data_src_path, copy_dir)
294        dst_dir = os.path.join(data_dst_path, copy_dir)
295        log('Copying directory: %s' % copy_dir)
296        copy_file_or_dir(src_dir, dst_dir)
297
298    # copy required data files
299    for copy_file in j_dict['copy_data_files']:
300        src_file = os.path.join(data_src_path, copy_file)
301        new_file = os.path.join(data_dst_path, copy_file)
302        log('Copying: %s' % copy_file)
303        copy_file_or_dir(src_file, new_file)
304
305    # copy required visualisation files
306    log('Creating directory: %s' % viz_dst_path)
307    os.makedirs(viz_dst_path)
308    for copy_file in j_dict['copy_viz_files']:
309        src_file = os.path.join(viz_src_path, copy_file)
310        new_file = os.path.join(viz_dst_path, copy_file)
311        log('Copying: %s' % copy_file)
312        copy_file_or_dir(src_file, new_file)
313
314    # copy required project files
315    log('Creating directory: %s' % proj_dst_path)
316    os.makedirs(proj_dst_path)
317    for copy_file in j_dict['copy_proj_files']:
318        src_file = os.path.join(proj_src_path, copy_file)
319        new_file = os.path.join(proj_dst_path, copy_file)
320        log('Copying: %s' % copy_file)
321        copy_file_or_dir(src_file, new_file)
322
323    # copy required ArcGIS files
324    log('Creating directory: %s' % arcgis_dst_path)
325    os.makedirs(arcgis_dst_path)
326    for copy_file in j_dict['copy_arc_files']:
327        src_file = os.path.join(arcgis_src_path, copy_file)
328        new_file = os.path.join(arcgis_dst_path, copy_file)
329        log('Copying: %s' % copy_file)
330        copy_file_or_dir(src_file, new_file)
331
332    # now copy jurisdiction-specific DVD files
333    src_dir = 'extra_files/%s/*' % j_name
334    dst_dir = j_name
335    dir_copy(src_dir, dst_dir)
336
337    # copy the extra_files and special directories
338    src_dir = 'extra_files/browser_files'
339    dst_dir = j_name
340    dir_copy(src_dir, dst_dir)
341    src_dir = 'extra_files/documents'
342    dir_copy(src_dir, dst_dir)
343    src_file = 'extra_files/autorun.inf'
344    dir_copy(src_file, dst_dir)
345    src_dir = 'extra_files/.cache'
346    dir_copy(src_dir, dst_dir)
347
348    # get size of the staging directory
349    cmd = 'du -sh %s' % j_name
350    fd = os.popen(cmd, 'r')
351    res = fd.read()
352    fd.close()
353    (res, _) = res.split('\t', 1)
354    log('Staging directory %s has size %s' % (j_name, res))
355
356def usage():
357    print('usage: update.py <source>')
358    print('where <source> is one of the jurisdiction staging directories.')
359
360if sys.platform == 'win32':
361    print('Sorry, you can only run this script under Unix')
362    sys.exit(10)
363   
364if len(sys.argv) != 2:
365    usage()
366    sys.exit(10)
367
368jurisdiction = sys.argv[1].lower()
369# remove any trailing '/' - from TAB completion
370if jurisdiction.endswith('/'):
371    jurisdiction = jurisdiction[:-1]
372
373start_time = time.time()
374update_staging(jurisdiction)
375stop_time = time.time()
376elapsed_time = stop_time - start_time
377log('Elapsed time is %.1fs' % elapsed_time)
Note: See TracBrowser for help on using the repository browser.