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

Unified Diff: chrome/test/mini_installer/visitor.py

Issue 2747023002: Cleanup machine based on the state in configuration file for mini installer test.
Patch Set: fix gni file 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
Index: chrome/test/mini_installer/visitor.py
diff --git a/chrome/test/mini_installer/visitor.py b/chrome/test/mini_installer/visitor.py
new file mode 100644
index 0000000000000000000000000000000000000000..e5de04fa08885ac68a1128f7766cac7a83017d35
--- /dev/null
+++ b/chrome/test/mini_installer/visitor.py
@@ -0,0 +1,31 @@
+# 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.
+
+class Visitor(object):
+ """Traverse one property of a state's dict"""
+ CONDITION = 'condition'
+
+ def __init__(self, variable_expander):
+ self._variable_expander = variable_expander
+
+ def Traverse(self, property_value):
+ for entry_name, entry_value in property_value.iteritems():
+ if Visitor.CONDITION in entry_value and not self._EvaluateCondition(
+ self._variable_expander.Expand(entry_value[Visitor.CONDITION])):
+ continue
+ self._VisitEntry(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}})
+
+ def _VisitEntry(self, entry_name, entry_value):
+ raise NotImplementedError()

Powered by Google App Engine
This is Rietveld 408576698