コード例 #1
0
    def reset(self):
        if self.type not in ["config", "menuconfig"]:
            return

        config = data.get_config(self.value)
        if not config['is_user_set']:
            logger.info("Option '%s' = %s is default value" %
                        (self.value, self.get_value()))
            return

        logger.info("Reset option '%s' = %s to default value" %
                    (self.value, self.get_value()))
        if 'choice_group' in config:
            group = config['choice_group']
            cg = data.get_choice_group(group)
            for k in cg['configs']:
                choice_config = data.get_config(k)
                # We need to set it to False because update_defaults will ignore otherwise
                choice_config['is_user_set'] = False
            cg.pop('requested_value', None)  # pop if available
        else:
            config.pop('requested_value', None)  # pop if available

        # We need to set it to False because update_defaults will ignore if user set
        config['is_user_set'] = False
        update_defaults(self.value)
        logger.info("After reset: %s" % self.get_value())
コード例 #2
0
def update_choice_default(c):
    """Update a choice group to select the best default"""

    choice_group = data.get_choice_group(c)

    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']

    selection = choice_group.get("selected")
    requested = choice_group.get("requested_value")
    s_rank = (100, 0)  # Higher than any other
    if selection is not None:
        s_rank = choice_rank(selection, requested)

    for k in choice_group['configs']:
        if k == selection:
            continue
        k_rank = choice_rank(k, requested)

        if k_rank < s_rank:
            # A better choice
            selection = k
            s_rank = k_rank

    if selection != choice_group.get("selected"):
        set_config_internal(selection, True)
コード例 #3
0
 def can_enable(self):
     if self.type == "config":
         config = data.get_config(self.value)
         if 'choice_group' in config:
             # Check if any member of the group is forced by a select
             group = config['choice_group']
             for k in data.get_choice_group(group)['configs']:
                 if k != self.value and len(
                         data.get_config(k)['selected_by']) > 0:
                     return False
     elif self.type == "empty":
         return False
     return can_enable(data.get_menu_configitem(self.type, self.value))
コード例 #4
0
ファイル: general.py プロジェクト: ARM-software/bob-build
 def __clear_config_source(self, key):
     """
     Clear 'source' property of a config and all its
     counterparts if it's a member of a choice group
     """
     config = data.get_config(key)
     if "choice_group" in config:
         group = config['choice_group']
         cg = data.get_choice_group(group)
         for k in cg['configs']:
             c2 = data.get_config(k)
             c2.pop('source', None)
     else:
         config.pop('source', None)
コード例 #5
0
 def get_help(self):
     if self.type in ["config", "menuconfig"]:
         config = data.get_config(self.value)
         text = self.value + ": " + config['title'] + "\n\n"
         if "help" in config:
             text += config['help']
         else:
             text += "No help available"
         return text
     elif self.type in ["choice"]:
         choice = data.get_choice_group(self.value)
         text = choice['title'] + "\n\n"
         if "help" in choice:
             text += choice['help']
         else:
             text += "No help available"
         return text
     elif self.type in ["menu"]:
         config = data.get_menu(self.value)
         if 'help' in config:
             return config['help']
     return "No help available"
コード例 #6
0
def menu_parse():
    menus = {None: []}
    for i in data.get_menu_list():
        menus[i] = []

    menuconfig_stack = []
    depends_stack = []

    for (i_type, i_symbol) in data.iter_symbols_menuorder():
        if i_type == "config":
            config = data.get_config(i_symbol)
            inmenu = config.get('inmenu')

            if 'title' not in config:
                # No title, so we don't display it
                continue

            while len(depends_stack) > 0:
                if expr.check_depends(config.get('depends'),
                                      depends_stack[-1]):
                    break
                depends_stack.pop()

            while len(menuconfig_stack) > 0:
                if expr.check_depends(config.get('depends'),
                                      menuconfig_stack[-1]):
                    inmenu = menuconfig_stack[-1]
                    break
                menuconfig_stack.pop()
                depends_stack = []

            if 'choice_group' in config:
                inmenu = config['choice_group']

            config['depends_indent'] = len(depends_stack)

            menus[inmenu].append(MenuItem('config', i_symbol))

            depends_stack.append(i_symbol)
        elif i_type == "menuconfig":
            config = data.get_config(i_symbol)
            inmenu = config.get('inmenu')

            while len(menuconfig_stack) > 0:
                if expr.check_depends(config.get('depends'),
                                      menuconfig_stack[-1]):
                    inmenu = menuconfig_stack[-1]
                    break
                menuconfig_stack.pop()

            menuconfig_stack.append(i_symbol)
            menus[i_symbol] = []

            menus[inmenu].append(MenuItem('menuconfig', i_symbol))
        elif i_type == "menu":
            menu = data.get_menu(i_symbol)
            inmenu = menu.get('inmenu')

            menuconfig_stack = []

            menus[inmenu].append(MenuItem('menu', i_symbol))
        elif i_type == "choice":
            inmenu = data.get_choice_group(i_symbol).get('inmenu')

            menus[i_symbol] = []

            menus[inmenu].append(MenuItem('choice', i_symbol))
        else:
            raise Exception("Unexpected menu item: type {}, symbol {}".format(
                i_type, i_symbol))
    return menus
