Package multi :: Module processor_io
[hide private]
[frames] | no frames]

Source Code for Module multi.processor_io

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2007 Gary S Thompson (https://gna.org/users/varioustoxins)    # 
 4  # Copyright (C) 2012 Edward d'Auvergne                                        # 
 5  #                                                                             # 
 6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 7  #                                                                             # 
 8  # This program is free software: you can redistribute it and/or modify        # 
 9  # it under the terms of the GNU General Public License as published by        # 
10  # the Free Software Foundation, either version 3 of the License, or           # 
11  # (at your option) any later version.                                         # 
12  #                                                                             # 
13  # This program is distributed in the hope that it will be useful,             # 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
16  # GNU General Public License for more details.                                # 
17  #                                                                             # 
18  # You should have received a copy of the GNU General Public License           # 
19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Module docstring. 
24  """Module containing classes for IO stream capture on slave processors.""" 
25   
26   
27 -class Redirect_text(object):
28 """Store the data of the IO streams, prepending a token to each line of written text.""" 29
30 - def __init__(self, data, token='', stream=0):
31 """Set up the text redirection object. 32 33 @param data: The data object to store all IO in. 34 @type data: list of lists 35 @param token: The string to add to the end of all newlines. 36 @type token: str 37 @keyword stream: The type of steam (0 for STDOUT and 1 for STDERR). 38 @type stream: int 39 """ 40 41 # Store the args. 42 self.data = data 43 self.token = token 44 self.stream = stream
45 46
47 - def flush(self):
48 """Dummy flush method."""
49 50
51 - def isatty(self):
52 """Answer that this is not a TTY. 53 54 @return: False, as this is not a TTY. 55 @rtype: bool 56 """ 57 58 return False
59 60
61 - def write(self, string):
62 """Replacement write() method. 63 64 This prepends the token to each line of STDOUT and STDERR and stores the result together with the stream number. 65 66 @param string: The text to write. 67 @type string: str 68 """ 69 70 # Append the token to all newline chars. 71 string = string.replace('\n', '\n' + self.token) 72 73 # Store the text. 74 self.data.append([string, self.stream])
75