| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """CBuildbot is wrapper around the build process used by the pre-flight queue""" | 7 """CBuildbot is wrapper around the build process used by the pre-flight queue""" |
| 8 | 8 |
| 9 import errno | 9 import errno |
| 10 import heapq | 10 import heapq |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 test_results_dir: Path from buildroot/chroot to find test results. This must | 399 test_results_dir: Path from buildroot/chroot to find test results. This must |
| 400 a subdir of /tmp. | 400 a subdir of /tmp. |
| 401 """ | 401 """ |
| 402 test_results_dir = test_results_dir.lstrip('/') | 402 test_results_dir = test_results_dir.lstrip('/') |
| 403 if not os.path.exists(ARCHIVE_BASE): | 403 if not os.path.exists(ARCHIVE_BASE): |
| 404 os.makedirs(ARCHIVE_BASE) | 404 os.makedirs(ARCHIVE_BASE) |
| 405 else: | 405 else: |
| 406 dir_entries = os.listdir(ARCHIVE_BASE) | 406 dir_entries = os.listdir(ARCHIVE_BASE) |
| 407 if len(dir_entries) >= ARCHIVE_COUNT: | 407 if len(dir_entries) >= ARCHIVE_COUNT: |
| 408 oldest_dirs = heapq.nsmallest((len(dir_entries) - ARCHIVE_COUNT) + 1, | 408 oldest_dirs = heapq.nsmallest((len(dir_entries) - ARCHIVE_COUNT) + 1, |
| 409 [filename for filename in dir_entries], | 409 [os.path.join(ARCHIVE_BASE, filename) for filename in dir_entries], |
| 410 key=lambda fn: os.stat(fn).st_mtime) | 410 key=lambda fn: os.stat(fn).st_mtime) |
| 411 Info('Removing archive dirs %s' % oldest_dirs) | 411 Info('Removing archive dirs %s' % oldest_dirs) |
| 412 for oldest_dir in oldest_dirs: | 412 for oldest_dir in oldest_dirs: |
| 413 shutil.rmtree(os.path.join(ARCHIVE_BASE, oldest_dir)) | 413 shutil.rmtree(os.path.join(ARCHIVE_BASE, oldest_dir)) |
| 414 | 414 |
| 415 archive_target = os.path.join(ARCHIVE_BASE, str(archive_dir)) | 415 archive_target = os.path.join(ARCHIVE_BASE, str(archive_dir)) |
| 416 if os.path.exists(archive_target): | 416 if os.path.exists(archive_target): |
| 417 shutil.rmtree(archive_target) | 417 shutil.rmtree(archive_target) |
| 418 | 418 |
| 419 results_path = os.path.join(buildroot, 'chroot', test_results_dir) | 419 results_path = os.path.join(buildroot, 'chroot', test_results_dir) |
| 420 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) | 420 RunCommand(['sudo', 'chmod', '-R', '+r', results_path]) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 except: | 543 except: |
| 544 # Send failure to master bot. | 544 # Send failure to master bot. |
| 545 if not buildconfig['master'] and buildconfig['important']: | 545 if not buildconfig['master'] and buildconfig['important']: |
| 546 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 546 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
| 547 | 547 |
| 548 raise | 548 raise |
| 549 | 549 |
| 550 | 550 |
| 551 if __name__ == '__main__': | 551 if __name__ == '__main__': |
| 552 main() | 552 main() |
| OLD | NEW |