OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2014 The Chromium 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 """Gets a Chromium archived build, and unpacks it | 7 """Gets a Chromium archived build, and unpacks it |
8 into a target directory. | 8 into a target directory. |
9 | 9 |
10 Use -r option to specify the revison number | 10 Use -r option to specify the revison number |
11 Use -t option to specify the directory to unzip the build into. | 11 Use -t option to specify the directory to unzip the build into. |
12 | 12 |
13 Usage: | 13 Usage: |
14 $ get_chromium_build.py -r <revision> -t <target> | 14 $ get_chromium_build.py -r <revision> -t <target> |
15 """ | 15 """ |
16 | 16 |
17 import json | |
18 import logging | 17 import logging |
19 import optparse | 18 import optparse |
20 import os | 19 import os |
21 import platform | 20 import platform |
22 import shutil | 21 import shutil |
23 import subprocess | 22 import subprocess |
24 import sys | 23 import sys |
25 import time | 24 import time |
26 import urllib | 25 import urllib |
27 import urllib2 | 26 import urllib2 |
(...skipping 15 matching lines...) Expand all Loading... |
43 'Windows': {'zipfiles': ['chrome-win32.zip', | 42 'Windows': {'zipfiles': ['chrome-win32.zip', |
44 'chrome-win32-syms.zip'], | 43 'chrome-win32-syms.zip'], |
45 'folder': 'chrome_win', | 44 'folder': 'chrome_win', |
46 'archive_path': 'Win'}} | 45 'archive_path': 'Win'}} |
47 | 46 |
48 def __init__(self, options): | 47 def __init__(self, options): |
49 platform_data = BuildUpdater._PLATFORM_PATHS_MAP[platform.system()] | 48 platform_data = BuildUpdater._PLATFORM_PATHS_MAP[platform.system()] |
50 self._zipfiles = platform_data['zipfiles'] | 49 self._zipfiles = platform_data['zipfiles'] |
51 self._folder = platform_data['folder'] | 50 self._folder = platform_data['folder'] |
52 self._archive_path = platform_data['archive_path'] | 51 self._archive_path = platform_data['archive_path'] |
53 self._revision = options.revision | 52 self._revision = int(options.revision) |
54 self._target_dir = options.target_dir | 53 self._target_dir = options.target_dir |
55 self._download_dir = os.path.join(self._target_dir, 'downloads') | 54 self._download_dir = os.path.join(self._target_dir, 'downloads') |
56 | 55 |
57 def _GetBuildUrl(self, revision, filename): | 56 def _GetBuildUrl(self, revision, filename): |
58 return CHROMIUM_URL_FMT % (self._archive_path, revision, filename) | 57 return CHROMIUM_URL_FMT % (self._archive_path, revision, filename) |
59 | 58 |
60 def _FindBuildRevision(self, revision, filename): | 59 def _FindBuildRevision(self, revision, filename): |
61 git_hash = json.loads(revision)[platform.system()] | 60 MAX_REVISIONS_PER_BUILD = 100 |
62 if self._DoesBuildExist(git_hash, filename): | 61 for revision_guess in xrange(revision, revision + MAX_REVISIONS_PER_BUILD): |
63 return git_hash | 62 if self._DoesBuildExist(revision_guess, filename): |
| 63 return revision_guess |
| 64 else: |
| 65 time.sleep(.1) |
64 return None | 66 return None |
65 | 67 |
66 def _DoesBuildExist(self, revision_guess, filename): | 68 def _DoesBuildExist(self, revision_guess, filename): |
67 url = self._GetBuildUrl(revision_guess, filename) | 69 url = self._GetBuildUrl(revision_guess, filename) |
68 | 70 |
69 r = urllib2.Request(url) | 71 r = urllib2.Request(url) |
70 r.get_method = lambda: 'HEAD' | 72 r.get_method = lambda: 'HEAD' |
71 try: | 73 try: |
72 urllib2.urlopen(r) | 74 urllib2.urlopen(r) |
73 return True | 75 return True |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 162 |
161 def main(argv): | 163 def main(argv): |
162 logging.getLogger().setLevel(logging.DEBUG) | 164 logging.getLogger().setLevel(logging.DEBUG) |
163 options = ParseOptions(argv) | 165 options = ParseOptions(argv) |
164 b = BuildUpdater(options) | 166 b = BuildUpdater(options) |
165 b.DownloadAndUpdateBuild() | 167 b.DownloadAndUpdateBuild() |
166 logging.info('Successfully got archived Chromium build.') | 168 logging.info('Successfully got archived Chromium build.') |
167 | 169 |
168 if __name__ == '__main__': | 170 if __name__ == '__main__': |
169 sys.exit(main(sys.argv)) | 171 sys.exit(main(sys.argv)) |
OLD | NEW |