Package generic_fns :: Module state
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.state

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  from cPickle import dump, load 
24   
25   
26 -class State:
27 - def __init__(self, relax):
28 """Class containing the functions for manipulating the program state.""" 29 30 self.relax = relax
31 32
33 - def load(self, file=None, dir=None, compress_type=1):
34 """Function for loading a saved program state.""" 35 36 # Open the file for reading. 37 file = self.relax.IO.open_read_file(file_name=file, dir=dir, compress_type=compress_type) 38 39 # Unpickle the data class. 40 self.relax.data = load(file) 41 42 # Close the file. 43 file.close()
44 45
46 - def save(self, file=None, dir=None, force=0, compress_type=1):
47 """Function for saving the program state.""" 48 49 # Open the file for writing. 50 file = self.relax.IO.open_write_file(file_name=file, dir=dir, force=force, compress_type=compress_type) 51 52 # Pickle the data class and write it to file 53 dump(self.relax.data, file, 1) 54 55 # Close the file. 56 file.close()
57