1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/usr/bin/python
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# WINDOWS ONLY
"""Installs a specified browser."""
import ConfigParser
import copy
import os
import logging
import time
import util
BROWSERS = [{'name': 'ie6',
'version': '6',
'family': 'ie',
'selenium_name': '*iexplore',
},
{'name': 'ie7',
'version': '7',
'family': 'ie',
'selenium_name': '*iexplore',
},
{'name': 'ie8',
'version': '8',
'family': 'ie',
'selenium_name': '*iexplore',
},
{'name': 'ff3',
'version': '3',
'family': 'firefox',
'selenium_name': '*firefox'
},
{'name': 'ff3.5',
'version': '3.5',
'family': 'firefox',
'selenium_name': '*firefox'
},
{'name': 'ff2',
'version': '2',
'family': 'firefox',
'selenium_name': '*firefox'
},
{'name': 'chrome-dev',
'version': '4',
'family': 'chrome',
'selenium_name': '*googlechrome'
},
{'name': 'chrome-beta',
'version': '3',
'family': 'chrome',
'selenium_name': '*googlechrome'
},
{'name': 'chrome-stable',
'version': '3',
'family': 'chrome',
'selenium_name': '*googlechrome'
},
{'name': 'saf3',
'family': 'safari',
'selenium_name': '*safari'
},
{'name': 'saf4',
'family': 'safari',
'selenium_name': '*safari'
}]
if util.IsXP():
HOME_PATH = 'C:\\Documents and Settings\\testing'
elif util.IsVista() or util.IsWin7():
HOME_PATH = 'C:\\Users\\testing'
SERVER = 'http://tsqaserver/mac/o3d/imaging/software/browsers'
SOFTWARE_PATH = 'C:\\imaging\\software'
_FIREFOX_VERSIONS = {'ff3': SERVER + '/ff3.0.13.exe',
'ff2': SERVER + '/ff2.0.11.exe',
'ff3.5': SERVER + '/ff3.5.2.exe'}
_CHROME_VERSIONS = {'chrome-stable': SERVER + '/chrome_stable.exe',
'chrome-dev': SERVER + '/chrome_dev.exe',
'chrome-beta': SERVER + '/chrome_beta.exe'}
_IE_7_URLS = {'xp': SERVER + '/IE7-WindowsXP-x86-enu.exe',
'xp_64': SERVER + '/IE7-WindowsServer2003-x64-enu.exe'}
_IE_8_URLS = {'xp': SERVER + '/IE8-WindowsXP-x86-ENU.exe',
'xp_64': SERVER + '/IE8-WindowsServer2003-x64-ENU.exe',
'vista': SERVER + '/IE8-WindowsVista-x86-ENU.exe',
'vista_64': SERVER + '/IE8-WindowsVista-x64-ENU.exe'}
def GetVersionNumber(family):
"""Get the version number of the installed browser in |family|. Returns
None if browser is not installed."""
if family == 'ie':
path = r'HKLM\SOFTWARE\Microsoft\Internet Explorer'
version = util.RegQuery(path, 'Version')
if version is not None:
return version[0:1]
elif family == 'firefox':
path = r'HKLM\SOFTWARE\Mozilla\Mozilla Firefox'
version = util.RegQuery(path, 'CurrentVersion')
if version is not None:
if version.startswith('3.0'):
return '3'
elif version.startswith('3.5'):
return '3.5'
elif version.startswith('2'):
return '2'
elif family == 'chrome':
chrome_dir = (HOME_PATH + r'\Local Settings\Application Data\Google' +
r'\Chrome\Application')
files = os.listdir(chrome_dir)
for file in files:
# The Chrome application directory has a folder named with the version #.
if file.startswith('2.'):
return '2'
elif file.startswith('3.'):
return '3'
elif file.startswith('4.'):
return '4'
return None
def IsBrowserInstalled(browser):
"""Checks if |browser| is installed."""
return GetVersionNumber(browser['family']).startswith(browser['version'])
def Install(browser):
"""Installs |browser|, if necessary. It is not possible to install
an older version of the already installed browser currently.
Args:
browser: specific browst to install.
Returns:
whether browser is installed.
"""
# Only dynamic installation of browsers for Windows now.
if not util.IsWindows():
return True
logging.info('Wants to install ' + browser['name'])
version = GetVersionNumber(browser['family'])
if version is None:
logging.info('No version of %s is installed' % browser['family'])
else:
logging.info('Version %s of %s is installed already'
% (version, browser['family']))
if not IsBrowserInstalled(browser):
install_cmd = None
# Download browser.
logging.info('Downloading ' + browser['name'])
if browser['family'] == 'ie':
if browser['name'] == 'ie7':
install_cmd = util.Download(_IE_7_URLS[util.GetOSPrefix()],
SOFTWARE_PATH)
elif browser['name'] == 'ie8':
install_cmd = util.Download(_IE_8_URLS[util.GetOSPrefix()],
SOFTWARE_PATH)
install_cmd += ' /passive /no-default'
elif browser['family'] == 'firefox':
if util.IsWindows():
install = util.Download(_FIREFOX_VERSIONS[browser['name']],
SOFTWARE_PATH)
install_cmd = install + ' -ms'
elif browser['family'] == 'chrome':
if util.IsWindows():
install_cmd = util.Download(_CHROME_VERSIONS[browser['name']],
SOFTWARE_PATH)
else:
logging.error('Browser %s is not currently supported' % browser['name'])
# Run installation.
if install_cmd is not None:
logging.info('Installing browser: ' + install_cmd)
if install_cmd is None or util.RunStr(install_cmd) != 0:
logging.error('Could not install %s' % browser['name'])
return False
# Do post installation things.
if browser['family'] == 'chrome':
first_run = file(HOME_PATH + '\\Local Settings\\'
'Application Data\\Google\\Chrome\\Application\\'
'First Run', 'w')
first_run.close()
# Wait for Chrome to install. Reboot to get rid of that first run UI.
time.sleep(90)
util.Reboot()
logging.error('Could not reboot. Needed for Chrome installation.')
return False
else:
logging.info(browser['name'] + ' already installed')
return True
|