def set(self, cfg={}): """ sync config, do_set, dump. """ ml_log.log(self.tag + ".set()") ret = ml_check.sync(self.cfg, cfg, self.main_syntax) if not ret[0]: return ret self.write_lock() try: ret = self.do_set() except Exception as e: ret = (False, [str(e)]) self.write_unlock() if not ret[0]: # do_set fails, load old cfg then do_set. ret_load = self.load() if ret_load[0]: self.write_lock() try: ret_set = self.do_set() except Exception as e: ret_set = (False, [str(e)]) self.write_unlock() return ret else: return self.dump()
def load(self): """ load from a file """ ml_log.log(self.tag + ".load()") self.read_lock() e = self.do_load() self.read_unlock() if not e[0]: return e ret = ml_check.sync(self.cfg, e[1], self.main_syntax) if not ret[0]: return ret return (True, None)