Home | History | Annotate | Download | only in mini_installer
      1 # Copyright 2013 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 
      6 class Verifier:
      7   """Verifies that the current machine states match the expectation."""
      8 
      9   def VerifyInput(self, verifier_input, variable_expander):
     10     """Verifies that the current machine states match |verifier_input|.
     11 
     12     Args:
     13       verifier_input: An input to the verifier. It is a dictionary where each
     14           key is an expectation name and the associated value is an expectation
     15           dictionary. The expectation dictionary may contain an optional
     16           'condition' property, a string that determines whether the expectation
     17           should be verified. Each subclass can specify a different expectation
     18           name and expectation dictionary.
     19       variable_expander: A VariableExpander object.
     20     """
     21     for expectation_name, expectation in verifier_input.iteritems():
     22       if 'condition' in expectation:
     23         condition = variable_expander.Expand(expectation['condition'])
     24         if not self._EvaluateCondition(condition):
     25           continue
     26       self._VerifyExpectation(expectation_name, expectation, variable_expander)
     27 
     28   def _VerifyExpectation(self, expectation_name, expectation,
     29                          variable_expander):
     30     """Verifies that the current machine states match |verifier_input|.
     31 
     32     This is an abstract method for subclasses to override.
     33 
     34     Args:
     35       expectation_name: An expectation name. Each subclass can specify a
     36           different expectation name format.
     37       expectation: An expectation dictionary. Each subclass can specify a
     38           different expectation dictionary format.
     39       variable_expander: A VariableExpander object.
     40     """
     41     raise NotImplementedError()
     42 
     43   def _EvaluateCondition(self, condition):
     44     """Evaluates |condition| using eval().
     45 
     46     Args:
     47       condition: A condition string.
     48 
     49     Returns:
     50       The result of the evaluated condition.
     51     """
     52     return eval(condition, {'__builtins__': None}, None)
     53