Issue #4625: If IDLE cannot write to its recent file or breakpoint

files, display a message popup and continue rather than crash.
(original patch by Roger Serwy)
This commit is contained in:
Ned Deily 2011-12-14 14:57:43 -08:00
parent 27b154ea57
commit 40ad04171d
2 changed files with 27 additions and 14 deletions

View File

@ -796,11 +796,16 @@ class EditorWindow(object):
rf_list = [path for path in rf_list if path not in bad_paths] rf_list = [path for path in rf_list if path not in bad_paths]
ulchars = "1234567890ABCDEFGHIJK" ulchars = "1234567890ABCDEFGHIJK"
rf_list = rf_list[0:len(ulchars)] rf_list = rf_list[0:len(ulchars)]
rf_file = open(self.recent_files_path, 'w')
try: try:
rf_file.writelines(rf_list) with open(self.recent_files_path, 'w') as rf_file:
finally: rf_file.writelines(rf_list)
rf_file.close() except IOError as err:
if not getattr(self.root, "recentfilelist_error_displayed", False):
self.root.recentfilelist_error_displayed = True
tkMessageBox.showerror(title='IDLE Error',
message='Unable to update Recent Files list:\n%s'
% str(err),
parent=self.text)
# for each edit window instance, construct the recent files menu # for each edit window instance, construct the recent files menu
for instance in self.top.instance_dict.keys(): for instance in self.top.instance_dict.keys():
menu = instance.recent_files_menu menu = instance.recent_files_menu

View File

@ -207,18 +207,26 @@ class PyShellEditorWindow(EditorWindow):
breaks = self.breakpoints breaks = self.breakpoints
filename = self.io.filename filename = self.io.filename
try: try:
lines = open(self.breakpointPath,"r").readlines() with open(self.breakpointPath,"r") as old_file:
lines = old_file.readlines()
except IOError: except IOError:
lines = [] lines = []
new_file = open(self.breakpointPath,"w") try:
for line in lines: with open(self.breakpointPath,"w") as new_file:
if not line.startswith(filename + '='): for line in lines:
new_file.write(line) if not line.startswith(filename + '='):
self.update_breakpoints() new_file.write(line)
breaks = self.breakpoints self.update_breakpoints()
if breaks: breaks = self.breakpoints
new_file.write(filename + '=' + str(breaks) + '\n') if breaks:
new_file.close() new_file.write(filename + '=' + str(breaks) + '\n')
except IOError as err:
if not getattr(self.root, "breakpoint_error_displayed", False):
self.root.breakpoint_error_displayed = True
tkMessageBox.showerror(title='IDLE Error',
message='Unable to update breakpoint list:\n%s'
% str(err),
parent=self.text)
def restore_file_breaks(self): def restore_file_breaks(self):
self.text.update() # this enables setting "BREAK" tags to be visible self.text.update() # this enables setting "BREAK" tags to be visible