コード例 #7
0
    def get_styled_text(self, is_selected, max_width):
        text_parts = []
        if self.type == "config":
            config = data.get_config(self.value)

            indent = config.get("depends_indent") or 0
            # Display "(new)" next to menu options that have no previously selected value
            new_text = " (new)" if config.get('is_new') else ""

            show_value = display_value(config['value'], config['datatype'])
            if len(config['selected_by']) > 0:
                text_parts.append(StyledText("-"))
                text_parts.append(StyledText("%s" % show_value))
                text_parts.append(StyledText("-"))
            elif 'choice_group' in config or config['datatype'] != "bool":
                text_parts.append(StyledText("("))
                trim_to = max_width - len(
                    config['title']) - indent - len(new_text) - 3
                trim_to = max(trim_to, 8)  # we want to display something
                if trim_to >= len(show_value):
                    text_parts.append(StyledText("%s" % show_value))
                else:
                    text_parts.append(
                        StyledText("%s..." % show_value[:(trim_to - 3)]))
                text_parts.append(StyledText(")"))
            else:
                text_parts.append(StyledText("["))
                text_parts.append(StyledText("%s" % show_value))
                text_parts.append(StyledText("]"))

            if config['is_user_set']:
                text_parts[1].style = 'option_set_by_user'

            text_parts.append(
                StyledText(" %s%s%s" % ("  " *
                                        (indent), config['title'], new_text)))
        elif self.type == "menu":
            text_parts.append(StyledText("   "))
            text_parts.append(
                StyledText(" %s --->" % data.get_menu_title(self.value)))
        elif self.type == "menuconfig":
            config = data.get_config(self.value)
            is_menu_enabled = '>'
            if config['value'] is False:
                # Submenu is empty
                is_menu_enabled = '-'

            text_parts.append(StyledText("["))
            show_value = display_value(config['value'], config['datatype'])
            trim_to = max_width - len(config['title']) - 5
            trim_to = max(trim_to, 8)  # we want to display something
            if trim_to >= len(show_value):
                text_parts.append(StyledText("%s" % show_value))
            else:
                text_parts.append(
                    StyledText("%s..." % show_value[:(trim_to - 5)]))
            text_parts.append(StyledText("]"))
            text_parts.append(
                StyledText(" %s ---%s" % (config['title'], is_menu_enabled)))

            if config['is_user_set']:
                text_parts[1].style = 'option_set_by_user'
        elif self.type == "choice":
            choice = data.get_choice_group(self.value)
            current_value = ''
            for i in choice['configs']:
                if data.get_config(i)['value'] is True:
                    current_value = data.get_config(i).get('title')
                    break
            text_parts.append(StyledText("   "))
            text_parts.append(
                StyledText(" %s (%s)" % (choice['title'], current_value)))
        elif self.type == "empty":
            text_parts.append(StyledText("***"))
            text_parts.append(StyledText(" Empty Menu ***"))
        else:
            raise Exception("Unknown type (%s)" % self.type)

        text_parts[
            -1].style = 'highlight' if is_selected else get_default_style()
        return text_parts
コード例 #8
0
def set_config(key, value, is_user_set=True):
    try:
        c = data.get_config(key)
    except KeyError:
        logger.warning("Ignoring unknown configuration option %s" % key)
        return

    if is_user_set:
        # Validate user input
        if c['datatype'] == 'bool':
            # Must be y or n
            if value not in [True, False]:
                logger.warning(
                    "Ignoring boolean configuration option %s with non-boolean value '%s'."
                    % (key, value))
                return
        elif c['datatype'] == 'int':
            # Must convert to an integer
            try:
                value = int(value)
            except ValueError:
                logger.warning(
                    "Ignoring integer configuration option %s with non-integer value '%s'"
                    % (key, value))
                return

    # Record user specified value even if it is (currently) impossible
    c['is_user_set'] |= is_user_set
    if is_user_set:
        if "choice_group" in c:
            group = c['choice_group']
            if value is True:
                # Record the selection for this group
                data.get_choice_group(group)['requested_value'] = key
        else:
            c['requested_value'] = value

    if c['datatype'] == 'bool':
        if value is False and len(c['selected_by']) > 0:
            # Option is forced, so cannot be turned off
            return
        if value is True and not can_enable(c):
            # Option is unavailable, so cannot be turned on. However if the
            # option is selected by another we force it on regardless
            if len(c['selected_by']) == 0:
                return

    c['value'] = value
    if is_user_set:
        c['is_new'] = False

    if "choice_group" in c:
        group = c['choice_group']
        cg = data.get_choice_group(group)

        if value is True:
            # Record the selection for this group
            cg['selected'] = key
            # Member of a choice group - unset all other items
            for k in cg['configs']:
                if k != key:
                    set_config(k, False, is_user_set=is_user_set)
                    if data.get_config(k)['value'] is True:
                        # Failed to turn the other option off, so set this to n
                        c['value'] = False
                        return
        else:
            # Check if this is the last entry in a choice being unset.
            # If there is no other option set then either this entry will be
            # set back to 'y' - or if this entry cannot be set, the best default
            # entry in the choice will be picked
            for k in cg['configs']:
                if k != key and data.get_config(k)['value'] is True:
                    break
            else:
                if can_enable(c):
                    cg['selected'] = key
                    c['value'] = True
                else:
                    # Reset current selection.
                    cg['selected'] = None
                    update_choice_default(group)

    if "select" in c:
        for k in c["select"]:
            force_config(k, value, key)

    set_config_selectifs(key)

    if "rdepends" in c:
        # Check any reverse dependencies to see if they need updating
        for k in c['rdepends']:
            c2 = data.get_config(k)
            if c2['value'] is True and not can_enable(c2):
                set_config_internal(k, False)
            elif not c2['is_user_set']:
                update_defaults(k)
            elif "choice_group" in c2:
                update_choice_default(c2['choice_group'])
            elif 'requested_value' in c2 and c2['value'] != c2[
                    'requested_value']:
                set_config(k, c2['requested_value'])

    if "rdefault" in c:
        # Check whether any default values need updating
        for k in c['rdefault']:
            update_defaults(k)

    if "rselect_if" in c:
        # Update any select_ifs that might now be valid
        for k in c['rselect_if']:
            set_config_selectifs(k)