"""
-config.py
----------
-
Lazy conditional string evaluation module for Moe configuration variables.
-
* Each variable has ordered list of operations (definitions), each defining operation either
assigns (SET) or appends (APPEND) value of an expression to the variable. Each operation may be guarded by condition(s).
self.variables[k].dump(prefix) for k in sorted(self.variables.keys())
])
+ def fix(self, key):
+ "Fix variable value. Fixing undefined variable raises `UndefinedError`."
+ self.lookup(key, create=True).fix()
+
def parse(self, s, source=None, level=0):
"""Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details."""
import moe.confparser
def parse_file(self, filename, desc=None, level=0):
"""Parse an utf-8 file into the tree, see `moe.confparser.ConfigParser` for details.
Names the source "`filename` <`desc`>". """
- f = open(filename, 'rt')
- if desc:
- filename += " <" + desc + ">"
- self.parse(f, source=filename, level=level)
+ with open(filename, 'rt') as f:
+ if desc:
+ filename += " <" + desc + ">"
+ self.parse(f, source=filename, level=level)
class ConfigElem(object):
self.fixed = True
def unfix(self):
- "Set the variable to be modifiable again."
+ "Make the variable modifiable again."
self.fixed = False
def value(self, depth=0):