-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore_session.py
58 lines (53 loc) · 2.22 KB
/
restore_session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def save_session(self):
"""saves open filenames to a file called session"""
name = open("session", "w")
for buffer in self.buffers:
text = buffer.filename
name.write(buffer.filename + "\n")
name.close()
def open_session(self, ret):
"""opens session from session file"""
if ret:
opensession = open("session", "r")
files_open = []
for line in opensession:
if line != _("* Unnamed *\n"):
files_open.append(line)
buffer = self.new_buffer()
for c in files_open:
n = 0
filename = files_open[n][:-1]
n = n+1
buffer.filename = filename
try:
f = open(buffer.filename, 'r')
buffer = self.buffers[self.current]
buffer.begin_not_undoable_action()
utf8 = unicode(f.read(), 'utf-8')
buffer.set_text(utf8)
buffer.end_not_undoable_action()
f.close()
self.status.set_text(_('File %s open')
% buffer.filename)
except IOError, (errno, strerror):
errortext = _('Unable to open %(filename)s.' % {'filename': buffer.filename})
if errno == 2:
errortext += _(' The file does not exist.')
elif errno == 13:
errortext += _(' You do not have permission to open the file.')
buffer.set_text(_(errortext))
if verbose:
print (_('Unable to open %(filename)s. %(traceback)s'
% {'filename': buffer.filename, 'traceback': traceback.format_exc()}))
self.status.set_text(_('Failed to open %s')
% buffer.filename)
buffer.filename = FILE_UNNAMED
except:
buffer.set_text(_('Unable to open %s\n'
% buffer.filename))
if verbose:
print (_('Unable to open %(filename)s. %(traceback)s'
% {'filename': buffer.filename,
'traceback': traceback.format_exc()}))
buffer.filename = FILE_UNNAMED
# EOF