Skip to content

Commit 3cede9a

Browse files
committed
Better question abstraction
1 parent 97aea7a commit 3cede9a

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

bpython/wizard.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@
3232
positive_answers = ('Y', 'y', 'yes', 'ja',)
3333
negative_answers = ('N', 'n', 'no', 'nein',)
3434

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}
5254

5355
filename = os.path.expanduser('~/.bpython/config')
5456

@@ -81,26 +83,24 @@ def run_wizard():
8183
else:
8284
config = ConfigParser()
8385

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"
104104

105105
config.write(open(filename, 'w'))
106106

0 commit comments

Comments
 (0)