]> mj.ucw.cz Git - eval.git/commitdiff
Added shorthand access moe.ConfTree[key] to conf
authorTomas Gavenciak <gavento@ucw.cz>
Tue, 7 Sep 2010 11:30:22 +0000 (13:30 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Tue, 7 Sep 2010 11:30:22 +0000 (13:30 +0200)
t/moe/conf.py

index c745961896837d58ec216f9e0c760a5c80a2f93e..00e0b5a246b2b101ecc792e9ac3ff5524bc9790b 100644 (file)
@@ -24,8 +24,10 @@ TODO (OPT): Implemet "subtree" listing.
 
 import types, itertools, re, bisect
 import logging as log
+
 from moe import MoeError
 
+
 "Allowed depth of recursion - includes ALL recursive calls, so should quite high."
 c_maxdepth = 256
 
@@ -35,6 +37,7 @@ debug_maxdepth = 0
 "Variable name regexp, dots (separators) must be separated from edges and each other."
 re_VARNAME = re.compile(r'\A([A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+\Z')
 
+
 def check_depth(depth):
   "Helper to check for recursion depth."
   global debug_maxdepth
@@ -83,6 +86,12 @@ class ConfigTree(object):
       self.variables[key] = ConfigVar(key)
     return self.variables[key]
 
+  def __getitem__(self, key)
+    """
+    Return the value of an existing variable.
+    """
+    return self.lookup(key, create=False).value()
+
   def dump(self, prefix=''):
     """
     Pretty printing of the tree.