Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 # Run to install the necessary components to run webdriver on the buildbots or | 7 # Run to install the necessary components to run webdriver on the buildbots or |
| 8 # on your local machine. | 8 # on your local machine. |
| 9 # Note: The setup steps can be done fairly easily by hand. This script is | 9 # Note: The setup steps can be done fairly easily by hand. This script is |
| 10 # intended to simply and reduce the time for setup since there are a fair number | 10 # intended to simply and reduce the time for setup since there are a fair number |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 depot_tools = os.path.join('e:', depot_tools) | 74 depot_tools = os.path.join('e:', depot_tools) |
| 75 return depot_tools | 75 return depot_tools |
| 76 else: | 76 else: |
| 77 path = os.environ['PATH'].split(os.pathsep) | 77 path = os.environ['PATH'].split(os.pathsep) |
| 78 for loc in path: | 78 for loc in path: |
| 79 if 'depot_tools' in loc: | 79 if 'depot_tools' in loc: |
| 80 return loc | 80 return loc |
| 81 raise Exception("Could not find depot_tools in your path.") | 81 raise Exception("Could not find depot_tools in your path.") |
| 82 | 82 |
| 83 | 83 |
| 84 class GoogleCodeInstaller(object): | 84 class ChromeDriverInstaller(object): |
|
Emily Fortuna
2013/10/21 17:19:38
This is a bad idea as the Dart browser driver does
| |
| 85 """Install code that is being hosted on Google Code.""" | 85 """Install ChromeDriver from Google Storage.""" |
| 86 | 86 |
| 87 def __init__(self, project_name, download_location, download_name_func): | 87 def __init__(self, download_location): |
| 88 """ Create a object that will install code from a Google Code site. | 88 """ Create an object that will install ChromeDriver from Google Storage. |
| 89 Arguments: | 89 Arguments: |
| 90 project_name - The GoogleCode project name such as "selenium" or | |
| 91 "chromedriver." | |
| 92 download_location - Where to download the desired file on our filesystem. | 90 download_location - Where to download the desired file on our filesystem. |
| 93 download_name_func - A function that takes a dictionary (currently with keys | |
| 94 "os" and "version", but more can be added) that calculates the string | |
| 95 representing the name of the download we want. | |
| 96 """ | 91 """ |
| 97 self.project_name = project_name | |
| 98 self.download_location = download_location | 92 self.download_location = download_location |
| 99 self.download_name_func = download_name_func | 93 self.project_name = 'chromedriver' |
| 100 self.download_regex_str = self.download_name_func({'os': self.get_os_str, | 94 self.google_storage_downloads_page = 'http://chromedriver.storage.googleapis .com' |
| 101 'version': '.+'}) | |
| 102 | 95 |
| 103 def google_code_downloads_page(self): | |
| 104 return 'http://code.google.com/p/%s/downloads/list' % self.project_name | |
| 105 | |
| 106 def google_code_download(self): | |
| 107 return 'http://%s.googlecode.com/files/' % self.project_name | |
| 108 | 96 |
| 109 def find_latest_version(self): | 97 def find_latest_version(self): |
| 110 """Find the latest version number of some code available for download on a | 98 """Find the latest version number of ChromeDriver.""" |
| 111 Google code page. This was unfortunately done in an ad hoc manner because | 99 f = urllib2.urlopen(self.google_storage_downloads_page) |
| 112 Google Code does not seem to have an API for their list of current | |
| 113 downloads(!). | |
| 114 """ | |
| 115 google_code_site = self.google_code_downloads_page() | |
| 116 f = urllib2.urlopen(google_code_site) | |
| 117 latest = '' | 100 latest = '' |
| 118 for line in f.readlines(): | 101 l = f.read() |
| 119 if re.search(self.download_regex_str, line): | 102 r = re.compile('(?:<Key>)(\d+\.\d+)') |
| 120 suffix_index = line.find( | 103 v = max(r.findall(l)) |
| 121 self.download_regex_str[self.download_regex_str.rfind('.'):]) | 104 return v |
| 122 name_end = self.download_regex_str.rfind('.+') | |
| 123 name = self.download_name_func({'os': self.get_os_str, 'version': ''}) | |
| 124 name = name[:name.rfind('.')] | |
| 125 version_str = line[line.find(name) + len(name) : suffix_index] | |
| 126 orig_version_str = version_str | |
| 127 if version_str.count('.') == 0: | |
| 128 version_str = version_str.replace('_', '.') | |
| 129 version_str = re.compile(r'[^\d.]+').sub('', version_str) | |
| 130 if latest == '': | |
| 131 latest = '0.' * version_str.count('.') | |
| 132 latest += '0' | |
| 133 orig_latest_str = latest | |
| 134 else: | |
| 135 orig_latest_str = latest | |
| 136 latest = latest.replace('_', '.') | |
| 137 » latest = re.compile(r'[^\d.]+').sub('', latest) | |
| 138 nums = version_str.split('.') | |
| 139 latest_nums = latest.split('.') | |
| 140 for (num, latest_num) in zip(nums, latest_nums): | |
| 141 if int(num) > int(latest_num): | |
| 142 latest = orig_version_str | |
| 143 break | |
| 144 else: | |
| 145 latest = orig_latest_str | |
| 146 if latest == '': | |
| 147 raise Exception("Couldn't find the desired download on " + \ | |
| 148 ' %s.' % google_code_site) | |
| 149 return latest | |
| 150 | 105 |
| 151 def run(self): | 106 def run(self): |
| 152 """Download and install the Google Code.""" | 107 """Download and install the Google Code.""" |
| 153 print 'Installing from %s' % self.project_name | 108 print 'Installing from %s' % self.project_name |
| 154 os_str = self.get_os_str | 109 os_str = self.get_os_str |
| 155 version = self.find_latest_version() | 110 version = self.find_latest_version() |
| 156 download_name = self.download_name_func({'os': os_str, 'version': version}) | 111 download_name = 'chromedriver_%s.zip' % os_str |
| 157 urllib.urlretrieve(self.google_code_download() + '/' + download_name, | 112 |
| 113 urllib.urlretrieve(self.google_storage_downloads_page + '/' + version + | |
| 114 '/chromedriver_' + os_str + '.zip', | |
| 158 os.path.join(self.download_location, download_name)) | 115 os.path.join(self.download_location, download_name)) |
| 159 if download_name.endswith('.zip'): | 116 |
| 160 if platform.system() != 'Windows': | 117 if platform.system() != 'Windows': |
| 161 # The Python zip utility does not preserve executable permissions, but | 118 # The Python zip utility does not preserve executable permissions, but |
| 162 # this does not seem to be a problem for Windows, which does not have a | 119 # this does not seem to be a problem for Windows, which does not have a |
| 163 # built in zip utility. :-/ | 120 # built in zip utility. :-/ |
| 164 run_cmd('unzip -u %s -d %s' % (os.path.join(self.download_location, | 121 run_cmd('unzip -u %s -d %s' % (os.path.join(self.download_location, |
| 165 download_name), self.download_location), stdin='y') | 122 download_name), self.download_location), stdin='y') |
| 166 else: | 123 else: |
| 167 z = zipfile.ZipFile(os.path.join(self.download_location, download_name)) | 124 z = zipfile.ZipFile(os.path.join(self.download_location, download_name)) |
| 168 z.extractall(self.download_location) | 125 z.extractall(self.download_location) |
| 169 z.close() | 126 z.close() |
| 170 os.remove(os.path.join(self.download_location, download_name)) | 127 os.remove(os.path.join(self.download_location, download_name)) |
| 128 | |
| 171 chrome_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | 129 chrome_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 172 'orig-chromedriver') | 130 'orig-chromedriver') |
| 173 if self.project_name == 'chromedriver' and os.path.exists(chrome_path): | 131 if self.project_name == 'chromedriver' and os.path.exists(chrome_path): |
| 174 # We have one additional location to make sure chromedriver is updated. | 132 # We have one additional location to make sure chromedriver is updated. |
| 175 # TODO(efortuna): Remove this. See move_chrome_driver_if_needed in | 133 # TODO(efortuna): Remove this. See move_chrome_driver_if_needed in |
| 176 # perf_testing/run_perf_tests.py | 134 # perf_testing/run_perf_tests.py |
| 177 driver = 'chromedriver' | 135 driver = 'chromedriver' |
| 178 if platform.system() == 'Windows': | 136 if platform.system() == 'Windows': |
| 179 driver += '.exe' | 137 driver += '.exe' |
| 180 shutil.copy(os.path.join(self.download_location, driver), | 138 shutil.copy(os.path.join(self.download_location, driver), |
| 181 os.path.join(chrome_path, driver)) | 139 os.path.join(chrome_path, driver)) |
| 182 | 140 |
| 183 @property | 141 @property |
| 184 def get_os_str(self): | 142 def get_os_str(self): |
| 185 """The strings to indicate what OS a download is for as used on Google Code. | 143 """The strings to indicate what OS a download is for. |
| 186 """ | 144 """ |
| 187 os_str = 'win' | 145 os_str = 'win' |
| 188 if 'darwin' in sys.platform: | 146 if 'darwin' in sys.platform: |
| 189 os_str = 'mac' | 147 os_str = 'mac' |
| 190 elif 'linux' in sys.platform: | 148 elif 'linux' in sys.platform: |
| 191 os_str = 'linux32' | 149 os_str = 'linux32' |
| 192 if '64bit' in platform.architecture()[0]: | 150 if '64bit' in platform.architecture()[0]: |
| 193 os_str = 'linux64' | 151 os_str = 'linux64' |
| 194 if self.project_name == 'chromedriver' and ( | 152 if self.project_name == 'chromedriver' and ( |
| 195 os_str == 'mac' or os_str == 'win'): | 153 os_str == 'mac' or os_str == 'win'): |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 os_str = 'mac' | 344 os_str = 'mac' |
| 387 elif 'linux' in sys.platform: | 345 elif 'linux' in sys.platform: |
| 388 os_str = 'linux' | 346 os_str = 'linux' |
| 389 return os_str | 347 return os_str |
| 390 | 348 |
| 391 def main(): | 349 def main(): |
| 392 args = parse_args() | 350 args = parse_args() |
| 393 if not args.python: | 351 if not args.python: |
| 394 SeleniumBindingsInstaller(args.buildbot).run() | 352 SeleniumBindingsInstaller(args.buildbot).run() |
| 395 if not args.chromedriver: | 353 if not args.chromedriver: |
| 396 GoogleCodeInstaller('chromedriver', | 354 ChromeDriverInstaller(find_depot_tools_location(args.buildbot)).run() |
| 397 find_depot_tools_location(args.buildbot), | |
| 398 lambda x: 'chromedriver_%(os)s_%(version)s.zip' % x).run() | |
| 399 if not args.seleniumrc: | |
| 400 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), | |
| 401 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() | |
| 402 if not args.iedriver and platform.system() == 'Windows': | |
| 403 GoogleCodeInstaller('selenium', find_depot_tools_location(args.buildbot), | |
| 404 lambda x: 'IEDriverServer_Win32_%(version)s.zip' % x).run() | |
| 405 if not args.firefox: | 355 if not args.firefox: |
| 406 FirefoxInstaller().run() | 356 FirefoxInstaller().run() |
| 407 if not args.opera: | 357 if not args.opera: |
| 408 OperaInstaller().run() | 358 OperaInstaller().run() |
| 409 | 359 |
| 410 if __name__ == '__main__': | 360 if __name__ == '__main__': |
| 411 main() | 361 main() |
| OLD | NEW |