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

Side by Side Diff: chrome/test/mini_installer/uninstall_chrome.py

Issue 23523045: Clean the machine before running commands in the mini_installer test framework. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address gab and grt's comments. Created 7 years, 3 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Uninstalls Chrome. 5 """Uninstalls Chrome.
6 6
7 This script reads the uninstall command from registry, calls it, and verifies 7 This script reads the uninstall command from registry, calls it, and verifies
8 the output status code. 8 the output status code.
9 """ 9 """
10 10
11 import _winreg 11 import _winreg
12 import optparse 12 import optparse
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 15
16 16
17 def main(): 17 def main():
18 parser = optparse.OptionParser(description='Uninstall Chrome.') 18 parser = optparse.OptionParser(description='Uninstall Chrome.')
19 parser.add_option('--system-level', action='store_true', dest='system_level', 19 parser.add_option('--system-level', action='store_true', dest='system_level',
20 default=False, help='Uninstall Chrome at system level.') 20 default=False, help='Uninstall Chrome at system level.')
21 parser.add_option('--chrome-long-name', default='Google Chrome', 21 parser.add_option('--chrome-long-name', default='Google Chrome',
22 help='Google Chrome or Chromium)') 22 help='Google Chrome or Chromium)')
23 parser.add_option('--silent', action='store_true', dest='silent',
gab 2013/09/13 15:06:19 How about: --no-error-if-absent or something more
sukolsak 2013/09/13 15:59:33 Will do.
gab 2013/09/13 20:12:55 I meant in this CL...
sukolsak 2013/09/13 23:11:14 Done. Yes, I was waiting for your reply.
gab 2013/09/16 13:59:58 Ah ok, my bad :)!
24 default=False, help='Silently return if the registry key '
25 'for uninstalling Chrome is not found')
23 options, _ = parser.parse_args() 26 options, _ = parser.parse_args()
24 27
25 # TODO(sukolsak): Add support for uninstalling MSI-based Chrome installs when 28 # TODO(sukolsak): Add support for uninstalling MSI-based Chrome installs when
26 # we support testing MSIs. 29 # we support testing MSIs.
27 if options.system_level: 30 if options.system_level:
28 root_key = _winreg.HKEY_LOCAL_MACHINE 31 root_key = _winreg.HKEY_LOCAL_MACHINE
29 else: 32 else:
30 root_key = _winreg.HKEY_CURRENT_USER 33 root_key = _winreg.HKEY_CURRENT_USER
31 sub_key = ('SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s' % 34 sub_key = ('SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s' %
32 options.chrome_long_name) 35 options.chrome_long_name)
33 # Query the key. It will throw a WindowsError if the key doesn't exist. 36 # Query the key. It will throw a WindowsError if the key doesn't exist.
34 try: 37 try:
35 key = _winreg.OpenKey(root_key, sub_key, 0, _winreg.KEY_QUERY_VALUE) 38 key = _winreg.OpenKey(root_key, sub_key, 0, _winreg.KEY_QUERY_VALUE)
36 except WindowsError: 39 except WindowsError:
40 if options.silent:
41 return 1
gab 2013/09/13 15:06:19 I'd say we should return 0 here.
sukolsak 2013/09/13 15:59:33 Will do.
gab 2013/09/13 20:12:55 I meant in this CL...
sukolsak 2013/09/13 23:11:14 Done.
37 raise KeyError('Registry key %s\\%s is missing' % ( 42 raise KeyError('Registry key %s\\%s is missing' % (
38 'HKEY_LOCAL_MACHINE' if options.system_level else 'HKEY_CURRENT_USER', 43 'HKEY_LOCAL_MACHINE' if options.system_level else 'HKEY_CURRENT_USER',
39 sub_key)) 44 sub_key))
40 uninstall_string, _ = _winreg.QueryValueEx(key, 'UninstallString') 45 uninstall_string, _ = _winreg.QueryValueEx(key, 'UninstallString')
41 exit_status = subprocess.call(uninstall_string + ' --force-uninstall', 46 exit_status = subprocess.call(uninstall_string + ' --force-uninstall',
42 shell=True) 47 shell=True)
43 # The exit status for successful uninstallation of Chrome is 19 (see 48 # The exit status for successful uninstallation of Chrome is 19 (see
44 # chrome/installer/util/util_constants.h). 49 # chrome/installer/util/util_constants.h).
45 if exit_status != 19: 50 if exit_status != 19:
46 raise Exception('Could not uninstall Chrome. The installer exited with ' 51 raise Exception('Could not uninstall Chrome. The installer exited with '
47 'status %d.' % exit_status) 52 'status %d.' % exit_status)
48 return 0 53 return 0
49 54
50 55
51 if __name__ == '__main__': 56 if __name__ == '__main__':
52 sys.exit(main()) 57 sys.exit(main())
OLDNEW
« chrome/test/mini_installer/test_installer.py ('K') | « chrome/test/mini_installer/test_installer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698