mailr4459 - in /branches/N_state_model: ./ prompt/interpreter.py relax test_suite/system_tests/model_free.py


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

Header


Content

Posted by edward on January 07, 2008 - 18:44:
Author: bugman
Date: Mon Jan  7 18:44:57 2008
New Revision: 4459

URL: http://svn.gna.org/viewcvs/relax?rev=4459&view=rev
Log:
Merged revisions 4452-4458 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3

........
  r4452 | bugman | 2008-01-07 18:19:07 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Fixed the running of the script for the model-free m4 model creating system 
test.
........
  r4453 | bugman | 2008-01-07 18:28:57 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Completely changed how the relax program introduction is handled.
........
  r4454 | bugman | 2008-01-07 18:35:50 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Added the ability to turn off the printing out of the script prior to its 
execution.
........
  r4455 | bugman | 2008-01-07 18:36:51 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Turned off the printing of the script prior to its execution in the system 
tests.
........
  r4456 | bugman | 2008-01-07 18:42:18 +0100 (Mon, 07 Jan 2008) | 5 lines
  
  Shifted the quit option from run() to __init__().
  
  This will remove the need for all system tests using a script to ask the 
interpreter to not exit.
........
  r4457 | bugman | 2008-01-07 18:42:52 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Made the 'intro_string', 'quit', and 'show_script' variables private.
........
  r4458 | bugman | 2008-01-07 18:43:35 +0100 (Mon, 07 Jan 2008) | 3 lines
  
  Passed the quit flag into the prompt mode of operation.
........

Modified:
    branches/N_state_model/   (props changed)
    branches/N_state_model/prompt/interpreter.py
    branches/N_state_model/relax
    branches/N_state_model/test_suite/system_tests/model_free.py

Propchange: branches/N_state_model/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: branches/N_state_model/prompt/interpreter.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/prompt/interpreter.py?rev=4459&r1=4458&r2=4459&view=diff
==============================================================================
--- branches/N_state_model/prompt/interpreter.py (original)
+++ branches/N_state_model/prompt/interpreter.py Mon Jan  7 18:44:57 2008
@@ -79,12 +79,27 @@
 
 
 class Interpreter:
-    def __init__(self, relax):
-        """The interpreter class."""
-
-        # Place the program class structure under self.relax
+    def __init__(self, relax, intro_string=None, show_script=True, 
quit=True):
+        """The interpreter class.
+
+        @param relax:           The relax instance.
+        @type relax:            instance
+        @param intro_string:    The string to print at the start of 
execution.
+        @type intro_string:     str
+        @param show_script:     If true, the relax will print the script 
contents prior to executing
+                                the script.
+        @type show_script:      bool
+        @param quit:            If true, the default, then relax will exit 
after running the run()
+                                method.
+        @type quit:             bool
+        """
+
+        # Place the arguments in the class namespace.
         self.relax = relax
-
+        self.__intro_string = intro_string
+        self.__show_script = show_script
+        self.__quit_flag = quit
+        
         # The prompts.
         sys.ps1 = 'relax> '
         sys.ps2 = 'relax| '
@@ -139,17 +154,16 @@
         self._Vmd = Vmd(relax)
 
 
-    def run(self, script_file=None, quit=True):
+    def run(self, script_file=None):
         """Run the python interpreter.
 
         The namespace of this function is the namespace seen inside the 
interpreter.  All user
         accessible functions, classes, etc, should be placed in this 
namespace.
 
-        @param script_file: The script file to be executed.  For the 
interpreter mode, this should
-                            be left as None.
+
+        @param script_file: The script file to be executed.  For the 
interpreter mode, this
+                            should be left as None.
         @type script_file:  None or str
-        @param quit:        If true, the default, then relax will exit after 
running this function.
-        @type quit:         bool
         """
 
         # Python modules.
@@ -230,7 +244,7 @@
             self.intro = 1
 
             # Run the script.
-            run_script(intro=self.relax.intro_string, local=self.local, 
script_file=script_file, quit=quit)
+            run_script(intro=self.__intro_string, local=self.local, 
script_file=script_file, quit=self.__quit_flag, 
show_script=self.__show_script)
 
         # Test for the dummy mode for generating documentation (then exit).
         elif hasattr(self.relax, 'dummy_mode'):
@@ -240,7 +254,7 @@
 
         # Go to the prompt.
         else:
-            prompt(intro=self.relax.intro_string, local=self.local)
+            prompt(intro=self.__intro_string, local=self.local, 
quit=self.__quit_flag)
 
 
     def _off(self):
