mailr3795 - /1.3/prompt/state.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on November 22, 2007 - 10:36:
Author: bugman
Date: Thu Nov 22 10:36:30 2007
New Revision: 3795

URL: http://svn.gna.org/viewcvs/relax?rev=3795&view=rev
Log:
Modified both state.load() and state.save() to accept file descriptor objects.


Modified:
    1.3/prompt/state.py

Modified: 1.3/prompt/state.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/state.py?rev=3795&r1=3794&r2=3795&view=diff
==============================================================================
--- 1.3/prompt/state.py (original)
+++ 1.3/prompt/state.py Thu Nov 22 10:36:30 2007
@@ -25,7 +25,7 @@
 
 # relax module imports.
 import help
-from relax_errors import RelaxBinError, RelaxIntError, RelaxNoneStrError, 
RelaxStrError
+from relax_errors import RelaxBinError, RelaxIntError, RelaxNoneStrError, 
RelaxStrError, RelaxStrFileError
 from generic_fns.state import load_state, save_state
 
 
@@ -42,13 +42,14 @@
         self.__relax__ = relax
 
 
-    def load(self, file=None, dir=None):
+    def load(self, state=None, dir=None):
         """Function for loading a saved program state.
 
         Keyword Arguments
         ~~~~~~~~~~~~~~~~~
 
-        file:  The file name, which must be a string, of a saved program 
state.
+        state:  The file name, which can be a string or a file descriptor 
object, of a saved program
+                state.
 
         dir:  Directory which the file is found in.
 
@@ -59,7 +60,8 @@
         This function is able to handle uncompressed, bzip2 compressed 
files, or gzip compressed
         files automatically.  The full file name including extension can be 
supplied, however, if
         the file cannot be found, this function will search for the file 
name with '.bz2' appended
-        followed by the file name with '.gz' appended.
+        followed by the file name with '.gz' appended.  For more advanced 
users, file descriptor
+        objects are also supported.
 
 
         Examples
@@ -68,43 +70,44 @@
         The following commands will load the state saved in the file 'save'.
 
         relax> state.load('save')
-        relax> state.load(file='save')
+        relax> state.load(state='save')
 
 
         The following commands will load the state saved in the bzip2 
compressed file 'save.bz2'.
 
         relax> state.load('save')
-        relax> state.load(file='save')
+        relax> state.load(state='save')
         relax> state.load('save.bz2')
-        relax> state.load(file='save.bz2')
+        relax> state.load(state='save.bz2')
         """
 
         # Function intro text.
         if self.__relax__.interpreter.intro:
             text = sys.ps3 + "state.load("
-            text = text + "file=" + `file`
+            text = text + "state=" + `state`
             text = text + ", dir=" + `dir` + ")"
             print text
 
         # File name.
-        if type(file) != str:
-            raise RelaxStrError, ('file name', file)
+        if type(state) != str and type(state) != file:
+            raise RelaxStrFileError, ('file name', state)
 
         # Directory.
         if dir != None and type(dir) != str:
             raise RelaxNoneStrError, ('directory', dir)
 
         # Execute the functional code.
-        load_state(file=file, dir_name=dir)
+        load_state(state=state, dir_name=dir)
 
 
-    def save(self, file=None, dir=None, force=0, compress_type=1):
+    def save(self, state=None, dir=None, force=0, compress_type=1):
         """Function for saving the program state.
 
         Keyword Arguments
         ~~~~~~~~~~~~~~~~~
 
-        file:  The file name, which must be a string, to save the current 
program state in.
+        state:  The file name, which can be a string or a file descriptor 
object, to save the
+                current program state in.
 
         dir:  The directory to place the file in.
 
@@ -130,37 +133,37 @@
         The following commands will save the current program state into the 
file 'save':
 
         relax> state.save('save', compress_type=0)
-        relax> state.save(file='save', compress_type=0)
+        relax> state.save(state='save', compress_type=0)
 
 
         The following commands will save the current program state into the 
bzip2 compressed file
         'save.bz2':
 
         relax> state.save('save')
-        relax> state.save(file='save')
+        relax> state.save(state='save')
         relax> state.save('save.bz2')
-        relax> state.save(file='save.bz2')
+        relax> state.save(state='save.bz2')
 
 
         If the file 'save' already exists, the following commands will save 
the current program
         state by overwriting the file.
 
         relax> state.save('save', 1)
-        relax> state.save(file='save', force=1)
+        relax> state.save(state='save', force=1)
         """
 
         # Function intro text.
         if self.__relax__.interpreter.intro:
             text = sys.ps3 + "state.save("
-            text = text + "file=" + `file`
+            text = text + "state=" + `state`
             text = text + ", dir=" + `dir`
             text = text + ", force=" + `force`
             text = text + ", compress_type=" + `compress_type` + ")"
             print text
 
         # File name.
-        if type(file) != str:
-            raise RelaxStrError, ('file name', file)
+        if type(state) != str and type(state) != file:
+            raise RelaxStrFileError, ('file name', state)
 
         # Directory.
         if dir != None and type(dir) != str:
@@ -175,4 +178,4 @@
             raise RelaxIntError, ('compression type', compress_type)
 
         # Execute the functional code.
-        save_state(file=file, dir=dir, force=force, 
compress_type=compress_type)
+        save_state(state=state, dir=dir, force=force, 
compress_type=compress_type)




Related Messages


Powered by MHonArc, Updated Thu Nov 22 10:40:10 2007