|
@@ -73,15 +73,13 @@ class Kaylee:
|
73
|
73
|
|
74
|
74
|
def create_strings_file(self):
|
75
|
75
|
# Open the strings file
|
76
|
|
- strings = open(self.config.strings_file, "w")
|
77
|
|
- # Add command words to the corpus
|
78
|
|
- for voice_cmd in sorted(self.commands.keys()):
|
79
|
|
- strings.write(voice_cmd.strip().replace('%d', '') + "\n")
|
80
|
|
- # Add number words to the corpus
|
81
|
|
- for word in self.number_parser.number_words:
|
82
|
|
- strings.write(word + "\n")
|
83
|
|
- # Close the strings file
|
84
|
|
- strings.close()
|
|
76
|
+ with open(self.config.strings_file, 'w') as strings:
|
|
77
|
+ # Add command words to the corpus
|
|
78
|
+ for voice_cmd in sorted(self.commands.keys()):
|
|
79
|
+ strings.write(voice_cmd.strip().replace('%d', '') + "\n")
|
|
80
|
+ # Add number words to the corpus
|
|
81
|
+ for word in self.number_parser.number_words:
|
|
82
|
+ strings.write(word + "\n")
|
85
|
83
|
|
86
|
84
|
def log_history(self, text):
|
87
|
85
|
if self.options['history']:
|
|
@@ -91,11 +89,9 @@ class Kaylee:
|
91
|
89
|
self.history.pop(0)
|
92
|
90
|
|
93
|
91
|
# Open and truncate the history file
|
94
|
|
- hfile = open(self.config.history_file, "w")
|
95
|
|
- for line in self.history:
|
96
|
|
- hfile.write(line + "\n")
|
97
|
|
- # Close the file
|
98
|
|
- hfile.close()
|
|
92
|
+ with open(self.config.history_file, 'w') as hfile:
|
|
93
|
+ for line in self.history:
|
|
94
|
+ hfile.write(line + '\n')
|
99
|
95
|
|
100
|
96
|
def run_command(self, cmd):
|
101
|
97
|
"""Print the command, then run it"""
|