| 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}})
|
|
|