Exemplo n.º 1
0
def ReadStatusFile(content, variables):
    # Empty defaults for rules and wildcards. Variant-independent
    # rules are mapped by "", others by the variant name.
    rules = {variant: {} for variant in ALL_VARIANTS}
    rules[""] = {}
    wildcards = {variant: {} for variant in ALL_VARIANTS}
    wildcards[""] = {}

    variables.update(VARIABLES)
    for section in ReadContent(content):
        assert type(section) == list
        assert len(section) == 2
        exp = _EvalExpression(section[0], variables)
        if exp is False:
            # The expression is variant-independent and evaluates to False.
            continue
        elif exp == VARIANT_EXPRESSION:
            # If the expression contains one or more "variant" keywords, we evaluate
            # it for all possible variants and create rules for those that apply.
            for variant in ALL_VARIANTS:
                _EvalVariantExpression(section, rules, wildcards, variant,
                                       variables)
        else:
            # The expression is variant-independent and evaluates to True.
            assert exp is True, "Make sure expressions evaluate to boolean values"
            _ReadSection(
                section[1],
                rules[""],
                wildcards[""],
                variables,
            )
    return Freeze(rules), Freeze(wildcards)
Exemplo n.º 2
0
def ReadStatusFile(content, variables):
  """Status file format
  Status file := [section]
  section = [CONDITION, section_rules]
  section_rules := {path: outcomes}
  outcomes := outcome | [outcome, ...]
  outcome := SINGLE_OUTCOME | [CONDITION, SINGLE_OUTCOME, SINGLE_OUTCOME, ...]
  """

  # Empty defaults for rules and prefix_rules. Variant-independent
  # rules are mapped by "", others by the variant name.
  rules = {variant: {} for variant in ALL_VARIANTS}
  rules[""] = {}
  prefix_rules = {variant: {} for variant in ALL_VARIANTS}
  prefix_rules[""] = {}

  variables.update(VARIABLES)
  for conditional_section in ReadContent(content):
    assert type(conditional_section) == list
    assert len(conditional_section) == 2
    condition, section = conditional_section
    exp = _EvalExpression(condition, variables)

    # The expression is variant-independent and evaluates to False.
    if exp is False:
      continue

    # The expression is variant-independent and evaluates to True.
    if exp is True:
      _ReadSection(
          section,
          variables,
          rules[''],
          prefix_rules[''],
      )
      continue

    # The expression is variant-dependent (contains "variant" keyword)
    if exp == VARIANT_EXPRESSION:
      # If the expression contains one or more "variant" keywords, we evaluate
      # it for all possible variants and create rules for those that apply.
      for variant in ALL_VARIANTS:
        _EvalVariantExpression(
            condition, section, variables, variant, rules, prefix_rules)
      continue

    assert False, "Make sure expressions evaluate to boolean values"

  return Freeze(rules), Freeze(prefix_rules)
    def test_freeze(self):
        self.assertEqual(2, Freeze({1: [2]})[1][0])
        self.assertEqual(set([3]), Freeze({1: [2], 2: set([3])})[2])

        with self.assertRaises(Exception):
            Freeze({1: [], 2: set([3])})[2] = 4
        with self.assertRaises(Exception):
            Freeze({1: [], 2: set([3])}).update({3: 4})
        with self.assertRaises(Exception):
            Freeze({1: [], 2: set([3])})[1].append(2)
        with self.assertRaises(Exception):
            Freeze({1: [], 2: set([3])})[2] |= set([3])

        # Sanity check that we can do the same calls on a non-frozen object.
        {1: [], 2: set([3])}[2] = 4
        {1: [], 2: set([3])}.update({3: 4})
        {1: [], 2: set([3])}[1].append(2)
        {1: [], 2: set([3])}[2] |= set([3])