From: David Shea dshea@redhat.com
--- dracut/driver_updates.py | 2 +- scripts/merge-pr | 2 +- tests/dd_tests/dd_test.py | 1 - tests/gettext/click.py | 2 +- tests/glade/check_invisible_char.py | 2 +- tests/lib/mkdud.py | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/dracut/driver_updates.py b/dracut/driver_updates.py index f60480e..47c142a 100755 --- a/dracut/driver_updates.py +++ b/dracut/driver_updates.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright (C) 2015 by Red Hat, Inc. All rights reserved. # diff --git a/scripts/merge-pr b/scripts/merge-pr index a13a780..514464b 100755 --- a/scripts/merge-pr +++ b/scripts/merge-pr @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # # merge-pr - Rebase, merge, and close a github pull request # diff --git a/tests/dd_tests/dd_test.py b/tests/dd_tests/dd_test.py index e857db8..de6b229 100644 --- a/tests/dd_tests/dd_test.py +++ b/tests/dd_tests/dd_test.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # unit tests for driver disk utilities (utils/dd)
# Ignore any interruptible calls diff --git a/tests/gettext/click.py b/tests/gettext/click.py index 6c3ce24..22851b7 100755 --- a/tests/gettext/click.py +++ b/tests/gettext/click.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # # Copyright (C) 2015 Red Hat, Inc. # diff --git a/tests/glade/check_invisible_char.py b/tests/glade/check_invisible_char.py index 72d8486..6d43ce1 100755 --- a/tests/glade/check_invisible_char.py +++ b/tests/glade/check_invisible_char.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # # Copyright (C) 2015 Red Hat, Inc. # diff --git a/tests/lib/mkdud.py b/tests/lib/mkdud.py index 39b376d..e5c5e83 100755 --- a/tests/lib/mkdud.py +++ b/tests/lib/mkdud.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # mkdud.py - test helper that makes driverdisk images # # Copyright (c) 2015 Red Hat, Inc.
From: David Shea dshea@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@redhat.com + +import os, contextlib + +@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)
anaconda-patches@lists.fedorahosted.org