<s> from __future__ import absolute_import <EOL> import os <EOL> from . import config_file <EOL> from . import config_option <EOL> from . import current_config <EOL> from . import prompt <EOL> def load_option ( option , mode , newConfig , <EOL> instanceConfig = None ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in os . environ and option . has_test_value ( ) : <EOL> option . set ( option . test_value ( ) ) <EOL> return <EOL> suggestions = [ ] <EOL> instance_value = instanceConfig . get ( option . config_file_key ( ) ) <EOL> if instance_value is not None : <EOL> suggestions . append ( prompt . Suggestion ( instance_value , '<STR_LIT>' , <EOL> desc = '<STR_LIT>' , default = True ) ) <EOL> suggestions += option . suggestions ( ) <EOL> if option . optional ( ) : <EOL> suggestions . append ( prompt . Suggestion ( '<STR_LIT>' , '<STR_LIT:N>' , <EOL> desc = '<STR_LIT:none>' , default = True ) ) <EOL> try_defaults_lte = config_option . Visibility . DEFAULT <EOL> if mode == '<STR_LIT>' : <EOL> try_defaults_lte = config_option . Visibility . NEVER <EOL> elif mode == '<STR_LIT>' : <EOL> try_defaults_lte = config_option . Visibility . HIDDEN <EOL> elif mode == '<STR_LIT>' : <EOL> pass <EOL> elif mode == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> raise config_option . BadValue ( '<STR_LIT>' % mode ) <EOL> valid = False <EOL> if option . visibility ( ) <= try_defaults_lte : <EOL> for s in [ s for s in suggestions if s . default ] : <EOL> try : <EOL> option . set ( s . value ) <EOL> valid = True <EOL> break <EOL> except config_option . BadValue as e : <EOL> print '<STR_LIT>' % ( option . config_file_key ( ) , s . value ) <EOL> print '<STR_LIT>' % e <EOL> if not valid : <EOL> if mode == '<STR_LIT>' : <EOL> raise RuntimeError ( '<STR_LIT>' % option . config_file_key ( ) ) <EOL> else : <EOL> prompt . print_section_header ( option . prompt_title ( ) ) <EOL> value = prompt . get_input ( <EOL> message = option . prompt_message ( ) , <EOL> validator = option . validate , <EOL> suggestions = suggestions , <EOL> is_path = option . is_path ( ) , <EOL> ) <EOL> print <EOL> option . set ( value ) <EOL> newConfig . set ( option . config_file_key ( ) , option . _config_file_value ) <EOL> def load_config ( mode = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> current_config . reset ( ) <EOL> instanceConfig = config_file . InstanceConfigFile ( ) <EOL> newConfig = config_file . InstanceConfigFile ( ) <EOL> non_framework_options = [ o for o in current_config . option_list <EOL> if not isinstance ( o , config_option . FrameworkOption ) ] <EOL> framework_options = [ o for o in current_config . option_list <EOL> if isinstance ( o , config_option . FrameworkOption ) ] <EOL> for option in non_framework_options : <EOL> load_option ( option , mode , newConfig , instanceConfig ) <EOL> has_one_framework = False <EOL> verbose_for_frameworks = False <EOL> while not has_one_framework : <EOL> if verbose_for_frameworks and mode == '<STR_LIT>' : <EOL> framework_mode = '<STR_LIT>' <EOL> else : <EOL> framework_mode = mode <EOL> for option in framework_options : <EOL> load_option ( option , framework_mode , newConfig , instanceConfig ) <EOL> if option . has_value ( ) : <EOL> has_one_framework = True <EOL> if not has_one_framework : <EOL> errstr = '<STR_LIT>' <EOL> if mode == '<STR_LIT>' : <EOL> raise RuntimeError ( errstr ) <EOL> else : <EOL> print errstr <EOL> verbose_for_frameworks = True <EOL> for option in current_config . option_list : <EOL> option . apply ( ) <EOL> if newConfig . dirty ( ) and newConfig . can_write ( ) : <EOL> newConfig . save ( ) <EOL> print '<STR_LIT>' % newConfig . filename ( ) </s>
