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
118 0: No compression (no file extension).
119 1: bzip2 compression ('.bz2' file extension).
120 2: gzip compression ('.gz' file extension).
121
122
123 Examples
124 ~~~~~~~~
125
126 The following commands will save the current program state into the file 'save':
127
128 relax> state.save('save', compress_type=0)
129 relax> state.save(file='save', compress_type=0)
130
131
132 The following commands will save the current program state into the bzip2 compressed file
133 'save.bz2':
134
135 relax> state.save('save')
136 relax> state.save(file='save')
137 relax> state.save('save.bz2')
138 relax> state.save(file='save.bz2')
139
140
141 If the file 'save' already exists, the following commands will save the current program
142 state by overwriting the file.
143
144 relax> state.save('save', 1)
145 relax> state.save(file='save', force=1)
146 """
147
148
149 if self.__relax__.interpreter.intro:
150 text = sys.ps3 + "state.save("
151 text = text + "file=" + `file`
152 text = text + ", dir=" + `dir`
153 text = text + ", force=" + `force`
154 text = text + ", compress_type=" + `compress_type` + ")"
155 print text
156
157
158 if type(file) != str:
159 raise RelaxStrError, ('file name', file)
160
161
162 if dir != None and type(dir) != str:
163 raise RelaxNoneStrError, ('directory', dir)
164
165
166 if type(force) != int or (force != 0 and force != 1):
167 raise RelaxBinError, ('force flag', force)
168
169
170 if type(compress_type) != int:
171 raise RelaxIntError, ('compression type', compress_type)
172
173
174 self.__relax__.generic.state.save(file=file, dir=dir, force=force, compress_type=compress_type)
175