cros_install_debug_syms: switch to outcap
Rather than manage sys.stdout ourselves, use the outcap.OutputCapturer
helper which was designed specifically for this. This avoids direct
monkey patching of sys.stdout which doesn't work well in Python 3 (due
to encoding issues), and makes the code a bit simpler.
The new version also captures stderr, but I think that's what we want
in practice too.
BUG=chromium:997354
TEST=`./run_tests` passes
Change-Id: Id495a7d31a8e5e49a3e2cd8827bd092b0d4b398d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1874457
Reviewed-by: Will Bradley <wbbradley@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_install_debug_syms.py b/scripts/cros_install_debug_syms.py
index 3eb547e..80f8bee 100644
--- a/scripts/cros_install_debug_syms.py
+++ b/scripts/cros_install_debug_syms.py
@@ -20,7 +20,6 @@
import multiprocessing
import os
import pickle
-import sys
import tempfile
from six.moves import urllib
@@ -34,6 +33,7 @@
from chromite.lib import osutils
from chromite.lib import path_util
from chromite.lib import gs
+from chromite.utils import outcap
if cros_build_lib.IsInsideChroot():
# pylint: disable=import-error
@@ -47,31 +47,24 @@
class DebugSymbolsInstaller(object):
- """Container for enviromnent objects, needed to make multiprocessing work.
-
- This also redirects stdout to null when stdout_to_null=True to avoid
- polluting the output with portage QA warnings.
- """
- _old_stdout = None
- _null = None
+ """Container for enviromnent objects, needed to make multiprocessing work."""
def __init__(self, vartree, gs_context, sysroot, stdout_to_null):
self._vartree = vartree
self._gs_context = gs_context
self._sysroot = sysroot
self._stdout_to_null = stdout_to_null
+ self._capturer = outcap.OutputCapturer()
def __enter__(self):
if self._stdout_to_null:
- self._old_stdout = sys.stdout
- self._null = open(os.devnull, 'w')
- sys.stdout = self._null
+ self._capturer.StartCapturing()
+
return self
def __exit__(self, _exc_type, _exc_val, _exc_tb):
if self._stdout_to_null:
- sys.stdout = self._old_stdout
- self._null.close()
+ self._capturer.StopCapturing()
def Install(self, cpv, url):
"""Install the debug symbols for |cpv|.