Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: download_firefox_nightly.py

Issue 891303002: Now cleaning old firefox archives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/webrtc/webrtc.DEPS/
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 13 matching lines...) Expand all
24 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozinfo')) 24 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozinfo'))
25 25
26 from mozdownload import scraper 26 from mozdownload import scraper
27 27
28 28
29 def _Touch(a_file): 29 def _Touch(a_file):
30 with open(a_file, 'a'): 30 with open(a_file, 'a'):
31 os.utime(a_file, None) 31 os.utime(a_file, None)
32 32
33 33
34 def _FindFallbackFirefoxBuild(target_dir): 34 def _GetFirefoxArchivesSortedOnModifiedDate(target_dir):
35 firefox_archives = glob.glob(os.path.join(target_dir, '*tar.bz2')) 35 firefox_archives = glob.glob(os.path.join(target_dir, '*tar.bz2'))
36 if not firefox_archives: 36 if not firefox_archives:
37 return None 37 return None
38 38
39 firefox_archives.sort(key=os.path.getmtime, reverse=True) 39 firefox_archives.sort(key=os.path.getmtime, reverse=True)
40 return firefox_archives
41
42
43 def _CleanOldFirefoxArchives(target_dir):
44 firefox_archives = _GetFirefoxArchivesSortedOnModifiedDate(target_dir)
45 if not firefox_archives or len(firefox_archives) < 2:
46 return
47
48 # Keep the newest archive around as a fallback build and delete the rest.
49 rest = firefox_archives[1:]
50 print 'About to delete old Firefox archives %s.' % rest
51 for old_archive in rest:
52 try:
53 os.remove(old_archive)
54 except OSError:
55 pass
56
57
58 def _FindFallbackFirefoxBuild(target_dir):
59 firefox_archives = _GetFirefoxArchivesSortedOnModifiedDate(target_dir)
60 if not firefox_archives:
61 return None
62
40 newest_build = firefox_archives[0] 63 newest_build = firefox_archives[0]
41 build_age_seconds = time.time() - os.path.getmtime(newest_build) 64 build_age_seconds = time.time() - os.path.getmtime(newest_build)
42 build_age_days = datetime.timedelta(seconds=build_age_seconds).days 65 build_age_days = datetime.timedelta(seconds=build_age_seconds).days
43 66
44 return newest_build, build_age_days 67 return newest_build, build_age_days
45 68
46 69
47 def _MaybeDownload(target_dir, force): 70 def _MaybeDownload(target_dir, force):
48 try: 71 try:
49 downloader = scraper.DailyScraper(directory=target_dir, version=None) 72 downloader = scraper.DailyScraper(directory=target_dir, version=None)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 132
110 def main(): 133 def main():
111 usage = 'usage: %prog -t <target_dir>' 134 usage = 'usage: %prog -t <target_dir>'
112 parser = OptionParser(usage) 135 parser = OptionParser(usage)
113 parser.add_option('-t', '--target-dir', 136 parser.add_option('-t', '--target-dir',
114 help=('Target directory to put the downloaded and extracted' 137 help=('Target directory to put the downloaded and extracted'
115 ' folder with the Firefox Nightly build in.')) 138 ' folder with the Firefox Nightly build in.'))
116 parser.add_option('-f', '--force', action='store_true', 139 parser.add_option('-f', '--force', action='store_true',
117 help=('Force download even if the current nightly is ' 140 help=('Force download even if the current nightly is '
118 'already downloaded.')) 141 'already downloaded.'))
142 parser.add_option('-c', '--clean-old-archives', action='store_true',
143 help=('Clean old firefox archives; one will always be '
144 'kept as a fallback.'))
119 options, _args = parser.parse_args() 145 options, _args = parser.parse_args()
120 if not options.target_dir: 146 if not options.target_dir:
121 parser.error('You must specify the target directory.') 147 parser.error('You must specify the target directory.')
122 148
123 target_dir = options.target_dir 149 target_dir = options.target_dir
124 if not os.path.isdir(target_dir): 150 if not os.path.isdir(target_dir):
125 os.mkdir(target_dir) 151 os.mkdir(target_dir)
126 152
127 firefox_archive = _MaybeDownload(target_dir, options.force) 153 firefox_archive = _MaybeDownload(target_dir, options.force)
128 if firefox_archive: 154 if firefox_archive:
129 return _ExtractArchive(firefox_archive, target_dir) 155 return _ExtractArchive(firefox_archive, target_dir)
130 156
157 if options.clean_old_archives:
158 _CleanOldFirefoxArchives(target_dir)
159
131 if __name__ == '__main__': 160 if __name__ == '__main__':
132 sys.exit(main()) 161 sys.exit(main())
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698