Skip to content

Commit d48d5e0

Browse files
committed
Some work on the wizard, it can now ask questions
1 parent c1586a8 commit d48d5e0

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

bpython/wizard.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,73 @@
2424
#
2525

2626
import os
27+
import sys
2728

28-
def check_first_run():
29-
if not os.path.isfile(os.path.expanduser('~/.bpython/config')):
30-
return False
31-
else:
32-
return True
29+
# questions asked by the wizard (keys are the config values, followed by text
30+
# and answers and defaults
31+
positive_answers = ('Y', 'y', 'yes', 'ja',)
32+
negative_answers = ('N', 'n', 'no', 'nein',)
33+
34+
questions = {'arg_spec': {'question': 'Do you want to show the argspec (y/n): ',
35+
'answers': {positive_answers: 'True',
36+
negative_answers: 'False'}
37+
},
38+
'syntax': {'question': 'Do you want syntax highlighting as you type (y/n): ',
39+
'answers': {positive_answers: 'True',
40+
negative_answers: 'False'}
41+
}
42+
}
43+
44+
filename = os.path.expanduser('~/.bpython/config')
45+
46+
def is_first_run():
47+
return not os.path.isfile(filename)
48+
49+
def create_empty_file():
50+
f = open(filename, 'w')
51+
f.write('')
52+
f.close()
3353

3454
def run_wizard():
3555
"""Run an interactive wizard asking a few questions about the users'
3656
enviroment and write the answers to the configuration file."""
57+
58+
59+
print """Hi there. It seems this is the first time you run bpython. I can
60+
tell because you do not have a configuration file yet. There are a few
61+
options I am going to give you.
62+
63+
I am ready to run the wizard for you now. If you do not want to run the
64+
wizard and just have me create an empty configuration file for you you can
65+
answer no to the following question.
66+
"""
67+
68+
answer = raw_input('Do you want to run the wizard: ')
69+
70+
if answer.lower() in negative_answers:
71+
create_empty_file()
72+
else:
73+
answers = {}
74+
75+
# Ask the questions
76+
print
77+
for config_value, question in questions.iteritems():
78+
while 1:
79+
print question['question'],
80+
answer = raw_input()
81+
82+
if answer in positive_answers:
83+
answers[config_value] = question['answers'][positive_answers]
84+
break
85+
elif answer in negative_answers:
86+
answers[config_value] = question['answers'][negative_answers]
87+
break
88+
else:
89+
print
90+
print 'I couldn\'t understand the answer you provided, please try again'
91+
92+
print answers
93+
94+
if __name__ == '__main__':
95+
if is_first_run():
96+
run_wizard()

0 commit comments

Comments
 (0)