[master 2/9] Remove explicit uses of /dev/null
dashea
installerbot-noreply at redhat.com
Thu Jun 18 21:03:48 UTC 2015
From: David Shea <dshea at redhat.com>
The subprocess module in python3 adds a special DEVNULL file, which
simplifies things a little for us.
---
anaconda | 5 ++---
dracut/driver-updates | 17 ++++++++---------
scripts/merge-pr | 4 +---
tests/gui/outside/__init__.py | 3 +--
tests/gui/outside/test_reclaim.py | 12 ++++++------
5 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/anaconda b/anaconda
index 9f5447a..efc9c1c 100755
--- a/anaconda
+++ b/anaconda
@@ -119,14 +119,13 @@ def startSpiceVDAgent():
log.info("Started spice-vdagent.")
def startX11():
- # Ignore stdout/stderr, since everything is logged to /tmp/X.log anyway
- xfd = open("/dev/null", "wb")
+ import subprocess
# Start Xorg and wait for it become ready
iutil.startX(["Xorg", "-br", "-logfile", "/tmp/X.log",
":%s" % constants.X_DISPLAY_NUMBER, "vt6", "-s", "1440", "-ac",
"-nolisten", "tcp", "-dpi", "96",
- "-noreset"], output_redirect=xfd)
+ "-noreset"], output_redirect=subprocess.DEVNULL)
# function to handle X startup special issues for anaconda
def doStartupX11Actions():
diff --git a/dracut/driver-updates b/dracut/driver-updates
index b5d8ddb..bdcfa0f 100755
--- a/dracut/driver-updates
+++ b/dracut/driver-updates
@@ -64,15 +64,14 @@ def run_cmd(cmd):
:raises: OSError if the cmd doesn't exist, RunCmdError if the rc != 0
"""
try:
- with open("/dev/null", "w") as fd_null:
- log.debug(" ".join(cmd))
- proc = subprocess.Popen(cmd, universal_newlines=True,
- stdout=subprocess.PIPE,
- stderr=fd_null)
- out = proc.communicate()[0]
- if out:
- for line in out.splitlines():
- log.debug(line)
+ log.debug(" ".join(cmd))
+ proc = subprocess.Popen(cmd, universal_newlines=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL)
+ out = proc.communicate()[0]
+ if out:
+ for line in out.splitlines():
+ log.debug(line)
except OSError as e:
log.error("Error running %s: %s", cmd[0], e.strerror)
raise
diff --git a/scripts/merge-pr b/scripts/merge-pr
index c951aea..a13a780 100755
--- a/scripts/merge-pr
+++ b/scripts/merge-pr
@@ -59,8 +59,6 @@ from tempfile import NamedTemporaryFile
import requests
import six
-DEVNULL = open(os.devnull, 'w')
-
def talk_to_github(request):
# Send a requests.Request to github, handle 2-factor auth
request.headers.update({'User-Agent': 'merge-pr'})
@@ -183,7 +181,7 @@ def main():
# Try checking out the base of the PR. If it isn't available, do a fetch of
# the base repo and try again.
try:
- subprocess.check_call(['git', 'checkout', '-q', pr['base']['sha']], stderr=DEVNULL)
+ subprocess.check_call(['git', 'checkout', '-q', pr['base']['sha']], stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
try:
subprocess.check_call(['git', 'fetch', '-q', pr['base']['repo']['clone_url'], pr['base']['sha']])
diff --git a/tests/gui/outside/__init__.py b/tests/gui/outside/__init__.py
index e37ecdd..0ab332b 100644
--- a/tests/gui/outside/__init__.py
+++ b/tests/gui/outside/__init__.py
@@ -27,7 +27,6 @@
import shutil
import subprocess
import tempfile
-import errno
class Creator(object):
"""A Creator subclass defines all the parameters for making a VM to run a
@@ -65,7 +64,7 @@ def __init__(self):
self._reqMemory = 1536
def _call(self, args):
- subprocess.call(args, stdout=open("/dev/null", "w"), stderr=open("/dev/null", "w"))
+ subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def archive(self):
"""Copy all log files and other test results to a subdirectory of the
diff --git a/tests/gui/outside/test_reclaim.py b/tests/gui/outside/test_reclaim.py
index c4f4dbf..8f7b7d0 100644
--- a/tests/gui/outside/test_reclaim.py
+++ b/tests/gui/outside/test_reclaim.py
@@ -46,14 +46,14 @@ def makeDrives(self):
# force anaconda to display the reclaim dialog.
for (drive, size) in self.drives:
subprocess.call(["/sbin/parted", "-s", self._drivePaths[drive], "mklabel", "msdos"],
- stdout=open("/dev/null", "w"),
- stderr=open("/dev/null", "w"))
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
subprocess.call(["/sbin/parted", "-s", self._drivePaths[drive], "mkpart", "p", "ext2", "0", str(size)],
- stdout=open("/dev/null", "w"),
- stderr=open("/dev/null", "w"))
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
subprocess.call(["/sbin/mkfs.ext4", "-F", self._drivePaths[drive]],
- stdout=open("/dev/null", "w"),
- stderr=open("/dev/null", "w"))
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
class BasicReclaimLiveCD_OutsideTest(OutsideMixin, unittest.TestCase):
creatorClass = BasicReclaimLiveCDCreator
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/fccbc308e09a02f61e0f803b4630844910bb29e9
More information about the anaconda-patches
mailing list