]> mj.ucw.cz Git - moe.git/blobdiff - t/moe/config.py
Added ConfigTree.remove, adapted parse and parse_file
[moe.git] / t / moe / config.py
index b2f788ef81e1bfea9de21b02aba8268f287fdad3..04e363f1887ef53446392b202a34df97faa00630 100644 (file)
@@ -101,11 +101,21 @@ class ConfigTree(object):
     for key in keys:
       self.lookup(key, create=True).fix()
 
+  def remove(self, parsed):
+    """Given a list [(varname, `Operation`)] as returned by `parse` or `parse_file`, 
+    removes the operations from the respective variables config tree.
+    Variables/operations not present int the tree raise ValueError.
+    """
+    for vname, o in parsed:
+      v = self.lookup(vname, create = True)
+      v.remove_operation(o)
+
   def parse(self, s, source=None, level=0):
-    """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details."""
+    """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details.
+    Returns list of parset operations: [(varname, `Operation`)]"""
     import moe.config_parser
     p = moe.config_parser.ConfigParser(s, self, source=source, level=level)
-    p.parse()
+    return p.parse()
 
   def parse_file(self, filename, desc=None, level=0):
     """Parse an utf-8 file into the tree, see `moe.confparser.ConfigParser` for details. 
@@ -113,7 +123,7 @@ class ConfigTree(object):
     with open(filename, 'rt') as f:
       if desc: 
        filename += " <" + desc + ">" 
-      self.parse(f, source=filename, level=level)
+      return self.parse(f, source=filename, level=level)
 
 
 class ConfigElem(object):