Пример #1
0
def write_config(config_filename):
    enforce_dependent_values()
    with utils.open_and_write_if_changed(config_filename) as f:
        for (i_type, i_symbol) in data.iter_symbols_menuorder():
            if i_type in ["config", "menuconfig"]:
                c = data.get_config(i_symbol)
                mark_set_by_user = "******"
                if not can_enable(c):
                    # Don't output this option because it cannot be enabled
                    continue
                elif c['datatype'] == "bool":
                    if c['value'] is True:
                        f.write("CONFIG_%s=y" % i_symbol)
                    else:
                        f.write("# CONFIG_%s is not set" % i_symbol)
                        mark_set_by_user = "******"
                elif c['datatype'] == "string":
                    quoted_str = re.sub(r'(["\\])', r'\\\1', c['value'])
                    f.write('CONFIG_%s="%s"' % (i_symbol, quoted_str))
                else:
                    f.write("CONFIG_%s=%s" % (i_symbol, c['value']))
                # Save meta data as user explicit mark this
                if c['is_user_set']:
                    f.write("%s" % mark_set_by_user)
                f.write("\n")
            elif i_type == "menu":
                f.write("\n#\n# %s\n#\n" % data.get_menu_title(i_symbol))
    logger.info("Written configuration to '%s'" % config_filename)
def get_menu_location(value):
    for i in general.menu_data:
        for k in general.menu_data[i]:
            if k.value == value:
                parent = [data.get_menu_title(i)]
                parent += get_menu_location(i)
                return parent
    return []
Пример #3
0
    def __init__(self, menu_number):
        self.items = menu_data[menu_number]
        self.title_bar = data.get_title_bar()
        self.selection = 0
        self.top = 0
        self.title = data.get_menu_title(menu_number)

        if len(self.items) == 0:
            # empty menu
            self.items = [MenuItem('empty', None)]
        elif data.is_choice_group(menu_number):
            # Find currently selected entry
            while self.items[self.selection].get_value() is not True:
                if self.selection < len(self.items) - 1:
                    self.selection += 1
                else:
                    break

        while not self.items[self.selection].can_enable():
            if self.selection < len(self.items) - 1:
                self.selection += 1
            else:
                break
Пример #4
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