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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 if 'win32' in sys.platform or 'cygwin' in sys.platform: | 73 if 'win32' in sys.platform or 'cygwin' in sys.platform: |
| 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 class GoogleBasedInstaller(object): | |
| 84 """Install a project from the web, pulling latest version.""" | |
|
Emily Fortuna
2013/10/24 19:48:46
update comments?
Andrei Mouravski
2013/10/24 19:51:41
Done.
| |
| 83 | 85 |
| 84 class GoogleCodeInstaller(object): | 86 def __init__(self, project_name, destination, download_path_func): |
| 85 """Install code that is being hosted on Google Code.""" | 87 """Create an object that will install the project. |
| 88 Arguments: | |
| 89 project_name - Name of the project, such as "selenium" or "chromedriver." | |
|
Emily Fortuna
2013/10/24 19:48:46
google code "name of the project"
Andrei Mouravski
2013/10/24 19:51:41
Done.
| |
| 90 destination - Where to download the desired file on our filesystem. | |
| 91 download_path_func - A function that takes a dictionary (currently with keys | |
| 92 "os" and "version", but more can be added) that calculates the string | |
| 93 representing the path of the download we want. | |
| 94 """ | |
| 95 self.project_name = project_name | |
| 96 self.destination = destination | |
| 97 self.download_path_func = download_path_func | |
| 86 | 98 |
| 87 def __init__(self, project_name, download_location, download_name_func): | 99 @property |
| 88 """ Create a object that will install code from a Google Code site. | 100 def get_os_str(self): |
| 89 Arguments: | 101 """The strings to indicate what OS a download is for.""" |
| 90 project_name - The GoogleCode project name such as "selenium" or | 102 os_str = 'win' |
| 91 "chromedriver." | 103 if 'darwin' in sys.platform: |
| 92 download_location - Where to download the desired file on our filesystem. | 104 os_str = 'mac' |
| 93 download_name_func - A function that takes a dictionary (currently with keys | 105 elif 'linux' in sys.platform: |
| 94 "os" and "version", but more can be added) that calculates the string | 106 os_str = 'linux32' |
| 95 representing the name of the download we want. | 107 if '64bit' in platform.architecture()[0]: |
| 96 """ | 108 os_str = 'linux64' |
| 97 self.project_name = project_name | 109 if self.project_name == 'chromedriver' and ( |
| 98 self.download_location = download_location | 110 os_str == 'mac' or os_str == 'win'): |
| 99 self.download_name_func = download_name_func | 111 os_str = os_str + '32' |
| 100 self.download_regex_str = self.download_name_func({'os': self.get_os_str, | 112 return os_str |
| 101 'version': '.+'}) | 113 |
| 114 def run(self): | |
| 115 """Download and install the project.""" | |
| 116 print 'Installing %s' % self.project_name | |
| 117 os_str = self.get_os_str | |
| 118 version = self.find_latest_version() | |
| 119 download_path = self.download_path_func({'os': os_str, 'version': version}) | |
| 120 download_name = os.path.basename(download_path) | |
| 121 urllib.urlretrieve(os.path.join(self.source_path(), download_path), | |
| 122 os.path.join(self.destination, download_name)) | |
| 123 if download_name.endswith('.zip'): | |
| 124 if platform.system() != 'Windows': | |
| 125 # The Python zip utility does not preserve executable permissions, but | |
| 126 # this does not seem to be a problem for Windows, which does not have a | |
| 127 # built in zip utility. :-/ | |
| 128 run_cmd('unzip -u %s -d %s' % (os.path.join(self.destination, | |
| 129 download_name), self.destination), stdin='y') | |
| 130 else: | |
| 131 z = zipfile.ZipFile(os.path.join(self.destination, download_name)) | |
| 132 z.extractall(self.destination) | |
| 133 z.close() | |
| 134 os.remove(os.path.join(self.destination, download_name)) | |
| 135 chrome_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | |
| 136 'orig-chromedriver') | |
| 137 if self.project_name == 'chromedriver' and os.path.exists(chrome_path): | |
| 138 # We have one additional location to make sure chromedriver is updated. | |
| 139 # TODO(efortuna): Remove this. See move_chrome_driver_if_needed in | |
| 140 # perf_testing/run_perf_tests.py | |
| 141 driver = 'chromedriver' | |
| 142 if platform.system() == 'Windows': | |
| 143 driver += '.exe' | |
| 144 shutil.copy(os.path.join(self.destination, driver), | |
| 145 os.path.join(chrome_path, driver)) | |
| 146 | |
| 147 class ChromeDriverInstaller(GoogleBasedInstaller): | |
| 148 """Install chromedriver from Google Storage.""" | |
| 149 | |
| 150 def __init__(self, destination): | |
| 151 """Create an object to install ChromeDriver | |
| 152 destination - Where to download the desired file on our filesystem. | |
| 153 """ | |
| 154 super(ChromeDriverInstaller, self).__init__('chromedriver', destination, | |
| 155 lambda x: '%(version)s/chromedriver_%(os)s.zip' % x) | |
| 156 | |
| 157 def find_latest_version(self): | |
| 158 """Find the latest version number of ChromeDriver.""" | |
| 159 source_page = urllib2.urlopen(self.source_path()) | |
| 160 source_text = source_page.read() | |
| 161 regex = re.compile('(?:<Key>)(\d+\.\d+)') | |
| 162 latest = max(regex.findall(source_text)) | |
| 163 return latest | |
| 164 | |
| 165 def source_path(self): | |
| 166 return 'http://chromedriver.storage.googleapis.com' | |
| 167 | |
| 168 class GoogleCodeInstaller(GoogleBasedInstaller): | |
| 169 """Install a project from Google Code.""" | |
| 102 | 170 |
| 103 def google_code_downloads_page(self): | 171 def google_code_downloads_page(self): |
| 104 return 'http://code.google.com/p/%s/downloads/list' % self.project_name | 172 return 'http://code.google.com/p/%s/downloads/list' % self.project_name |
| 105 | 173 |
| 106 def google_code_download(self): | |
| 107 return 'http://%s.googlecode.com/files/' % self.project_name | |
| 108 | |
| 109 def find_latest_version(self): | 174 def find_latest_version(self): |
| 110 """Find the latest version number of some code available for download on a | 175 """Find the latest version number of some code available for download on a |
| 111 Google code page. This was unfortunately done in an ad hoc manner because | 176 Google code page. This was unfortunately done in an ad hoc manner because |
| 112 Google Code does not seem to have an API for their list of current | 177 Google Code does not seem to have an API for their list of current |
| 113 downloads(!). | 178 downloads(!). |
| 114 """ | 179 """ |
| 115 google_code_site = self.google_code_downloads_page() | 180 google_code_site = self.google_code_downloads_page() |
| 116 f = urllib2.urlopen(google_code_site) | 181 f = urllib2.urlopen(google_code_site) |
| 117 latest = '' | 182 latest = '' |
| 183 | |
| 184 download_regex_str = self.download_path_func({'os': self.get_os_str, | |
| 185 'version': '.+'}) | |
| 186 | |
| 118 for line in f.readlines(): | 187 for line in f.readlines(): |
| 119 if re.search(self.download_regex_str, line): | 188 if re.search(download_regex_str, line): |
| 120 suffix_index = line.find( | 189 suffix_index = line.find( |
| 121 self.download_regex_str[self.download_regex_str.rfind('.'):]) | 190 download_regex_str[download_regex_str.rfind('.'):]) |
| 122 name_end = self.download_regex_str.rfind('.+') | 191 name_end = download_regex_str.rfind('.+') |
| 123 name = self.download_name_func({'os': self.get_os_str, 'version': ''}) | 192 name = self.download_path_func({'os': self.get_os_str, 'version': ''}) |
| 124 name = name[:name.rfind('.')] | 193 name = name[:name.rfind('.')] |
| 125 version_str = line[line.find(name) + len(name) : suffix_index] | 194 version_str = line[line.find(name) + len(name) : suffix_index] |
| 126 orig_version_str = version_str | 195 orig_version_str = version_str |
| 127 if version_str.count('.') == 0: | 196 if version_str.count('.') == 0: |
| 128 version_str = version_str.replace('_', '.') | 197 version_str = version_str.replace('_', '.') |
| 129 version_str = re.compile(r'[^\d.]+').sub('', version_str) | 198 version_str = re.compile(r'[^\d.]+').sub('', version_str) |
| 130 if latest == '': | 199 if latest == '': |
| 131 latest = '0.' * version_str.count('.') | 200 latest = '0.' * version_str.count('.') |
| 132 latest += '0' | 201 latest += '0' |
| 133 orig_latest_str = latest | 202 orig_latest_str = latest |
| 134 else: | 203 else: |
| 135 orig_latest_str = latest | 204 orig_latest_str = latest |
| 136 latest = latest.replace('_', '.') | 205 latest = latest.replace('_', '.') |
| 137 » latest = re.compile(r'[^\d.]+').sub('', latest) | 206 latest = re.compile(r'[^\d.]+').sub('', latest) |
| 138 nums = version_str.split('.') | 207 nums = version_str.split('.') |
| 139 latest_nums = latest.split('.') | 208 latest_nums = latest.split('.') |
| 140 for (num, latest_num) in zip(nums, latest_nums): | 209 for (num, latest_num) in zip(nums, latest_nums): |
| 141 if int(num) > int(latest_num): | 210 if int(num) > int(latest_num): |
| 142 latest = orig_version_str | 211 latest = orig_version_str |
| 143 break | 212 break |
| 144 else: | 213 else: |
| 145 latest = orig_latest_str | 214 latest = orig_latest_str |
| 146 if latest == '': | 215 if latest == '': |
| 147 raise Exception("Couldn't find the desired download on " + \ | 216 raise Exception("Couldn't find the desired download on " + \ |
| 148 ' %s.' % google_code_site) | 217 ' %s.' % google_code_site) |
| 149 return latest | 218 return latest |
| 150 | 219 |
| 151 def run(self): | 220 def source_path(self): |
| 152 """Download and install the Google Code.""" | 221 return 'http://%s.googlecode.com/files/' % self.project_name |
| 153 print 'Installing from %s' % self.project_name | |
| 154 os_str = self.get_os_str | |
| 155 version = self.find_latest_version() | |
| 156 download_name = self.download_name_func({'os': os_str, 'version': version}) | |
| 157 urllib.urlretrieve(self.google_code_download() + '/' + download_name, | |
| 158 os.path.join(self.download_location, download_name)) | |
| 159 if download_name.endswith('.zip'): | |
| 160 if platform.system() != 'Windows': | |
| 161 # 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 | |
| 163 # built in zip utility. :-/ | |
| 164 run_cmd('unzip -u %s -d %s' % (os.path.join(self.download_location, | |
| 165 download_name), self.download_location), stdin='y') | |
| 166 else: | |
| 167 z = zipfile.ZipFile(os.path.join(self.download_location, download_name)) | |
| 168 z.extractall(self.download_location) | |
| 169 z.close() | |
| 170 os.remove(os.path.join(self.download_location, download_name)) | |
| 171 chrome_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | |
| 172 'orig-chromedriver') | |
| 173 if self.project_name == 'chromedriver' and os.path.exists(chrome_path): | |
| 174 # We have one additional location to make sure chromedriver is updated. | |
| 175 # TODO(efortuna): Remove this. See move_chrome_driver_if_needed in | |
| 176 # perf_testing/run_perf_tests.py | |
| 177 driver = 'chromedriver' | |
| 178 if platform.system() == 'Windows': | |
| 179 driver += '.exe' | |
| 180 shutil.copy(os.path.join(self.download_location, driver), | |
| 181 os.path.join(chrome_path, driver)) | |
| 182 | |
| 183 @property | |
| 184 def get_os_str(self): | |
| 185 """The strings to indicate what OS a download is for as used on Google Code. | |
| 186 """ | |
| 187 os_str = 'win' | |
| 188 if 'darwin' in sys.platform: | |
| 189 os_str = 'mac' | |
| 190 elif 'linux' in sys.platform: | |
| 191 os_str = 'linux32' | |
| 192 if '64bit' in platform.architecture()[0]: | |
| 193 os_str = 'linux64' | |
| 194 if self.project_name == 'chromedriver' and ( | |
| 195 os_str == 'mac' or os_str == 'win'): | |
| 196 os_str = os_str + '32' | |
| 197 return os_str | |
| 198 | 222 |
| 199 | 223 |
| 200 class FirefoxInstaller(object): | 224 class FirefoxInstaller(object): |
| 201 """Installs the latest version of Firefox on the machine.""" | 225 """Installs the latest version of Firefox on the machine.""" |
| 202 | 226 |
| 203 def ff_download_site(self, os_name): | 227 def ff_download_site(self, os_name): |
| 204 return 'http://releases.mozilla.org/pub/mozilla.org/firefox/releases/' + \ | 228 return 'http://releases.mozilla.org/pub/mozilla.org/firefox/releases/' + \ |
| 205 'latest/%s/en-US/' % os_name | 229 'latest/%s/en-US/' % os_name |
| 206 | 230 |
| 207 @property | 231 @property |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 os_str = 'mac' | 410 os_str = 'mac' |
| 387 elif 'linux' in sys.platform: | 411 elif 'linux' in sys.platform: |
| 388 os_str = 'linux' | 412 os_str = 'linux' |
| 389 return os_str | 413 return os_str |
| 390 | 414 |
| 391 def main(): | 415 def main(): |
| 392 args = parse_args() | 416 args = parse_args() |
| 393 if not args.python: | 417 if not args.python: |
| 394 SeleniumBindingsInstaller(args.buildbot).run() | 418 SeleniumBindingsInstaller(args.buildbot).run() |
| 395 if not args.chromedriver: | 419 if not args.chromedriver: |
| 396 GoogleCodeInstaller('chromedriver', | 420 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: | 421 if not args.seleniumrc: |
| 400 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), | 422 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), |
|
Emily Fortuna
2013/10/24 19:48:46
ummm do you even run this code? GoogleCodeInstalle
Andrei Mouravski
2013/10/24 19:51:41
It does exist. Line 169.
| |
| 401 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() | 423 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() |
| 402 if not args.iedriver and platform.system() == 'Windows': | 424 if not args.iedriver and platform.system() == 'Windows': |
| 403 GoogleCodeInstaller('selenium', find_depot_tools_location(args.buildbot), | 425 GoogleCodeInstaller('selenium', find_depot_tools_location(args.buildbot), |
| 404 lambda x: 'IEDriverServer_Win32_%(version)s.zip' % x).run() | 426 lambda x: 'IEDriverServer_Win32_%(version)s.zip' % x).run() |
| 405 if not args.firefox: | 427 if not args.firefox: |
| 406 FirefoxInstaller().run() | 428 FirefoxInstaller().run() |
| 407 if not args.opera: | 429 if not args.opera: |
| 408 OperaInstaller().run() | 430 OperaInstaller().run() |
| 409 | 431 |
| 410 if __name__ == '__main__': | 432 if __name__ == '__main__': |
| 411 main() | 433 main() |
| OLD | NEW |