Package pipe_control :: Module script
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.script

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003-2014 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program 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 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Functions for executing relax scripts.""" 
24   
25  # Python module imports. 
26  from os import F_OK, access 
27   
28  # relax module imports. 
29  import prompt.interpreter 
30  from lib.errors import RelaxError 
31  from lib.io import get_file_path 
32  from status import Status; status = Status() 
33   
34   
35 -def script(file=None, dir=None):
36 """Function for executing a script file. 37 38 @keyword file: The name of the script to execute. 39 @type file: str 40 @keyword dir: The name of the directory in which the script is located. 41 @type dir: str or None 42 """ 43 44 # File argument. 45 if file == None: 46 raise RelaxNoneError('file') 47 elif not isinstance(file, str): 48 raise RelaxStrError('file', file) 49 50 # The full path. 51 file_path = get_file_path(file, dir) 52 53 # Test if the script file exists. 54 if not access(file_path, F_OK): 55 raise RelaxError("The script file '%s' does not exist." % file_path) 56 57 # Turn on the function intro flag. 58 orig_intro_state = status.uf_intro 59 status.uf_intro = True 60 61 # Load the interpreter. 62 interpreter = prompt.interpreter.Interpreter(show_script=False, raise_relax_error=True) 63 interpreter.populate_self() 64 interpreter.on(verbose=False) 65 66 # Execute the script. 67 prompt.interpreter.run_script(local=interpreter._locals, script_file=file_path) 68 69 # Return the function intro flag to the original value. 70 status.uf_intro = orig_intro_state
71