| Index: chrome/test/mini_installer/cleaner_visitor.py
|
| diff --git a/chrome/test/mini_installer/cleaner_visitor.py b/chrome/test/mini_installer/cleaner_visitor.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b81909803ca61cf177d071297fc6320f893261fd
|
| --- /dev/null
|
| +++ b/chrome/test/mini_installer/cleaner_visitor.py
|
| @@ -0,0 +1,50 @@
|
| +# Copyright 2017 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.
|
| +
|
| +import _winreg
|
| +import os
|
| +import shutil
|
| +
|
| +class CleanerVisitor(object):
|
| +
|
| + def VisitFile(self, entry):
|
| + """ Delete the file if file is existed but shouldn't exist. Only support
|
| + Directory.
|
| + """
|
| + if entry.is_file_existed and not entry.should_file_exist and os.path.isdir(
|
| + entry.file_path):
|
| + shutil.rmtree(entry.file_path, ignore_errors=True)
|
| +
|
| + def VisitRegistryKey(self, entry):
|
| + """ Reset the registry key to match the expectation.
|
| + """
|
| + if entry.key_handle is not None and entry.should_key_exist == 'forbidden':
|
| + try:
|
| + self._DeleteRegKey(entry.root_key_value, entry.sub_key)
|
| + except WindowsError:
|
| + # Suppress any delete error
|
| + pass
|
| +
|
| +
|
| + def VisitRegistryValue(self, entry):
|
| + pass
|
| +
|
| + def VisitProcess(self, entry):
|
| + pass
|
| +
|
| + def _DeleteRegKey(self, root, key_path):
|
| + """ Delete a registry key recursively.
|
| +
|
| + Args:
|
| + root: An integer represents HKEY_ constant.
|
| + key_path: A string represents the path of key that needs to be
|
| + deleted.
|
| + """
|
| + with _winreg.OpenKey(root, key_path, 0, _winreg.KEY_SET_VALUE |
|
| + _winreg.KEY_READ |
|
| + _winreg.KEY_WOW64_32KEY) as key:
|
| + num_of_sub_keys, _, _ = _winreg.QueryInfoKey(key)
|
| + for i in range(0, num_of_sub_keys):
|
| + self._DeleteRegKey(root, key_path + "\\" + _winreg.EnumKey(key, i))
|
| + _winreg.DeleteKey(root, key_path)
|
|
|