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

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

Issue 2747023002: Cleanup machine based on the state in configuration file for mini installer test.
Patch Set: refactor to use visitor pattern Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/test/mini_installer/entry.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import _winreg
6 import os
7 import shutil
8
9 class CleanerVisitor(object):
10
11 def VisitFile(self, entry):
12 """ Delete the file if file is existed but shouldn't exist. Only support
13 Directory.
14 """
15 if entry.is_file_existed and not entry.should_file_exist and os.path.isdir(
16 entry.file_path):
17 shutil.rmtree(entry.file_path, ignore_errors=True)
18
19 def VisitRegistryKey(self, entry):
20 """ Reset the registry key to match the expectation.
21 """
22 if entry.key_handle is not None and entry.should_key_exist == 'forbidden':
23 try:
24 self._DeleteRegKey(entry.root_key_value, entry.sub_key)
25 except WindowsError:
26 # Suppress any delete error
27 pass
28
29
30 def VisitRegistryValue(self, entry):
31 pass
32
33 def VisitProcess(self, entry):
34 pass
35
36 def _DeleteRegKey(self, root, key_path):
37 """ Delete a registry key recursively.
38
39 Args:
40 root: An integer represents HKEY_ constant.
41 key_path: A string represents the path of key that needs to be
42 deleted.
43 """
44 with _winreg.OpenKey(root, key_path, 0, _winreg.KEY_SET_VALUE |
45 _winreg.KEY_READ |
46 _winreg.KEY_WOW64_32KEY) as key:
47 num_of_sub_keys, _, _ = _winreg.QueryInfoKey(key)
48 for i in range(0, num_of_sub_keys):
49 self._DeleteRegKey(root, key_path + "\\" + _winreg.EnumKey(key, i))
50 _winreg.DeleteKey(root, key_path)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/mini_installer/entry.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698