Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A utility script for downloading versioned Syzygy binaries.""" | 6 """A utility script for downloading versioned Syzygy binaries.""" |
| 7 | 7 |
| 8 import cStringIO | 8 import cStringIO |
| 9 import hashlib | 9 import hashlib |
| 10 import errno | 10 import errno |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 # Ensure that the specified SVN revision or GIT hash is valid. | 351 # Ensure that the specified SVN revision or GIT hash is valid. |
| 352 if not _REVISION_RE.match(options.revision): | 352 if not _REVISION_RE.match(options.revision): |
| 353 option_parser.error('Must specify a valid SVN or GIT revision.') | 353 option_parser.error('Must specify a valid SVN or GIT revision.') |
| 354 | 354 |
| 355 # This just makes output prettier to read. | 355 # This just makes output prettier to read. |
| 356 options.output_dir = os.path.normpath(options.output_dir) | 356 options.output_dir = os.path.normpath(options.output_dir) |
| 357 | 357 |
| 358 return options | 358 return options |
| 359 | 359 |
| 360 | 360 |
| 361 def main(): | 361 def _RemoveOrphanedFiles(options): |
| 362 # We only care about Windows platforms, as the Syzygy binaries aren't used | 362 """This is run on non-Windows systems to remove orphaned files that may have |
| 363 # elsewhere. | 363 been downloaded by a previous version of this script. |
| 364 if sys.platform not in ('win32', 'cygwin'): | 364 """ |
| 365 # Reconfigure logging to output info messages. This will allow inspection of | |
| 366 # cleanup status on non-Windows buildbots. | |
| 367 _LOGGER.setLevel(logging.INFO) | |
| 368 | |
| 369 output_dir = os.path.abspath(options.output_dir) | |
| 370 | |
| 371 expected_syzygy_dir = os.path.abspath(os.path.join( | |
|
Sigurður Ásgeirsson
2014/09/19 18:44:42
one line of running commentary perhaps?
chrisha
2014/09/19 18:48:17
Done.
| |
| 372 os.path.dirname(__file__), '..', 'third_party', 'syzygy')) | |
| 373 expected_output_dir = os.path.join(expected_syzygy_dir, 'binaries') | |
| 374 if expected_output_dir != output_dir: | |
| 375 _LOGGER.info('Unexpected output directory, skipping cleanup.') | |
| 365 return | 376 return |
| 366 | 377 |
| 378 if not os.path.isdir(expected_syzygy_dir): | |
| 379 _LOGGER.info('Output directory does not exist, skipping cleanup.') | |
| 380 return | |
| 381 | |
| 382 def OnError(function, path, excinfo): | |
| 383 """Logs error encountered by shutil.rmtree.""" | |
| 384 _LOGGER.error('Error when running %s(%s)', function, path, exc_info=excinfo) | |
| 385 | |
| 386 _LOGGER.info('Removing orphaned files from %s', expected_syzygy_dir) | |
| 387 if not options.dry_run: | |
| 388 shutil.rmtree(expected_syzygy_dir, True, OnError) | |
| 389 | |
| 390 | |
| 391 def main(): | |
| 367 options = _ParseCommandLine() | 392 options = _ParseCommandLine() |
| 368 | 393 |
| 369 if options.dry_run: | 394 if options.dry_run: |
| 370 _LOGGER.debug('Performing a dry-run.') | 395 _LOGGER.debug('Performing a dry-run.') |
| 371 | 396 |
| 397 # We only care about Windows platforms, as the Syzygy binaries aren't used | |
| 398 # elsewhere. However, there was a short period of time where this script | |
| 399 # wasn't gated on OS types, and those OSes downloaded and installed binaries. | |
| 400 # This will cleanup orphaned files on those operating systems. | |
| 401 if sys.platform not in ('win32', 'cygwin'): | |
| 402 return _RemoveOrphanedFiles(options) | |
| 403 | |
| 372 # Load the current installation state, and validate it against the | 404 # Load the current installation state, and validate it against the |
| 373 # requested installation. | 405 # requested installation. |
| 374 state, is_consistent = _GetCurrentState(options.revision, options.output_dir) | 406 state, is_consistent = _GetCurrentState(options.revision, options.output_dir) |
| 375 | 407 |
| 376 # Decide whether or not an install is necessary. | 408 # Decide whether or not an install is necessary. |
| 377 if options.force: | 409 if options.force: |
| 378 _LOGGER.debug('Forcing reinstall of binaries.') | 410 _LOGGER.debug('Forcing reinstall of binaries.') |
| 379 elif is_consistent: | 411 elif is_consistent: |
| 380 # Avoid doing any work if the contents of the directory are consistent. | 412 # Avoid doing any work if the contents of the directory are consistent. |
| 381 _LOGGER.debug('State unchanged, no reinstall necessary.') | 413 _LOGGER.debug('State unchanged, no reinstall necessary.') |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 401 # Install the new binaries. In a dry-run this will actually download the | 433 # Install the new binaries. In a dry-run this will actually download the |
| 402 # archives, but it won't write anything to disk. | 434 # archives, but it won't write anything to disk. |
| 403 state = _InstallBinaries(options, deleted) | 435 state = _InstallBinaries(options, deleted) |
| 404 | 436 |
| 405 # Build and save the state for the directory. | 437 # Build and save the state for the directory. |
| 406 _SaveState(options.output_dir, state, options.dry_run) | 438 _SaveState(options.output_dir, state, options.dry_run) |
| 407 | 439 |
| 408 | 440 |
| 409 if __name__ == '__main__': | 441 if __name__ == '__main__': |
| 410 main() | 442 main() |
| OLD | NEW |