Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2142)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/outputtee.py

Issue 1839193004: Run auto-formatter (autopep8) on webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2009, Google Inc. All rights reserved. 1 # Copyright (c) 2009, Google Inc. All rights reserved.
2 # Copyright (c) 2009 Apple Inc. All rights reserved. 2 # Copyright (c) 2009 Apple Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 import codecs 30 import codecs
31 import os 31 import os
32 import sys 32 import sys
33 33
34 34
35 # Simple class to split output between multiple destinations 35 # Simple class to split output between multiple destinations
36 class Tee: 36 class Tee:
37
37 def __init__(self, *files): 38 def __init__(self, *files):
38 self.files = files 39 self.files = files
39 40
40 # Callers should pass an already encoded string for writing. 41 # Callers should pass an already encoded string for writing.
41 def write(self, bytes): 42 def write(self, bytes):
42 for file in self.files: 43 for file in self.files:
43 file.write(bytes) 44 file.write(bytes)
44 45
45 46
46 class OutputTee: 47 class OutputTee:
48
47 def __init__(self): 49 def __init__(self):
48 self._original_stdout = None 50 self._original_stdout = None
49 self._original_stderr = None 51 self._original_stderr = None
50 self._files_for_output = [] 52 self._files_for_output = []
51 53
52 def add_log(self, path): 54 def add_log(self, path):
53 log_file = self._open_log_file(path) 55 log_file = self._open_log_file(path)
54 self._files_for_output.append(log_file) 56 self._files_for_output.append(log_file)
55 self._tee_outputs_to_files(self._files_for_output) 57 self._tee_outputs_to_files(self._files_for_output)
56 return log_file 58 return log_file
(...skipping 13 matching lines...) Expand all
70 def _tee_outputs_to_files(self, files): 72 def _tee_outputs_to_files(self, files):
71 if not self._original_stdout: 73 if not self._original_stdout:
72 self._original_stdout = sys.stdout 74 self._original_stdout = sys.stdout
73 self._original_stderr = sys.stderr 75 self._original_stderr = sys.stderr
74 if files and len(files): 76 if files and len(files):
75 sys.stdout = Tee(self._original_stdout, *files) 77 sys.stdout = Tee(self._original_stdout, *files)
76 sys.stderr = Tee(self._original_stderr, *files) 78 sys.stderr = Tee(self._original_stderr, *files)
77 else: 79 else:
78 sys.stdout = self._original_stdout 80 sys.stdout = self._original_stdout
79 sys.stderr = self._original_stderr 81 sys.stderr = self._original_stderr
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698