| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 """Downloads a Firefox Nightly build for the current platform.""" | 6 """Downloads a Firefox Nightly build for the current platform.""" |
| 7 | 7 |
| 8 import datetime | 8 import datetime |
| 9 import glob | 9 import glob |
| 10 import os | 10 import os |
| 11 import shutil | 11 import shutil |
| 12 import sys | 12 import sys |
| 13 import subprocess | 13 import subprocess |
| 14 import tarfile | 14 import tarfile |
| 15 import time | 15 import time |
| 16 import zipfile | 16 import zipfile |
| 17 | 17 |
| 18 from optparse import OptionParser | 18 from optparse import OptionParser |
| 19 | 19 |
| 20 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 20 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 21 THIRD_PARTY_DIR = os.path.abspath(os.path.join(BASE_DIR, 'third_party')) | 21 THIRD_PARTY_DIR = os.path.abspath(os.path.join(BASE_DIR, 'third_party')) |
| 22 | 22 |
| 23 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozdownload')) | 23 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozdownload')) |
| 24 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozinfo')) | 24 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozinfo')) |
| 25 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'requests')) |
| 25 | 26 |
| 27 from mozdownload import errors |
| 26 from mozdownload import scraper | 28 from mozdownload import scraper |
| 27 import utils | 29 import utils |
| 28 | 30 |
| 29 | 31 |
| 30 def _Touch(a_file): | 32 def _Touch(a_file): |
| 31 with open(a_file, 'a'): | 33 with open(a_file, 'a'): |
| 32 os.utime(a_file, None) | 34 os.utime(a_file, None) |
| 33 | 35 |
| 34 | 36 |
| 35 def _GetFirefoxArchivesSortedOnModifiedDate(target_dir): | 37 def _GetFirefoxArchivesSortedOnModifiedDate(target_dir): |
| (...skipping 27 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 newest_build = firefox_archives[0] | 66 newest_build = firefox_archives[0] |
| 65 build_age_seconds = time.time() - os.path.getmtime(newest_build) | 67 build_age_seconds = time.time() - os.path.getmtime(newest_build) |
| 66 build_age_days = datetime.timedelta(seconds=build_age_seconds).days | 68 build_age_days = datetime.timedelta(seconds=build_age_seconds).days |
| 67 | 69 |
| 68 return newest_build, build_age_days | 70 return newest_build, build_age_days |
| 69 | 71 |
| 70 | 72 |
| 71 def _MaybeDownload(target_dir, force): | 73 def _MaybeDownload(target_dir, force): |
| 72 try: | 74 try: |
| 73 downloader = scraper.DailyScraper(directory=target_dir, version=None) | 75 downloader = scraper.DailyScraper(destination=target_dir) |
| 74 filename = downloader.build_filename(downloader.binary) | 76 filename = downloader.build_filename(downloader.binary) |
| 75 firefox_archive = os.path.join(target_dir, filename) | 77 firefox_archive = os.path.join(target_dir, filename) |
| 76 | 78 |
| 77 if os.path.exists(firefox_archive) and not force: | 79 if os.path.exists(firefox_archive) and not force: |
| 78 # Touch the file anyway since we were 'successful', so we can accurately | 80 # Touch the file anyway since we were 'successful', so we can accurately |
| 79 # compute the age of the most recent download attempt and act accordingly | 81 # compute the age of the most recent download attempt and act accordingly |
| 80 # when a download fails later. | 82 # when a download fails later. |
| 81 _Touch(firefox_archive) | 83 _Touch(firefox_archive) |
| 82 print 'Skipping download as %s is already downloaded.' % firefox_archive | 84 print 'Skipping download as %s is already downloaded.' % firefox_archive |
| 83 return None | 85 return None |
| 84 | 86 |
| 85 downloader.download() | 87 downloader.download() |
| 86 print 'Downloaded %s' % firefox_archive | 88 print 'Downloaded %s' % firefox_archive |
| 87 return firefox_archive | 89 return firefox_archive |
| 88 except scraper.NotFoundException as exception: | 90 except errors.NotFoundError as exception: |
| 89 print 'Failed to download firefox: %s.' % exception | 91 print 'Failed to download firefox: %s.' % exception |
| 90 fallback_build, age_days = _FindFallbackFirefoxBuild(target_dir) | 92 fallback_build, age_days = _FindFallbackFirefoxBuild(target_dir) |
| 91 | 93 |
| 92 if not fallback_build: | 94 if not fallback_build: |
| 93 raise Exception('We failed to download Firefox and we have no builds to ' | 95 raise Exception('We failed to download Firefox and we have no builds to ' |
| 94 'fall back on; failing...') | 96 'fall back on; failing...') |
| 95 if age_days > 3: | 97 if age_days > 3: |
| 96 raise Exception('We have failed to download firefox builds for more ' | 98 raise Exception('We have failed to download firefox builds for more ' |
| 97 'than 3 days now: failing so someone looks at it. The ' | 99 'than 3 days now: failing so someone looks at it. The ' |
| 98 'most recent build we have is %d days old.' % age_days) | 100 'most recent build we have is %d days old.' % age_days) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 139 |
| 138 firefox_archive = _MaybeDownload(target_dir, options.force) | 140 firefox_archive = _MaybeDownload(target_dir, options.force) |
| 139 if firefox_archive: | 141 if firefox_archive: |
| 140 _ExtractArchive(firefox_archive, target_dir) | 142 _ExtractArchive(firefox_archive, target_dir) |
| 141 | 143 |
| 142 if options.clean_old_firefox_archives: | 144 if options.clean_old_firefox_archives: |
| 143 _CleanOldFirefoxArchives(target_dir) | 145 _CleanOldFirefoxArchives(target_dir) |
| 144 | 146 |
| 145 if __name__ == '__main__': | 147 if __name__ == '__main__': |
| 146 sys.exit(main()) | 148 sys.exit(main()) |
| OLD | NEW |