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