[master 2/2] Disable the output from rpmbuild
dashea
installerbot-noreply at redhat.com
Thu Jul 16 19:21:54 UTC 2015
From: David Shea <dshea at redhat.com>
---
tests/dd_tests/dd_test.py | 4 ++-
tests/lib/shutup.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 tests/lib/shutup.py
diff --git a/tests/dd_tests/dd_test.py b/tests/dd_tests/dd_test.py
index de6b229..4d23560 100644
--- a/tests/dd_tests/dd_test.py
+++ b/tests/dd_tests/dd_test.py
@@ -12,6 +12,7 @@
from contextlib import contextmanager
from collections import namedtuple
from rpmfluff import SourceFile, SimpleRpmBuild, expectedArch
+from shutup import shutup
TOP_SRCDIR = os.environ.get("top_builddir", "../..")
UTILDIR = os.path.join(TOP_SRCDIR, "utils/dd")
@@ -55,7 +56,8 @@ def make_rpm(outdir, name='test', version='1.0', release='1', arch=None,
SourceFile(item.srcpath, item.contents),
**item.kwargs)
with in_tempdir("anaconda-test-dd."):
- p.make()
+ with shutup():
+ p.make()
rpmfile = p.get_built_rpm(arch or expectedArch)
outfile = os.path.join(outdir, os.path.basename(rpmfile))
shutil.move(rpmfile, outfile)
diff --git a/tests/lib/shutup.py b/tests/lib/shutup.py
new file mode 100644
index 0000000..811b3e1
--- /dev/null
+++ b/tests/lib/shutup.py
@@ -0,0 +1,69 @@
+#
+# hideoutput.py: context manager for ignoring overly verbose output
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Shea <dshea at redhat.com>
+
+import os, contextlib
+
+ at contextlib.contextmanager
+def shutup():
+ """Run something with stdout and stderr redirected to /dev/null
+
+ The redirections will be process-wide, so this is not recommended
+ for multithreaded applications.
+ """
+
+ # Ignore all the warnings about interruptible calls
+ # pylint: disable=ignorable-system-call, interruptible-system-call
+
+ # Wrap the whole thing a try-finally to ensure errors don't leak file descriptor
+ old_stdout = None
+ old_stderr = None
+ devnull_fd = None
+
+ try:
+ # Save the current file descriptors
+ old_stdout = os.dup(1)
+ old_stderr = os.dup(2)
+
+ # Redirect to /dev/null
+ # Try to undo partial redirects if something goes wrong
+ devnull_fd = os.open(os.devnull, os.O_WRONLY)
+ try:
+ os.dup2(devnull_fd, 1)
+ os.dup2(devnull_fd, 2)
+ except:
+ os.dup2(old_stderr, 2)
+ os.dup2(old_stdout, 1)
+ raise
+
+ # Run the body. Cleanup in finally to ensure stderr is restored before
+ # an exception is raised.
+ try:
+ yield
+ finally:
+ os.dup2(old_stderr, 2)
+ os.dup2(old_stdout, 1)
+
+ finally:
+ if old_stdout is not None:
+ os.close(old_stdout)
+ if old_stderr is not None:
+ os.close(old_stderr)
+ if devnull_fd is not None:
+ os.close(devnull_fd)
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/feeed1dc7f452e68bc25226f9d387093b8c5a668
More information about the anaconda-patches
mailing list