def search(stdscr, window):
    (success, string) = inputbox(stdscr,
                                 window,
                                 title="Search",
                                 prompt="Enter substring to search for")
    if not success:
        return
    string = string.lower()
    results = ""
    for i in data.get_config_list():
        config = data.get_config(i)
        if (string in i.lower()
                or string in (config.get("title") or "").lower()
                or string in (config.get("help") or "").lower()):
            results += "Symbol: %s [=%s]\n" % (i, config["value"])
            results += "Type  : %s\n" % (config["datatype"], )
            if "title" in config:
                results += "Prompt: %s\n" % (config["title"], )
            menu_stack = get_menu_location(i)
            if len(menu_stack) > 0:
                results += "  Location:\n"
            indent = 2
            while len(menu_stack) > 0:
                m = menu_stack.pop()
                indent += 2
                results += " " * indent
                results += "-> %s\n" % (m, )
            results += "\n\n"
    if results == "":
        results = "No matches found"
    prompt(stdscr, window, results)
Example #2
0
def enforce_dependent_values(auto_fix=False):
    """
    Check that values are consistently set, specifically with respect
    to whether the dependencies are correct.

    For boolean values we only reset to n if auto_fix is
    True. Otherwise we raise an exception (the Mconfig needs to be
    fixed).

    For string and int values, if the configuration value is not
    enabled, reset them to "" and 0 respectively. This is different to
    the bool case as we need to reset default values.
    """
    for i in data.get_config_list():
        c = data.get_config(i)
        if can_enable(c):
            continue
        if c['datatype'] == 'bool' and c['value'] is True:
            logger.warning("unmet direct dependencies: " + "%s depends on %s" %
                           (i, c['depends']))
            if auto_fix:
                set_config_internal(i, False)
            else:
                raise Exception("Unmet direct dependencies")
        elif c['datatype'] == 'string':
            set_config_internal(i, '')
        elif c['datatype'] == 'int':
            set_config_internal(i, 0)
Example #3
0
def set_initial_values():
    "Set all configuration objects to their default value"

    config_list = data.get_config_list()

    # Set up initial values, and set up reverse dependencies
    for k in config_list:
        c = data.get_config(k)
        c['selected_by'] = set()
        c['is_user_set'] = False
        c['is_new'] = True
        if c['datatype'] == "bool":
            c['value'] = False
        elif c['datatype'] == "int":
            c['value'] = 0
        else:
            c['value'] = ''

        for i in expr.dependency_list(c.get("depends")):
            data.get_config(i).setdefault('rdepends', []).append(k)

        if "default_cond" in c:
            for j in c['default_cond']:
                for i in expr.dependency_list(j['cond']):
                    data.get_config(i).setdefault('rdefault', []).append(k)
                value_deps = expr.dependency_list(j['expr'])
                for d in value_deps:
                    data.get_config(d).setdefault('rdefault', []).append(k)

        if "default" in c:
            value_deps = expr.dependency_list(c['default'])
            for d in value_deps:
                data.get_config(d).setdefault('rdefault', []).append(k)

        if "select_if" in c:
            for j in c['select_if']:
                for i in expr.dependency_list(j[1]):
                    data.get_config(i).setdefault('rselect_if', []).append(k)

    # Check for dependency cycles
    for k in config_list:
        c = data.get_config(k)
        if k in c.get('rdepends', []):
            logger.error("%s depends on itself" % k)
            c['rdepends'].remove(k)
        if k in c.get('rdefault', []):
            logger.error("The default value of %s depends on itself" % k)
            c['rdefault'].remove(k)

    # Set values using defaults and taking into account dependencies
    for k in config_list:
        update_defaults(k)

    for k in config_list:
        update_bob_ignore(k)