@@ -326,7 +340,7 @@
             more = 0
 
 
-def interact_script(self, intro, local, script_file, quit):
+def interact_script(self, intro, local, script_file, quit, show_script=True):
     """Replacement function for 'code.InteractiveConsole.interact'.
 
     This will execute the script file.
@@ -340,20 +354,21 @@
     local['self'].intro = 1
 
     # Print the script.
-    try:
-        file = open(script_file, 'r')
-    except IOError, warning:
+    if show_script:
         try:
-            raise RelaxError, "The script file '" + script_file + "' does 
not exist."
-        except AllRelaxErrors, instance:
-            sys.stdout.write(instance.__str__())
-            sys.stdout.write("\n")
-            return
-    sys.stdout.write("script = " + `script_file` + "\n")
-    
sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
-    sys.stdout.write(file.read())
-    
sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
-    file.close()
+            file = open(script_file, 'r')
+        except IOError, warning:
+            try:
+                raise RelaxError, "The script file '" + script_file + "' 
does not exist."
+            except AllRelaxErrors, instance:
+                sys.stdout.write(instance.__str__())
+                sys.stdout.write("\n")
+                return
+        sys.stdout.write("script = " + `script_file` + "\n")
+        
sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
+        sys.stdout.write(file.read())
+        
sys.stdout.write("----------------------------------------------------------------------------------------------------\n")
+        file.close()
 
     # Execute the script.
     try:
@@ -393,7 +408,7 @@
     console.interact(intro, local)
 
 
-def run_script(intro=None, local=None, script_file=None, quit=1):
+def run_script(intro=None, local=None, script_file=None, quit=1, 
show_script=True):
     """Python interpreter emulation.
 
     This function replaces 'code.interact'.
@@ -405,7 +420,7 @@
 
     # The console.
     console = InteractiveConsole(local)
-    console.interact(intro, local, script_file, quit)
+    console.interact(intro, local, script_file, quit, 
show_script=show_script)
 
 
 def runcode(self, code):

Modified: branches/N_state_model/relax
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/relax?rev=4459&r1=4458&r2=4459&view=diff
==============================================================================
--- branches/N_state_model/relax (original)
+++ branches/N_state_model/relax Mon Jan  7 18:44:57 2008
@@ -139,13 +139,13 @@
         elif tee_file and mode != 'thread':
             tee(tee_file)
 
+        # Create a string to pass to the interpreter to print.
+        intro_string = self.get_intro_string()
+
         # Run the interpreter for the prompt or script modes.
         if mode == 'prompt' or mode == 'script':
-            # Create a string to pass to the interpreter to print.
-            self.set_intro_string()
-
             # Run the interpreter.
-            self.interpreter = interpreter.Interpreter(self)
+            self.interpreter = interpreter.Interpreter(self, intro_string)
             self.interpreter.run(self.script_file)
 
         # Threading mode.
@@ -167,11 +167,8 @@
 
         # Execute the relax test suite
         elif mode == 'test suite':
-            # Create a string to pass to the interpreter to print.
-            self.set_intro_string()
-
             # Load the interpreter and turn intros on.
-            self.interpreter = interpreter.Interpreter(self)
+            self.interpreter = interpreter.Interpreter(self, 
show_script=False, quit=False)
             self.interpreter._on()
 
             # Run the tests.
@@ -180,11 +177,8 @@
 
         # Execute the relax system tests.
         elif mode == 'system tests':
-            # Create a string to pass to the interpreter to print.
-            self.set_intro_string()
-
             # Load the interpreter and turn intros on.
-            self.interpreter = interpreter.Interpreter(self)
+            self.interpreter = interpreter.Interpreter(self, 
show_script=False, quit=False)
             self.interpreter._on()
 
             # Run the tests.
@@ -193,9 +187,6 @@
 
         # Execute the relax unit tests.
         elif mode == 'unit tests':
-            # Create a string to pass to the interpreter to print.
-            self.set_intro_string()
-
             # Run the tests.
             runner = Test_suite_runner(self)
             runner.run_unit_tests()
@@ -366,14 +357,12 @@
         return mode, log_file, tee_file
 
 
-    def licence(self):
-        """Function for displaying the licence."""
-
-        help(gpl)
-
-
-    def set_intro_string(self):
-        """Create the program introduction."""
+    def get_intro_string(self):
+        """Create the program introduction.
+
+        @return:        The program introduction string.
+        @type return:   str
+        """
 
         # The width of the printout.
         if self.platform == 'Windows' or self.platform == 'Microsoft':
