def set(self, req): if not self.section: return EMPTY_SECTION if not self.option: return EMPTY_OPTION if not self.value: return EMPTY_VALUE cfgs = req.cfg.options.get(self.section, {}).get(self.option, {}).values() if not cfgs: return UNKNOWN_OPTION cls = cfgs[0][1] try: smart_get(self.value, cls) except: return BAD_VALUE m = driver(req) rv = m.option_set(self, req) write_timestamp(req, req.cfg.options_timestamp) return rv
def load_options(req): for sec, _sec in req.cfg.options.items(): for opt, _opt in _sec.items(): if sec == "morias" and opt == "debug": # too much danger continue if not _opt: # empty dictionary continue item = Option(sec, opt) cls = _opt.values()[0][1] var = "%s_%s" % (sec, opt) try: if item.get(req) is None: continue req.cfg.__dict__[var] = smart_get(item.value, cls) req.log_error("Set cfg.%s from options DB to `%s'" % (var, item.value.encode("utf-8")), state.LOG_INFO) except: exc_type, exc_value, exc_traceback = exc_info() traceback = format_exception(exc_type, exc_value, exc_traceback) traceback = "".join(traceback) req.log_error("Failed to load cfg.%s from options DB:" % var, state.LOG_ERR) req.log_error(traceback, state.LOG_ERR)