1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import sys
24
25 import help
26
27
30
31 self.__relax_help__ = \
32 """Class for saving or loading the program state."""
33
34
35 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help
36
37
38 self.__relax__ = relax
39
40
41 - def load(self, file=None, dir=None):
42 """Function for loading a saved program state.
43
44 Keyword Arguments
45 ~~~~~~~~~~~~~~~~~
46
47 file: The file name, which must be a string, of a saved program state.
48
49 dir: Directory which the file is found in.
50
51
52 Description
53 ~~~~~~~~~~~
54
55 This function is able to handle uncompressed, bzip2 compressed files, or gzip compressed
56 files automatically. The full file name including extension can be supplied, however, if
57 the file cannot be found, this function will search for the file name with '.bz2' appended
58 followed by the file name with '.gz' appended.
59
60
61 Examples
62 ~~~~~~~~
63
64 The following commands will load the state saved in the file 'save'.
65
66 relax> state.load('save')
67 relax> state.load(file='save')
68
69
70 The following commands will load the state saved in the bzip2 compressed file 'save.bz2'.
71
72 relax> state.load('save')
73 relax> state.load(file='save')
74 relax> state.load('save.bz2')
75 relax> state.load(file='save.bz2')
76 """
77
78
79 if self.__relax__.interpreter.intro:
80 text = sys.ps3 + "state.load("
81 text = text + "file=" + `file`
82 text = text + ", dir=" + `dir` + ")"
83 print text
84
85
86 if type(file) != str:
87 raise RelaxStrError, ('file name', file)
88
89
90 if dir != None and type(dir) != str:
91 raise RelaxNoneStrError, ('directory', dir)
92
93
94 self.__relax__.generic.state.load(file=file, dir=dir)
95
96
97 - def save(self, file=None, dir=None, force=0, compress_type=1):
98 """Function for saving the program state.
99
100 Keyword Arguments
101 ~~~~~~~~~~~~~~~~~
102
103 file: The file name, which must be a string, to save the current program state in.
104
105 dir: The directory to place the file in.
106
107 force: A flag which if set to 1 will cause the file to be overwritten.
108
109
110 Description
111 ~~~~~~~~~~~
112
113 The default behaviour of this function is to compress the file using bzip2 compression. If
114 the extension '.bz2' is not included in the file name, it will be added. The compression
115 can, however, be changed to either no compression or gzip compression. This is controlled
116 by the compress_type argument which can be set to:
117 0 - No compression (no file extension).
118 1 - bzip2 compression ('.bz2' file extension).
119 2 - gzip compression ('.gz' file extension).
120
121
122 Examples
123 ~~~~~~~~
124
125 The following commands will save the current program state into the file 'save':
126
127 relax> state.save('save', compress_type=0)
128 relax> state.save(file='save', compress_type=0)
129
130
131 The following commands will save the current program state into the bzip2 compressed file
132 'save.bz2':
133
134 relax> state.save('save')
135 relax> state.save(file='save')
136 relax> state.save('save.bz2')
137 relax> state.save(file='save.bz2')
138
139
140 If the file 'save' already exists, the following commands will save the current program
141 state by overwriting the file.
142
143 relax> state.save('save', 1)
144 relax> state.save(file='save', force=1)
145 """
146
147
148 if self.__relax__.interpreter.intro:
149 text = sys.ps3 + "state.save("
150 text = text + "file=" + `file`
151 text = text + ", dir=" + `dir`
152 text = text + ", force=" + `force`
153 text = text + ", compress_type=" + `compress_type` + ")"
154 print text
155
156
157 if type(file) != str:
158 raise RelaxStrError, ('file name', file)
159
160
161 if dir != None and type(dir) != str:
162 raise RelaxNoneStrError, ('directory', dir)
163
164
165 if type(force) != int or (force != 0 and force != 1):
166 raise RelaxBinError, ('force flag', force)
167
168
169 if type(compress_type) != int:
170 raise RelaxIntError, ('compression type', compress_type)
171
172
173 self.__relax__.generic.state.save(file=file, dir=dir, force=force, compress_type=compress_type)
174