|
32 | 32 | positive_answers = ('Y', 'y', 'yes', 'ja',) |
33 | 33 | negative_answers = ('N', 'n', 'no', 'nein',) |
34 | 34 |
|
35 | | -# FIXME find a better abstraction/representation |
36 | | -questions = {'auto_display_list': {'question': 'Do you want to show the autocomplete list as you type (y/n):', |
37 | | - 'answers': {positive_answers: 'True', |
38 | | - negative_answers: 'False'}, |
39 | | - 'section': 'general' |
40 | | - }, |
41 | | - 'arg_spec': {'question': 'Do you want to show the argspec (y/n):', |
42 | | - 'answers': {positive_answers: 'True', |
43 | | - negative_answers: 'False'}, |
44 | | - 'section': 'general' |
45 | | - }, |
46 | | - 'syntax': {'question': 'Do you want syntax highlighting as you type (y/n):', |
47 | | - 'answers': {positive_answers: 'True', |
48 | | - negative_answers: 'False'}, |
49 | | - 'section': 'general' |
50 | | - } |
51 | | - } |
| 35 | +# Create default answer |
| 36 | +positive_negative = {positive_answers: 'True', |
| 37 | + negative_answers: 'False'} |
| 38 | + |
| 39 | +# Create dict for storing everythin |
| 40 | +questions = {} |
| 41 | + |
| 42 | +# Create sections |
| 43 | +questions['general'] = {} |
| 44 | +questions['keyboard'] = {} |
| 45 | + |
| 46 | +questions['general']['auto_display_list'] = {'question': 'Do you want to show the autocomplete list as you type (y/n):', |
| 47 | + 'answers': positive_negative} |
| 48 | + |
| 49 | +questions['general']['arg_spec'] = {'question': 'Do you want to show the argspec (y/n):', |
| 50 | + 'answers': positive_negative} |
| 51 | + |
| 52 | +questions['general']['syntax'] = {'question': 'Do you want syntax highlighting as you type (y/n):', |
| 53 | + 'answers': positive_negative} |
52 | 54 |
|
53 | 55 | filename = os.path.expanduser('~/.bpython/config') |
54 | 56 |
|
@@ -81,26 +83,24 @@ def run_wizard(): |
81 | 83 | else: |
82 | 84 | config = ConfigParser() |
83 | 85 |
|
84 | | - # FIXME hacks |
85 | | - config.add_section('general') |
86 | | - config.add_section('keyboard') |
87 | | - |
88 | | - # Ask the questions |
89 | | - print |
90 | | - for config_value, question in questions.iteritems(): |
91 | | - while 1: |
92 | | - print question['question'], |
93 | | - answer = raw_input() |
94 | | - |
95 | | - if answer in positive_answers: |
96 | | - config.set(['section'], config_value, question['answers'][positive_answers]) |
97 | | - break |
98 | | - elif answer in negative_answers: |
99 | | - config.set(question['section'], config_value, question['answers'][negative_answers]) |
100 | | - break |
101 | | - else: |
102 | | - print |
103 | | - print 'I couldn\'t understand the answer you provided, please try again' |
| 86 | + for section_name, section in questions.iteritems(): |
| 87 | + config.add_section(section_name) |
| 88 | + |
| 89 | + print |
| 90 | + for config_value, q in section.iteritems(): |
| 91 | + while 1: |
| 92 | + print q['question'], |
| 93 | + answer = raw_input() |
| 94 | + |
| 95 | + if answer in positive_answers: |
| 96 | + config.set(section_name, config_value, q['answers'][positive_answers]) |
| 97 | + break |
| 98 | + elif answer in negative_answers: |
| 99 | + config.set(section_name, config_value, q['answers'][negative_answers]) |
| 100 | + break |
| 101 | + else: |
| 102 | + print |
| 103 | + print "I couldn't understand the answer you provided, please try again" |
104 | 104 |
|
105 | 105 | config.write(open(filename, 'w')) |
106 | 106 |
|
|
0 commit comments