def load_option(option, mode, newConfig,
                instanceConfig=None):
    """
    Called from load_config() [below]

    Arguments:
    option -- an Option instance
    mode -- see docstring for load_config()
    newConfig -- an instance of ConfigFile
    instanceConfig -- the current InstanceConfigFile
    """
    if 'DIGITS_MODE_TEST' in os.environ and option.has_test_value():
        option.set(option.test_value())
        return

    suggestions = []
    instance_value = instanceConfig.get(option.config_file_key())
    if instance_value is not None:
        suggestions.append(prompt.Suggestion(instance_value, '',
            desc = 'Previous', default = True))
    suggestions += option.suggestions()
    if option.optional():
        suggestions.append(prompt.Suggestion('', 'N',
            desc = 'none', default = True))

    # Try to use the default values for options less than
    #   or equal to (LTE) this value
    try_defaults_lte = config_option.Visibility.DEFAULT

    if mode == 'verbose':
        try_defaults_lte = config_option.Visibility.NEVER
    elif mode == 'normal':
        try_defaults_lte = config_option.Visibility.HIDDEN
    elif mode == 'quiet':
        pass
    elif mode == 'force':
        pass
    else:
        raise config_option.BadValue('Unknown mode "%s"' % mode)

    valid = False
    if option.visibility() <= try_defaults_lte:
        # check for a valid default value
        for s in [s for s in suggestions if s.default]:
            try:
                option.set(s.value)
                valid = True
                break
            except config_option.BadValue as e:
                print 'Default value for %s "%s" invalid:' % (option.config_file_key(), s.value)
                print '\t%s' % e
    if not valid:
        if mode == 'force':
            raise RuntimeError('No valid default value found for configuration option "%s"' % option.config_file_key())
        else:
            # prompt user for value
            prompt.print_section_header(option.prompt_title())
            value = prompt.get_input(
                    message     = option.prompt_message(),
                    validator   = option.validate,
                    suggestions = suggestions,
                    is_path     = option.is_path(),
                    )
            print
            option.set(value)
            newConfig.set(option.config_file_key(), option._config_file_value)
dataset/ETHPy150Open NVIDIA/DIGITS/digits/config/load.py/load_option/original