def update_defaults(k): """Set a configuration option to the correct default value if it hasn't been manually set""" c = data.get_config(k) if c.get("is_user_set"): # Has been manually set, so ignore return if "choice_group" in c: update_choice_default(c['choice_group']) return if "default_cond" in c: for i in c['default_cond']: if expr.condexpr_value(i['cond']): set_config_internal(k, expr.expr_value(i['expr'])) return # None of the conditioned defaults match if "default" in c: set_config_internal(k, expr.expr_value(c['default'])) return # No default - so set bools to 'n' if c['datatype'] == "bool": set_config_internal(k, False) elif c['datatype'] == "string": set_config_internal(k, '') elif c['datatype'] == "int": set_config_internal(k, 0)
def choice_rank(k, r): """Produces a ranking value for each choice entry, lower values are higher priority""" config = data.get_config(k) rank = 5 if not can_enable(config): # Lowest rank - cannot be enabled return 6, config['position'] if len(config.get("selected_by")) > 0: rank = 1 if config.get("is_user_set"): if k == r: rank = 2 else: for i in config.get("default_cond", []): if expr.condexpr_value( i['cond']) and expr.expr_value(i['expr']) is True: rank = 3 break else: def_expr = config.get("default", expr.NO) if expr.expr_value(def_expr) is True: rank = 4 return rank, config['position']
def set_config_selectifs(key): c = data.get_config(key) value = c['value'] if "select_if" in c: for k in c["select_if"]: if expr.condexpr_value(k[1]): force_config(k[0], value, key) else: # No longer forced, so turn off if previously forced force_config(k[0], False, key)
def test_condexpr_evaluation(caplog, tmpdir, inputdata, result, error): mconfig_file = tmpdir.join("Mconfig") mconfig = template_condexpr_mconfig.format(**inputdata) mconfig_file.write(mconfig, "wt") data.init(str(mconfig_file), False) c = data.get_config("OPTION") general.set_initial_values() val = expr.condexpr_value(c['default_cond'][0]['cond']) if error is not None: assert error in caplog.text else: assert val == result assert caplog.text == ""
def is_visible(config): # If there is no visible_cond expression, then the config is visible e = config.get('visible_cond') if e is None: return True return expr.condexpr_value(e)
def can_enable(config): # If there is no dependency expression, then the config can be enabled e = config.get('depends') if e is None: return True return expr.condexpr_value(e)