def saveConfig(path, value): try: cnf = get_config_attribute(path, root_obj=config) except Exception as exc: print("[OpenWebif] ", exc) return { "result": False, "message": "I'm sorry Dave, I'm afraid I can't do that" } try: if cnf.__class__.__name__ in ("ConfigBoolean", "ConfigEnableDisable", "ConfigYesNo"): cnf.value = value == "true" elif cnf.__class__.__name__ == "ConfigSet": values = cnf.value if int(value) in values: values.remove(int(value)) else: values.append(int(value)) cnf.value = values elif cnf.__class__.__name__ == "ConfigNumber": cnf.value = int(value) elif cnf.__class__.__name__ in ("ConfigInteger", "TconfigInteger"): cnf_min = int(cnf.limits[0][0]) cnf_max = int(cnf.limits[0][1]) cnf_value = int(value) if cnf_value < cnf_min: cnf_value = cnf_min elif cnf_value > cnf_max: cnf_value = cnf_max cnf.value = cnf_value elif cnf.__class__.__name__ in ("ConfigSlider"): cnf_min = int(cnf.min) cnf_max = int(cnf.max) cnf_value = int(value) if cnf_value < cnf_min: cnf_value = cnf_min elif cnf_value > cnf_max: cnf_value = cnf_max cnf.value = cnf_value else: cnf.value = value cnf.save() except Exception as e: print("[OpenWebif] ", e) return { "result": False } return { "result": True }
def saveConfig(path, value): try: cnf = get_config_attribute(path, root_obj=config) except Exception as exc: print "[OpenWebif] ", exc return { "result": False, "message": "I'm sorry Dave, I'm afraid I can't do that" } try: if cnf.__class__.__name__ in ("ConfigBoolean", "ConfigEnableDisable", "ConfigYesNo"): cnf.value = value == "true" elif cnf.__class__.__name__ == "ConfigSet": values = cnf.value if int(value) in values: values.remove(int(value)) else: values.append(int(value)) cnf.value = values elif cnf.__class__.__name__ == "ConfigNumber": cnf.value = int(value) elif cnf.__class__.__name__ in ("ConfigInteger", "TconfigInteger"): cnf_min = int(cnf.limits[0][0]) cnf_max = int(cnf.limits[0][1]) cnf_value = int(value) if cnf_value < cnf_min: cnf_value = cnf_min elif cnf_value > cnf_max: cnf_value = cnf_max cnf.value = cnf_value else: cnf.value = value cnf.save() except Exception, e: print "[OpenWebif] ", e return { "result": False }