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

Side by Side Diff: tools/testing/webdriver_test_setup.py

Issue 11232026: Add Opera to the "webdriver_test_setup" script. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | « no previous file | 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/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
11 # of steps. 11 # of steps.
12 12
13 # TODO(efortuna): Rewrite this script in Dart when the Process module has a 13 # TODO(efortuna): Rewrite this script in Dart when the Process module has a
14 # better high level API. 14 # better high level API.
15 import HTMLParser
15 import optparse 16 import optparse
16 import os 17 import os
17 import platform 18 import platform
18 import re 19 import re
19 import shutil 20 import shutil
21 import string
20 import subprocess 22 import subprocess
21 import sys 23 import sys
22 import urllib 24 import urllib
23 import urllib2 25 import urllib2
24 import zipfile 26 import zipfile
25 27
26 def run_cmd(cmd, stdin=None): 28 def run_cmd(cmd, stdin=None):
27 """Run the command on the command line in the shell. We print the output of 29 """Run the command on the command line in the shell. We print the output of
28 the command. 30 the command.
29 """ 31 """
30 print cmd 32 print cmd
31 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, 33 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
32 stdin=subprocess.PIPE, shell=True) 34 stdin=subprocess.PIPE, shell=True)
33 output, stderr = p.communicate(input=stdin) 35 output, stderr = p.communicate(input=stdin)
34 if output: 36 if output:
35 print output 37 print output
36 if stderr: 38 if stderr:
37 print stderr 39 print stderr
38 40
39 def parse_args(): 41 def parse_args():
40 parser = optparse.OptionParser() 42 parser = optparse.OptionParser()
41 parser.add_option('--firefox', '-f', dest='firefox', 43 parser.add_option('--firefox', '-f', dest='firefox',
42 help="Don't install Firefox", action='store_true', default=False) 44 help="Don't install Firefox", action='store_true', default=False)
45 parser.add_option('--opera', '-o', dest='opera', default=False,
46 help="Don't install Opera", action='store_true')
43 parser.add_option('--chromedriver', '-c', dest='chromedriver', 47 parser.add_option('--chromedriver', '-c', dest='chromedriver',
44 help="Don't install chromedriver.", action='store_true', default=False) 48 help="Don't install chromedriver.", action='store_true', default=False)
45 parser.add_option('--iedriver', '-i', dest='iedriver', 49 parser.add_option('--iedriver', '-i', dest='iedriver',
46 help="Don't install iedriver (only used on Windows).", 50 help="Don't install iedriver (only used on Windows).",
47 action='store_true', default=False) 51 action='store_true', default=False)
48 parser.add_option('--seleniumrc', '-s', dest='seleniumrc', 52 parser.add_option('--seleniumrc', '-s', dest='seleniumrc',
49 help="Don't install the Selenium RC server (used for Safari and Opera " 53 help="Don't install the Selenium RC server (used for Safari and Opera "
50 "tests).", action='store_true', default=False) 54 "tests).", action='store_true', default=False)
51 parser.add_option('--python', '-p', dest='python', 55 parser.add_option('--python', '-p', dest='python',
52 help="Don't install Selenium python bindings.", action='store_true', 56 help="Don't install Selenium python bindings.", action='store_true',
53 default=False) 57 default=False)
54 parser.add_option('--buildbot', '-b', dest='buildbot', action='store_true', 58 parser.add_option('--buildbot', '-b', dest='buildbot', action='store_true',
55 help='Perform a buildbot selenium setup (buildbots have a different' + 59 help='Perform a buildbot selenium setup (buildbots have a different' +
56 'location for their python executable).', default=False) 60 'location for their python executable).', default=False)
57 args, ignored = parser.parse_args() 61 args, _ = parser.parse_args()
58 return args 62 return args
59 63
60 def find_depot_tools_location(is_buildbot): 64 def find_depot_tools_location(is_buildbot):
61 """Depot_tools is our default install location for chromedriver, so we find 65 """Depot_tools is our default install location for chromedriver, so we find
62 its location on the filesystem. 66 its location on the filesystem.
63 Arguments: 67 Arguments:
64 is_buildbot - True if we are running buildbot machine setup (we can't detect 68 is_buildbot - True if we are running buildbot machine setup (we can't detect
65 this automatically because this script is not run at build time). 69 this automatically because this script is not run at build time).
66 """ 70 """
67 if is_buildbot: 71 if is_buildbot:
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 for loc in path: 270 for loc in path:
267 if 'python' in loc or 'Python' in loc: 271 if 'python' in loc or 'Python' in loc:
268 pip_cmd = os.path.join(loc, 'Scripts', pip_cmd) 272 pip_cmd = os.path.join(loc, 'Scripts', pip_cmd)
269 break 273 break
270 page = urllib2.urlopen(self.SETUPTOOLS_SITE) 274 page = urllib2.urlopen(self.SETUPTOOLS_SITE)
271 run_cmd('%s %s' % (admin_keyword, python_cmd), page.read()) 275 run_cmd('%s %s' % (admin_keyword, python_cmd), page.read())
272 page = urllib2.urlopen(self.PIP_SITE) 276 page = urllib2.urlopen(self.PIP_SITE)
273 run_cmd('%s %s' % (admin_keyword, python_cmd), page.read()) 277 run_cmd('%s %s' % (admin_keyword, python_cmd), page.read())
274 run_cmd('%s %s install -U selenium' % (admin_keyword, pip_cmd)) 278 run_cmd('%s %s install -U selenium' % (admin_keyword, pip_cmd))
275 279
280 class OperaHtmlParser(HTMLParser.HTMLParser):
281 """A helper class to parse Opera pages listing available downloads to find the
282 correct download we want."""
283
284 def initialize(self, rejection_func, accept_func):
285 """Initialize some state for our parser.
286 Arguments:
287 rejection_func: A function that accepts the value of the URL and determines
288 if it is of the type we are looking for.
289 accept_func: A function that takes the URL and the "current best" URL and
290 determines if it is better than our current download url."""
291 self.latest = 0
292 self.rejection_func = rejection_func
293 self.accept_func = accept_func
294
295 def handle_starttag(self, tag, attrs):
296 """Find the latest version."""
297 if (tag == 'a' and attrs[0][0] == 'href' and
298 self.rejection_func(attrs[0][1])):
299 self.latest = self.better_func(attrs[0][1], self.latest)
300
301 class OperaInstaller(object):
302 """Install from the Opera FTP website."""
303
304 def find_latest_version(self, download_page, rejection_func, accept_func):
305 """Get the latest non-beta version.
306 Arguments:
307 download_page: The initial page that lists all the download options.
308 rejection_func: A function that accepts the value of the URL and determines
309 if it is of the type we are looking for.
310 accept_func: A function that takes the URL and the "current best" URL and
311 determines if it is better than our current download url."""
312 f = urllib2.urlopen(download_page)
313 parser = OperaHtmlParser()
314 parser.initialize(rejection_func, accept_func)
315 parser.feed(f.read())
316 return str(parser.latest)
317
318 def run(self):
319 """Download and install Opera."""
320 print 'Installing Opera'
321 os_str = self.get_os_str
322 download_name = 'http://ftp.opera.com/pub/opera/%s/' % os_str
323
324 def higher_revision(new_version_str, current):
325 version_string = new_version_str[:-1]
326 if int(version_string) > current:
327 return int(version_string)
328 return current
329
330 version = self.find_latest_version(
331 download_name,
332 lambda x: x[0] in string.digits and 'b' not in x and 'rc' not in x,
333 higher_revision)
334 download_name += version
335 if ('linux' in sys.platform and
336 platform.linux_distribution()[0] == 'Ubuntu'):
337 # Last time I tried, the .deb file you download directly from opera was
338 # not installing correctly on Ubuntu. This installs Opera more nicely.
339 os.system("sudo sh -c 'wget -O - http://deb.opera.com/archive.key | "
340 "apt-key add -'")
341 os.system("""sudo sh -c 'echo "deb http://deb.opera.com/opera/ """
342 """stable non-free" > /etc/apt/sources.list.d/opera.list'""")
343 run_cmd('sudo apt-get update')
344 run_cmd('sudo apt-get install opera', stdin='y')
345 else:
346 if 'darwin' in sys.platform:
347 dotted_version = '%s.%s' % (version[:2], version[2:])
348 download_name += '/Opera_%s_Setup_Intel.dmg' % dotted_version
349 urllib.urlretrieve(download_name, 'opera.dmg')
350 run_cmd('hdiutil mount opera.dmg', stdin='qY\n')
351 run_cmd('sudo cp -R /Volumes/Opera/Opera.app /Applications')
352 run_cmd('hdiutil unmount /Volumes/Opera/')
353 elif 'win' in sys.platform:
354 download_name += '/en/Opera_%s_en_Setup.exe' % version
355 urllib.urlretrieve(download_name, 'opera_install.exe')
356 run_cmd('opera_install.exe -ms')
357 else:
358 # For all other flavors of linux, download the tar.
359 download_name += '/'
360 extension = '.tar.bz2'
361 if '64bit' in platform.architecture()[0]:
362 platform_str = '.x86_64'
363 else:
364 platform_str = '.i386'
365 def get_acceptable_file(new_version_str, current):
366 return new_version_str
367 latest = self.find_latest_version(
368 download_name,
369 lambda x: x.startswith('opera') and x.endswith(extension)
370 and platform_str in x,
371 get_acceptable_file)
372 download_name += latest
373 run_cmd('wget -O - %s | tar -C ~ -jxv' % download_name)
374 print ('PLEASE MANUALLY RUN "~/%s/install" TO COMPLETE OPERA '
375 'INSTALLATION' %
376 download_name[download_name.rfind('/') + 1:-len(extension)])
377
378 @property
379 def get_os_str(self):
380 """The strings to indicate what OS a download is."""
381 os_str = 'win'
382 if 'darwin' in sys.platform:
383 os_str = 'mac'
384 elif 'linux' in sys.platform:
385 os_str = 'linux'
386 return os_str
387
276 def main(): 388 def main():
277 args = parse_args() 389 args = parse_args()
278 if not args.python: 390 if not args.python:
279 SeleniumBindingsInstaller(args.buildbot).run() 391 SeleniumBindingsInstaller(args.buildbot).run()
280 if not args.chromedriver: 392 if not args.chromedriver:
281 GoogleCodeInstaller('chromedriver', 393 GoogleCodeInstaller('chromedriver',
282 find_depot_tools_location(args.buildbot), 394 find_depot_tools_location(args.buildbot),
283 lambda x: 'chromedriver_%(os)s_%(version)s.zip' % x).run() 395 lambda x: 'chromedriver_%(os)s_%(version)s.zip' % x).run()
284 if not args.seleniumrc: 396 if not args.seleniumrc:
285 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), 397 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)),
286 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() 398 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run()
287 if not args.iedriver and platform.system() == 'Windows': 399 if not args.iedriver and platform.system() == 'Windows':
288 GoogleCodeInstaller('selenium', find_depot_tools_location(args.buildbot), 400 GoogleCodeInstaller('selenium', find_depot_tools_location(args.buildbot),
289 lambda x: 'IEDriverServer_Win32_%(version)s.zip' % x).run() 401 lambda x: 'IEDriverServer_Win32_%(version)s.zip' % x).run()
290
291 if not args.firefox: 402 if not args.firefox:
292 FirefoxInstaller().run() 403 FirefoxInstaller().run()
404 if not args.opera:
405 OperaInstaller().run()
293 406
294 if __name__ == '__main__': 407 if __name__ == '__main__':
295 main() 408 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698