|
OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | |
kjellander_chromium
2013/12/16 12:59:04
Please change to Chromium's license.
phoglund_chromium
2013/12/16 14:38:46
Done.
| |
3 # | |
4 # Use of this source code is governed by a BSD-style license | |
5 # that can be found in the LICENSE file in the root of the source | |
6 # tree. An additional intellectual property rights grant can be found | |
7 # in the file PATENTS. All contributing project authors may | |
8 # be found in the AUTHORS file in the root of the source tree. | |
9 | |
10 """Downloads a Firefox Nightly build for the current platform.""" | |
11 | |
12 import os | |
13 import shutil | |
14 import sys | |
15 import subprocess | |
16 import tarfile | |
17 import zipfile | |
18 | |
19 from optparse import OptionParser | |
20 | |
21 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
22 THIRD_PARTY_DIR = os.path.abspath(os.path.join(BASE_DIR, 'third_party')) | |
23 | |
24 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozdownload')) | |
25 sys.path.append(os.path.join(THIRD_PARTY_DIR, 'mozinfo')) | |
26 | |
27 from mozdownload import scraper | |
28 | |
kjellander_chromium
2013/12/16 12:59:04
nit: two blank lines before top-level function.
phoglund_chromium
2013/12/16 14:38:46
Done.
| |
29 def main(): | |
30 usage = 'usage: %prog -t <target_dir>' | |
31 parser = OptionParser(usage) | |
32 parser.add_option('-t', '--target-dir', | |
33 help=('Target directory to put the downloaded and extracted' | |
34 ' folder with the Firefox Nightly build in.')) | |
35 parser.add_option('-f', '--force', action='store_true', | |
36 help=('Force download even if the current nightly is ' | |
37 'already downloaded.')) | |
38 options, _args = parser.parse_args() | |
39 if not options.target_dir: | |
40 parser.error('You must specify the target directory.') | |
41 | |
42 target_dir = options.target_dir | |
43 if not os.path.isdir(target_dir): | |
44 os.mkdir(target_dir) | |
45 | |
46 downloader = scraper.DailyScraper(directory=target_dir, version=None) | |
47 firefox_archive = os.path.join(target_dir, | |
48 downloader.build_filename(downloader.binary)) | |
49 | |
50 if os.path.exists(firefox_archive) and not options.force: | |
51 print 'Skipping download as %s is already downloaded.' % firefox_archive | |
52 return 0 | |
53 | |
54 downloader.download() | |
55 print 'Downloaded %s' % firefox_archive | |
56 | |
57 # Extract the archive. | |
58 if sys.platform == 'darwin': | |
59 volume = '/Volumes/Nightly' | |
60 firefox_executable = '%s/FirefoxNightly.app' % target_dir | |
61 | |
62 # Unmount any previous downloads. | |
63 subprocess.call(['hdiutil', 'detach', volume]) | |
64 | |
65 subprocess.check_call(['hdiutil', 'attach', firefox_archive]) | |
66 shutil.copytree('%s/FirefoxNightly.app' % volume, firefox_executable) | |
67 subprocess.check_call(['hdiutil', 'detach', volume]) | |
68 elif sys.platform == 'linux2': | |
69 tar_archive = tarfile.open(firefox_archive, 'r:bz2') | |
70 tar_archive.extractall(path=target_dir) | |
71 elif sys.platform == 'win32': | |
72 zip_archive = zipfile.ZipFile(firefox_archive) | |
73 zip_archive.extractall(path=target_dir) | |
74 else: | |
75 print >> sys.stderr, 'Unsupported platform: %s' % sys.platform | |
76 return 1 | |
77 | |
78 print 'Extracted %s' % firefox_archive | |
79 return 0 | |
80 | |
81 if __name__ == '__main__': | |
82 sys.exit(main()) | |
OLD | NEW |