1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for reading and writing the relax program state."""
24
25
26 from re import search
27
28
29 from data import Relax_data_store; ds = Relax_data_store()
30 from generic_fns.reset import reset
31 from relax_errors import RelaxError
32 from relax_io import open_read_file, open_write_file
33 from status import Status; status = Status()
34
35
37 """Load the program state from the pickled file.
38
39 @param file: The file object containing the relax state.
40 @type file: file object
41 """
42
43
44 state = load(file)
45
46
47 file.close()
48
49
50 black_list = dir(dict) + ['__weakref__', '__dict__', '__module__', '__reset__', '_back_compat_hook', 'add', 'from_xml', 'is_empty', 'to_xml']
51
52
53 for name in dir(state):
54
55 if name in black_list:
56 continue
57
58
59 obj = getattr(state, name)
60
61
62 setattr(ds, name, obj)
63
64
65 for key in list(state.keys()):
66
67 ds[key] = state[key]
68
69
70 del state
71
72
73 return True
74
75
76 -def load_state(state=None, dir=None, verbosity=1, force=False):
77 """Function for loading a saved program state.
78
79 @keyword state: The saved state file.
80 @type state: str
81 @keyword dir: The path of the state file.
82 @type dir: str
83 @keyword verbosity: The verbosity level.
84 @type verbosity: int
85 @keyword force: If True, the relax data store will be reset prior to state loading.
86 @type force: bool
87 """
88
89
90 file = open_read_file(file_name=state, dir=dir, verbosity=verbosity)
91
92
93 if force:
94 reset()
95
96
97 if not ds.is_empty():
98 raise RelaxError("The relax data store is not empty.")
99
100
101 ds.from_xml(file)
102
103
104 status.observers.pipe_alteration.notify()
105
106
107 status.observers.state_load.notify()
108
109
110 -def save_state(state=None, dir=None, compress_type=1, verbosity=1, force=False):
111 """Function for saving the program state.
112
113 @keyword state: The saved state file.
114 @type state: str
115 @keyword dir: The path of the state file.
116 @type dir: str
117 @keyword verbosity: The verbosity level.
118 @type verbosity: int
119 @keyword force: Boolean argument which if True causes the file to be overwritten if it
120 already exists.
121 @type force: bool
122 @keyword compress_type: The compression type. The integer values correspond to the compression
123 type: 0, no compression; 1, Bzip2 compression; 2, Gzip compression.
124 @type compress_type: int
125 """
126
127
128 file = open_write_file(file_name=state, dir=dir, verbosity=verbosity, force=force, compress_type=compress_type)
129
130
131 ds.to_xml(file)
132
133
134 file.close()
135