<commit_before>#!/usr/bin/env python

# Copyright (c) 2018-2019, <NAME>
# SPDX-License-Identifier: ISC

# Implements oldconfig functionality:
#
#   1. Load existing .config
#   2. Prompt the user for the value of all modifiable symbols/choices that
#      aren't already set in the .config
#   3. Write new .config
#
# The default input/output filename is '.config'. A different filename can be
# passed in the KCONFIG_CONFIG environment variable.
#
# Unlike 'make oldconfig', this script doesn't print menu titles and comments,
# but gives Kconfig definition locations. Printing menus and comments would be
# pretty easy to add: Look at the parents of each item and print all menu
# prompts and comments unless they have already been printed (assuming you want
# to skip "irrelevant" menus).
#
# Entering '?' displays the help text of the symbol/choice, if any.

from __future__ import print_function

import sys

from kconfiglib import Symbol, Choice, BOOL, TRISTATE, HEX, standard_kconfig


# Python 2/3 compatibility hack
if sys.version_info[0] < 3:
    input = raw_input


# Note: Used as the entry point in setup.py
def _main():
    # Earlier symbols in Kconfig files might depend on later symbols and become
    # visible if their values change. This flag is set to True if the value of
    # any symbol changes, in which case we rerun the oldconfig to check for new
    # visible symbols.
    global conf_changed

    kconf = standard_kconfig()
    kconf.load_config()

    while True:
        conf_changed = False

        for node in kconf.node_iter():
            oldconfig(node)

        if not conf_changed:
            break

    kconf.write_config()


def oldconfig(node):
    """
    Prompts the user for a value if node.item is a visible symbol/choice with
    no user value.
    """
    # See main()
    global conf_changed

    # Only symbols and choices can be configured
    if not isinstance(node.item, (Symbol, Choice)):
        return

    # Skip symbols and choices that aren't visible
    if not node.item.visibility:
        return

    # Skip symbols and choices that don't have a prompt (at this location)
    if not node.prompt:
        return

    if isinstance(node.item, Symbol):
        sym = node.item

        # Skip symbols that already have a user value
        if sym.user_value is not None:
            return

        # Skip symbols that can only have a single value, due to selects
        if len(sym.assignable) == 1:
            return

        # Skip symbols in choices in y mode. We ask once for the entire choice
        # instead.
        if sym.choice and sym.choice.tri_value == 2:
            return

        # Loop until the user enters a valid value or enters a blank string
        # (for the default value)
        while True:
            val = input("{} ({}) [{}] ".format(
                            node.prompt[0], _name_and_loc_str(sym),
                            _default_value_str(sym)))

            if val == "?":
                _print_help(node)
                continue<commit_msg>oldconfig: Style nit<commit_after>#!/usr/bin/env python

# Copyright (c) 2018-2019, <NAME>
# SPDX-License-Identifier: ISC

# Implements oldconfig functionality:
#
#   1. Load existing .config
#   2. Prompt the user for the value of all modifiable symbols/choices that
#      aren't already set in the .config
#   3. Write new .config
#
# The default input/output filename is '.config'. A different filename can be
# passed in the KCONFIG_CONFIG environment variable.
#
# Unlike 'make oldconfig', this script doesn't print menu titles and comments,
# but gives Kconfig definition locations. Printing menus and comments would be
# pretty easy to add: Look at the parents of each item and print all menu
# prompts and comments unless they have already been printed (assuming you want
# to skip "irrelevant" menus).
#
# Entering '?' displays the help text of the symbol/choice, if any.

from __future__ import print_function

import sys

from kconfiglib import Symbol, Choice, BOOL, TRISTATE, HEX, standard_kconfig


# Python 2/3 compatibility hack
if sys.version_info[0] < 3:
    input = raw_input


# Note: Used as the entry point in setup.py
def _main():
    # Earlier symbols in Kconfig files might depend on later symbols and become
    # visible if their values change. This flag is set to True if the value of
    # any symbol changes, in which case we rerun the oldconfig to check for new
    # visible symbols.
    global conf_changed

    kconf = standard_kconfig()
    kconf.load_config()

    while True:
        conf_changed = False

        for node in kconf.node_iter():
            oldconfig(node)

        if not conf_changed:
            break

    kconf.write_config()


def oldconfig(node):
    """
    Prompts the user for a value if node.item is a visible symbol/choice with
    no user value.
    """
    # See main()
    global conf_changed

    # Only symbols and choices can be configured
    if not isinstance(node.item, (Symbol, Choice)):
        return

    # Skip symbols and choices that aren't visible
    if not node.item.visibility:
        return

    # Skip symbols and choices that don't have a prompt (at this location)
    if not node.prompt:
        return

    if isinstance(node.item, Symbol):
        sym = node.item

        # Skip symbols that already have a user value
        if sym.user_value is not None:
            return

        # Skip symbols that can only have a single value, due to selects
        if len(sym.assignable) == 1:
            return

        # Skip symbols in choices in y mode. We ask once for the entire choice
        # instead.
        if sym.choice and sym.choice.tri_value == 2:
            return

        # Loop until the user enters a valid value or enters a blank string
        # (for the default value)
        while True:
            val = input("{} ({}) [{}] ".format(
                node.prompt[0], _name_and_loc_str(sym),
                _default_value_str(sym)))

            if val == "?":
                _print_help(node)
                continue
{'fraction_non_alphanumeric': 0.07118198257438764, 'fraction_numerical': 0.005918132500410981, 'mean_word_length': 2.4509359047078845, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3456662', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1608, 'n_words': 721}