| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2011, 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 optparse | 15 import optparse |
| 16 import os | 16 import os |
| 17 import platform | 17 import platform |
| 18 import re | 18 import re |
| 19 import subprocess | 19 import subprocess |
| 20 import sys | 20 import sys |
| 21 import urllib | 21 import urllib |
| 22 import urllib2 | 22 import urllib2 |
| 23 import zipfile |
| 23 | 24 |
| 24 def run_cmd(cmd, stdin=None): | 25 def run_cmd(cmd, stdin=None): |
| 25 """Run the command on the command line in the shell. We print the output of | 26 """Run the command on the command line in the shell. We print the output of |
| 26 the command. | 27 the command. |
| 27 """ | 28 """ |
| 28 print cmd | 29 print cmd |
| 29 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 30 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 30 stdin=subprocess.PIPE, shell=True) | 31 stdin=subprocess.PIPE, shell=True) |
| 31 output, not_used = p.communicate(input=stdin) | 32 output, stderr = p.communicate(input=stdin) |
| 32 if output: | 33 if output: |
| 33 print output | 34 print output |
| 35 if stderr: |
| 36 print stderr |
| 34 | 37 |
| 35 def parse_args(): | 38 def parse_args(): |
| 36 parser = optparse.OptionParser() | 39 parser = optparse.OptionParser() |
| 37 parser.add_option('--firefox', '-f', dest='firefox', help='Install Firefox', | 40 parser.add_option('--firefox', '-f', dest='firefox', help='Install Firefox', |
| 38 action='store_true', default=False) | 41 action='store_true', default=False) |
| 39 parser.add_option('--path', '-p', dest='path', help='Specify location ' + \ | 42 parser.add_option('--path', '-p', dest='path', help='Specify location ' + \ |
| 40 'on your PATH for where we should install chromedriver (default is in' + \ | 43 'on your PATH for where we should install chromedriver (default is in' + \ |
| 41 'depot_tools).', metavar='CHROMEDRIVER_LOC', type='str', action='store', | 44 'depot_tools).', metavar='CHROMEDRIVER_LOC', type='str', action='store', |
| 42 default=None) | 45 default=None) |
| 43 parser.add_option('--buildbot', '-b', dest='buildbot', action='store_true', | 46 parser.add_option('--buildbot', '-b', dest='buildbot', action='store_true', |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 127 |
| 125 def run(self): | 128 def run(self): |
| 126 """Download and install the Google Code.""" | 129 """Download and install the Google Code.""" |
| 127 print 'Installing from %s' % self.project_name | 130 print 'Installing from %s' % self.project_name |
| 128 os_str = self.get_os_str | 131 os_str = self.get_os_str |
| 129 version = self.find_latest_version() | 132 version = self.find_latest_version() |
| 130 download_name = self.download_name_func({'os': os_str, 'version': version}) | 133 download_name = self.download_name_func({'os': os_str, 'version': version}) |
| 131 urllib.urlretrieve(self.google_code_download() + '/' + download_name, | 134 urllib.urlretrieve(self.google_code_download() + '/' + download_name, |
| 132 os.path.join(self.download_location, download_name)) | 135 os.path.join(self.download_location, download_name)) |
| 133 if download_name.endswith('.zip'): | 136 if download_name.endswith('.zip'): |
| 134 run_cmd('unzip -u %s -d %s' % (os.path.join(self.download_location, | 137 z = zipfile.ZipFile(os.path.join(self.download_location, download_name)) |
| 135 download_name), self.download_location)) | 138 z.extractall(self.download_location) |
| 139 z.close() |
| 136 os.remove(os.path.join(self.download_location, download_name)) | 140 os.remove(os.path.join(self.download_location, download_name)) |
| 137 | 141 |
| 138 @property | 142 @property |
| 139 def get_os_str(self): | 143 def get_os_str(self): |
| 140 """The strings to indicate what OS a download is for as used on Google Code. | 144 """The strings to indicate what OS a download is for as used on Google Code. |
| 141 """ | 145 """ |
| 142 os_str = 'win' | 146 os_str = 'win' |
| 143 if 'darwin' in sys.platform: | 147 if 'darwin' in sys.platform: |
| 144 os_str = 'mac' | 148 os_str = 'mac' |
| 145 elif 'linux' in sys.platform: | 149 elif 'linux' in sys.platform: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 lambda x: 'chromedriver_%(os)s_%(version)s.zip' % x).run() | 245 lambda x: 'chromedriver_%(os)s_%(version)s.zip' % x).run() |
| 242 if 'win32' not in sys.platform and 'cygwin' not in sys.platform: | 246 if 'win32' not in sys.platform and 'cygwin' not in sys.platform: |
| 243 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), | 247 GoogleCodeInstaller('selenium', os.path.dirname(os.path.abspath(__file__)), |
| 244 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() | 248 lambda x: 'selenium-server-standalone-%(version)s.jar' % x).run() |
| 245 | 249 |
| 246 if args.firefox: | 250 if args.firefox: |
| 247 FirefoxInstaller().run() | 251 FirefoxInstaller().run() |
| 248 | 252 |
| 249 if __name__ == '__main__': | 253 if __name__ == '__main__': |
| 250 main() | 254 main() |
| OLD | NEW |