Example #4
0
def enforce_dependent_values(stage,
                             fix_bools=False,
                             error_level=logging.WARNING):
    """
    Check that values are consistently set, specifically with respect
    to whether the dependencies are correct.

    This function is called when we expect the values to be
    consistent. i.e. after reading in a new config, or prior to
    writing it out. It is called prior to plugin execution, to try and
    ensure the plugins see consistent state.

    For non-boolean configs (string, int), set their value to default
    ("", 0) if the config's dependencies are not met. This can happen
    where a user sets the value of the config, and then changes
    another config resulting in the dependency being disabled.

    Boolean values are treated specially. Normally they will be kept
    in a consistent state (wrt dependencies) by set_config(). However
    they can be forced by a 'select' statement even when the
    dependencies are not met. This indicates there is a problem with
    the Mconfig that needs to be fixed. This function will only reset
    Boolean values to n if specifically requested by fix_bools=True.
    This is only expected to be used after reading in a config file.
    That file may have been written with a different Mconfig that
    allowed the selection.

    The error_level determines the log level at which bool
    inconsistencies are reported. When set to logging.ERROR this forces
    the user to fix the Mconfig.
    """
    for i in data.get_config_list():
        c = data.get_config(i)
        if can_enable(c):
            continue
        if c['datatype'] == 'bool' and c['value'] is True:
            if len(c['selected_by']) > 0:
                msg = "{0}unmet direct dependencies: {1} depends on {2}, " \
                      "but is selected by [{3}].".format(stage, i,
                                                         c['depends'][1],
                                                         ",".join(c['selected_by']))
                if error_level is logging.ERROR:
                    msg += " Update the Mconfig so that this can't happen"
                logger.log(error_level, msg)
            else:
                raise Exception("Unmet direct dependencies without select")

            if fix_bools:
                set_config_internal(i, False)

        elif c['datatype'] == 'string':
            set_config_internal(i, '')
        elif c['datatype'] == 'int':
            set_config_internal(i, 0)
Example #5
0
def config_to_json():
    properties = dict()

    for key in data.get_config_list():
        c = data.get_config(key)
        key = key.lower()
        datatype = c["datatype"]
        value = c["value"]

        if datatype not in ["bool", "int", "string"]:
            logger.error("Invalid config type: %s (with value '%s')\n" %
                         (datatype, str(value)))

        if datatype == "int":
            value = int(value)

        properties[key] = {"ignore": c["bob_ignore"] == 'y', "value": value}

    return properties
Example #6
0
def config_to_json():
    properties = dict()

    for key in data.get_config_list():
        c = data.get_config(key)
        key = key.lower()
        datatype = c["datatype"]
        value = c["value"]

        if datatype == "bool":
            properties[key] = value
        elif datatype == "int":
            properties[key] = int(value)
        elif datatype == "string":
            properties[key] = value
        else:
            logger.error("Invalid config type: %s (with value '%s')\n" %
                         (datatype, str(value)))

    return properties
Example #7
0
def validate_configs():
    """
    Ensure that the types in 'default' statements are correct,
    and that the configs referred to in 'select' statements are boolean.
    """
    config_list = data.get_config_list()
    for k in config_list:
        c = data.get_config(k)
        if "default_cond" in c:
            for i in c['default_cond']:
                check_type(k, c, i['expr'])
        if "default" in c:
            check_type(k, c, c["default"])
        if "select_if" in c:
            for k in c["select_if"]:
                try:
                    c1 = data.get_config(k[0])
                except KeyError:
                    logger.warning("Ignoring unknown configuration option %s" %
                                   k[0])
                    continue
                if c1['datatype'] != "bool":
                    logger.error(
                        'Select option must have type bool but got type %s instead'
                        % c1['datatype'])
        if "select" in c:
            for k in c["select"]:
                try:
                    c1 = data.get_config(k)
                except KeyError:
                    logger.warning("Ignoring unknown configuration option %s" %
                                   k)
                    continue
                if c1['datatype'] != "bool":
                    logger.error(
                        'Select option must have type bool but got type %s instead'
                        % c1['datatype'])