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

Unified Diff: chrome/test/mini_installer/state_walker.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/mini_installer/registry_verifier.py ('k') | chrome/test/mini_installer/test_installer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/mini_installer/state_walker.py
diff --git a/chrome/test/mini_installer/state_walker.py b/chrome/test/mini_installer/state_walker.py
new file mode 100644
index 0000000000000000000000000000000000000000..410857e928169fd26fd60ed1530e5ab378094d69
--- /dev/null
+++ b/chrome/test/mini_installer/state_walker.py
@@ -0,0 +1,45 @@
+# 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
+
+from file import File
+from registry import Registry
+from process import Process
+
+class StateWalker(object):
+ _TYPE_TO_ENTRY = {
+ 'Files': File,
+ 'Processes': Process,
+ 'RegistryEntries': Registry,
+ }
+
+ def __init__(self, visitor):
+ self._visitor = visitor
+
+ def Walk(self, variable_expander, property_dict):
+ """Traverses |property_dict|, fetch data from OS and invoke |_visitor| in
+ the end."""
+ for property_name, property_value in property_dict.iteritems():
+ if property_name not in StateWalker._TYPE_TO_ENTRY:
+ raise KeyError('Unknown verifier %s' % property_name)
+ for entry_name, entry_value, in property_value.iteritems():
+ # Skip over expectations with conditions that aren't satisfied.
+ if 'condition' in property_value and not self._EvaluateCondition(
+ variable_expander.Expand(entry_value['condition'])):
+ continue
+ entry = StateWalker._TYPE_TO_ENTRY[property_name](variable_expander,
+ self._visitor)
+ entry.Check(entry_name, entry_value)
+
+ def _EvaluateCondition(self, condition):
+ """Evaluates |condition| using eval().
+
+ Args:
+ condition: A condition string.
+
+ Returns:
+ The result of the evaluated condition.
+ """
+ return eval(condition, {'__builtins__': {'False': False, 'True': True}})
« no previous file with comments | « chrome/test/mini_installer/registry_verifier.py ('k') | chrome/test/mini_installer/test_installer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698