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.                                     # 
 7  #                                                                             # 
 8  # relax 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 2 of the License, or           # 
11  # (at your option) any later version.                                         # 
12  #                                                                             # 
13  # relax 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 relax; if not, write to the Free Software                        # 
20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
21  #                                                                             # 
22  ############################################################################### 
23   
24  # Module docstring. 
25  """Module containing classes for IO stream capture on slave processors.""" 
26   
27   
28 -class Redirect_text(object):
29 """Store the data of the IO streams, prepending a token to each line of written text.""" 30
31 - def __init__(self, data, token='', stream=0):
32 """Set up the text redirection object. 33 34 @param data: The data object to store all IO in. 35 @type data: list of lists 36 @param token: The string to add to the end of all newlines. 37 @type token: str 38 @keyword stream: The type of steam (0 for STDOUT and 1 for STDERR). 39 @type stream: int 40 """ 41 42 # Store the args. 43 self.data = data 44 self.token = token 45 self.stream = stream
46 47
48 - def flush(self):
49 """Dummy flush method."""
50 51
52 - def isatty(self):
53 """Answer that this is not a TTY. 54 55 @return: False, as this is not a TTY. 56 @rtype: bool 57 """ 58 59 return False
60 61
62 - def write(self, string):
63 """Replacement write() method. 64 65 This prepends the token to each line of STDOUT and STDERR and stores the result together with the stream number. 66 67 @param string: The text to write. 68 @type string: str 69 """ 70 71 # Append the token to all newline chars. 72 string = string.replace('\n', '\n' + self.token) 73 74 # Store the text. 75 self.data.append([string, self.stream])
76