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

Unified Diff: chrome/test/mini_installer/visitor_runner.py

Issue 2747023002: Cleanup machine based on the state in configuration file for mini installer test.
Patch Set: fix gni file 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/mini_installer/visitor.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/mini_installer/visitor_runner.py
diff --git a/chrome/test/mini_installer/visitor_runner.py b/chrome/test/mini_installer/visitor_runner.py
new file mode 100644
index 0000000000000000000000000000000000000000..6720cb051a02ee5aba088112049b8517826fd646
--- /dev/null
+++ b/chrome/test/mini_installer/visitor_runner.py
@@ -0,0 +1,113 @@
+# 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 re
+
+import file_visitor
+import process_visitor
+import registry_visitor
+
+class VisitorRunner(object):
+ """Run all visitor based on a state's property dictionary.
+
+ A property dictionary is a dictionary where each key is a verifier's name
+ and the associated value is the input to that verifier. For details about
+ the input format for each verifier, take a look at http://goo.gl/1P85WL
+
+ All visitor's name should match the name of property. For example, visitor
+ for property "RegistryEntries" will be "registry_entries_visitor".
+ """
+ def __init__(self):
+ self._property_name_match = {}
+
+ def Run(self, state):
+ """ Walk through all properties of the state.
+
+ Args:
+ state: A property dictionary belongs to a state.
+ """
+ for property_name, property_value in state.iteritems():
+ visitor_name = self._Convert(property_name) + '_visitor'
grt (UTC plus 2) 2017/03/15 09:00:08 i don't understand this part -- why is there a per
+ if not hasattr(self, visitor_name):
+ self._HandleInvalidProperty(property_name)
+ else:
+ getattr(self, visitor_name).Traverse(property_value)
+
+
+
+ def _HandleInvalidProperty(self, property_name):
+ """ Abstract class.
+
+ Handle the situation that the property in config file does not supported
+ by the runner.
+
+ Args:
+ property_name: A string represents the unsupported property's name.
+ """
+ pass
+
+ def _Convert(self, input_str):
+ """Convert CamelCase property name in config file into snake_case for
+ reflection
+ """
+ if input_str not in self._property_name_match:
+ output_str = re.sub('([A-Z][a-z]*)', r'_\1', input_str).lower()[1:]
+ self._property_name_match[input_str] = output_str
+ return self._property_name_match[input_str]
+
+
+class VerifierRunner(VisitorRunner):
+ """Run all verifing visitor to verify that the current machine states match
+ the property dictionary.
+ """
+
+ def __init__(self, variable_expander):
+ """Constructor."""
+ # TODO(sukolsak): Implement other verifiers
+ super(VerifierRunner, self).__init__()
+ self.files_visitor = file_visitor.FileVerifier(variable_expander)
+ self.registry_entries_visitor = registry_visitor.RegistryVerifier(
+ variable_expander)
+ self.processes_visitor = process_visitor.ProcessVerifier(variable_expander)
+
+ def _HandleInvalidProperty(self, property_name):
+ """ Overridden VisitorRunner._HandleInvalidProperty, unsupported
+ property raises KeyError.
+ """
+ raise KeyError('Unknown verifier %s' % property_name)
+
+
+class CleanupRunner(VisitorRunner):
+ """ Run all cleaning visitor based on the config state to reset the machine to
+ a clean state.
+
+ Only support:
+ 1) Delete directory, always recursively. Delete file is NOT supported.
+ 2) Delete registry key, always recursively.
+ """
+
+ _instance = None
+
+ def __init__(self, variable_expander):
+ """Constructor."""
+ # TODO(sukolsak): Implement other verifiers
+ super(CleanupRunner, self).__init__()
+ self.files_visitor = file_visitor.FileCleaner(variable_expander)
+ self.registry_entries_visitor = registry_visitor.RegistryCleaner(
+ variable_expander)
+
+
+ @classmethod
+ def Create(cls, variable_expander):
+ """Singleton constructor.
+ """
+ if not cls._instance:
+ cls._instance = CleanupRunner(variable_expander)
+ return cls._instance
+
+ def _HandleInvalidProperty(self, property_name):
+ """ Overridden VisitorRunner._HandleInvalidProperty, ignore unsupported
+ state's property.
+ """
+ return
« no previous file with comments | « chrome/test/mini_installer/visitor.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698