-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
50 lines (42 loc) · 1016 Bytes
/
__init__.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
import sys
import signal
import pickle
try:
assert sys.version_info.major == 3
except AssertionError:
sys.exit('EXIT: i require python3')
# {{{
class ShellState:
def __init__(self,statefile):
self.statefile = statefile
self.state = self.readstate()
sys.setrecursionlimit(3000)
if self.state is None:
self.log = {}
else:
self.log = self.state.log
def readstate(self):
try:
pfile = open(self.statefile,'rb')
state = pickle.load(pfile)
pfile.close()
return state
except FileNotFoundError:
return None
def writestate(self,state):
pfile = open(self.statefile,'wb')
pickle.dump(state,pfile)
pfile.close()
def initialize(self):
self.writestate({})
def exit_handler(self,errormessage=None):
print()
if errormessage:
print(errormessage)
print("saving state...")
self.writestate(self)
print("exiting...")
sys.exit(0)
def signal_handler(self,signal,frame):
self.exit_handler()
# }}}