Chromium Code Reviews| Index: download_firefox_nightly.py |
| =================================================================== |
| --- download_firefox_nightly.py (revision 293895) |
| +++ download_firefox_nightly.py (working copy) |
| @@ -31,12 +31,37 @@ |
| os.utime(a_file, None) |
| -def _FindFallbackFirefoxBuild(target_dir): |
| +def _GetFirefoxArchivesSortedOnModifiedDate(target_dir): |
| firefox_archives = glob.glob(os.path.join(target_dir, '*tar.bz2')) |
| if not firefox_archives: |
| return None |
| firefox_archives.sort(key=os.path.getmtime, reverse=True) |
| + return firefox_archives |
| + |
| + |
| +def _CleanOldFirefoxArchives(target_dir): |
| + firefox_archives = _GetFirefoxArchivesSortedOnModifiedDate(target_dir) |
| + if not firefox_archives: |
|
kjellander_chromium
2015/02/02 09:45:00
Add:
or len(firefox_archives) < 2
condition here?
phoglund_chromium
2015/02/02 10:04:11
Done.
|
| + return |
| + if len(firefox_archives) < 2: |
| + return |
| + |
| + # Keep the newest archive around as a fallback build and delete the rest. |
| + rest = firefox_archives[1:] |
| + print 'About to delete old Firefox archives %s.' % rest |
| + for old_archive in rest: |
| + try: |
| + os.remove(old_archive) |
| + except OSError: |
| + pass |
|
kjellander_chromium
2015/02/02 09:45:00
I think it's unlikely we will fail to delete these
phoglund_chromium
2015/02/02 10:04:11
I don't think so. If we fail here it's not enough
kjellander_chromium
2015/02/02 10:13:46
Fair enough. Worst case we'll just run out of disk
|
| + |
| + |
| +def _FindFallbackFirefoxBuild(target_dir): |
| + firefox_archives = _GetFirefoxArchivesSortedOnModifiedDate(target_dir) |
| + if not firefox_archives: |
| + return None |
| + |
| newest_build = firefox_archives[0] |
| build_age_seconds = time.time() - os.path.getmtime(newest_build) |
| build_age_days = datetime.timedelta(seconds=build_age_seconds).days |
| @@ -116,6 +141,9 @@ |
| parser.add_option('-f', '--force', action='store_true', |
| help=('Force download even if the current nightly is ' |
| 'already downloaded.')) |
| + parser.add_option('-c', '--clean-old-archives', action='store_true', |
| + help=('Clean old firefox archives; one will always be ' |
| + 'kept as a fallback.')) |
| options, _args = parser.parse_args() |
| if not options.target_dir: |
| parser.error('You must specify the target directory.') |
| @@ -128,5 +156,8 @@ |
| if firefox_archive: |
| return _ExtractArchive(firefox_archive, target_dir) |
| + if options.clean_old_archives: |
| + _CleanOldFirefoxArchives(target_dir) |
| + |
| if __name__ == '__main__': |
| sys.exit(main()) |