1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
42 self.data = data
43 self.token = token
44 self.stream = stream
45
46
48 """Dummy flush method."""
49
50
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
71 string = string.replace('\n', '\n' + self.token)
72
73
74 self.data.append([string, self.stream])
75