@@ -382,36 +371,45 @@
             width = 100
 
         # Some new lines.
-        self.intro_string = '\n\n\n'
+        intro_string = '\n\n\n'
 
         # Program name and version.
         string = "relax " + self.version
-        self.intro_string = self.intro_string + self.spacing(string, width) 
+ '\n\n'
+        intro_string = intro_string + self.spacing(string, width) + '\n\n'
 
         # Program description.
         string = "Protein dynamics by NMR relaxation data analysis"
-        self.intro_string = self.intro_string + self.spacing(string, width) 
+ '\n\n'
+        intro_string = intro_string + self.spacing(string, width) + '\n\n'
 
         # Copyright printout.
         string = "Copyright (C) 2001-2006 Edward d'Auvergne"
-        self.intro_string = self.intro_string + self.spacing(string, width) 
+ '\n'
+        intro_string = intro_string + self.spacing(string, width) + '\n'
         string = "Copyright (C) 2006-2008 the relax development team"
-        self.intro_string = self.intro_string + self.spacing(string, width) 
+ '\n\n'
+        intro_string = intro_string + self.spacing(string, width) + '\n\n'
 
         # Program licence and help (80 characters wide).
         if width == 80:
-            self.intro_string = self.intro_string + "This is free software 
which you are welcome to modify and redistribute under\n"
-            self.intro_string = self.intro_string + "the conditions of the 
GNU General Public License (GPL).  This program,\n"
-            self.intro_string = self.intro_string + "including all modules, 
is licensed under the GPL and comes with absolutely no\n"
-            self.intro_string = self.intro_string + "warranty.  For details 
type 'GPL'.  Assistance in using this program can be\n"
-            self.intro_string = self.intro_string + "accessed by typing 
'help'.\n"
+            intro_string = intro_string + "This is free software which you 
are welcome to modify and redistribute under\n"
+            intro_string = intro_string + "the conditions of the GNU General 
Public License (GPL).  This program,\n"
+            intro_string = intro_string + "including all modules, is 
licensed under the GPL and comes with absolutely no\n"
+            intro_string = intro_string + "warranty.  For details type 
'GPL'.  Assistance in using this program can be\n"
+            intro_string = intro_string + "accessed by typing 'help'.\n"
 
         # Program licence and help (100 characters wide).
         else:
-            self.intro_string = self.intro_string + "This is free software 
which you are welcome to modify and redistribute under the conditions of 
the\n"
-            self.intro_string = self.intro_string + "GNU General Public 
License (GPL).  This program, including all modules, is licensed under the 
GPL\n"
-            self.intro_string = self.intro_string + "and comes with 
absolutely no warranty.  For details type 'GPL'.  Assistance in using this 
program\n"
-            self.intro_string = self.intro_string + "can be accessed by 
typing 'help'.\n"
+            intro_string = intro_string + "This is free software which you 
are welcome to modify and redistribute under the conditions of the\n"
+            intro_string = intro_string + "GNU General Public License (GPL). 
 This program, including all modules, is licensed under the GPL\n"
+            intro_string = intro_string + "and comes with absolutely no 
warranty.  For details type 'GPL'.  Assistance in using this program\n"
+            intro_string = intro_string + "can be accessed by typing 
'help'.\n"
+
+        # Return the string.
+        return intro_string
+
+
+    def licence(self):
+        """Function for displaying the licence."""
+
+        help(gpl)
 
 
     def spacing(self, string, width=100):

Modified: branches/N_state_model/test_suite/system_tests/model_free.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/system_tests/model_free.py?rev=4459&r1=4458&r2=4459&view=diff
==============================================================================
--- branches/N_state_model/test_suite/system_tests/model_free.py (original)
+++ branches/N_state_model/test_suite/system_tests/model_free.py Mon Jan  7 
18:44:57 2008
@@ -82,11 +82,8 @@
     def test_create_m4(self):
         """Creating model m4 with parameters {S2, te, Rex} using 
model_free.create_model()."""
 
-        # Place the script file name into self.relax.script_file.
-        self.relax.script_file = 
'test_suite/system_tests/scripts/create_m4.py'
-
-        # Execute relax in script mode.
-        self.relax.interpreter.run(quit=False)
+        # Execute the script.
+        
self.relax.interpreter.run(script_file='test_suite/system_tests/scripts/create_m4.py')
 
         # Alias the current data pipe.
         cdp = relax_data_store[relax_data_store.current_pipe]




Related Messages


Powered by MHonArc, Updated Mon Jan 07 19:00:21 2008