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

Side by Side 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 unified diff | Download patch
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 re
6
7 from file import File
8 from registry import Registry
9 from process import Process
10
11 class StateWalker(object):
12 _TYPE_TO_ENTRY = {
13 'Files': File,
14 'Processes': Process,
15 'RegistryEntries': Registry,
16 }
17
18 def __init__(self, visitor):
19 self._visitor = visitor
20
21 def Walk(self, variable_expander, property_dict):
22 """Traverses |property_dict|, fetch data from OS and invoke |_visitor| in
23 the end."""
24 for property_name, property_value in property_dict.iteritems():
25 if property_name not in StateWalker._TYPE_TO_ENTRY:
26 raise KeyError('Unknown verifier %s' % property_name)
27 for entry_name, entry_value, in property_value.iteritems():
28 # Skip over expectations with conditions that aren't satisfied.
29 if 'condition' in property_value and not self._EvaluateCondition(
30 variable_expander.Expand(entry_value['condition'])):
31 continue
32 entry = StateWalker._TYPE_TO_ENTRY[property_name](variable_expander,
33 self._visitor)
34 entry.Check(entry_name, entry_value)
35
36 def _EvaluateCondition(self, condition):
37 """Evaluates |condition| using eval().
38
39 Args:
40 condition: A condition string.
41
42 Returns:
43 The result of the evaluated condition.
44 """
45 return eval(condition, {'__builtins__': {'False': False, 'True': True}})
OLDNEW
« 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