From a0d0f859c7d1613f62a5179b2886cd40701231ff Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Sun, 9 Mar 2014 01:18:29 +0000 Subject: [PATCH] resolve another use of commands module for python3 compat 03255001d6 moved commands module to src/tito/compat.py to handle differences between python2 and python3, but missed a bit that did not show up in unit or functional tests. Fix those occurences and add unit test to detect the regression. --- src/tito/builder/main.py | 4 ++-- src/tito/compat.py | 5 +---- test/unit/pep8-tests.py | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 315999b..5172876 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -144,7 +144,7 @@ class BuilderBase(object): """ if not self.no_cleanup: debug("Cleaning up [%s]" % self.rpmbuild_dir) - commands.getoutput("rm -rf %s" % self.rpmbuild_dir) + getoutput("rm -rf %s" % self.rpmbuild_dir) else: print("WARNING: Leaving rpmbuild files in: %s" % self.rpmbuild_dir) @@ -165,7 +165,7 @@ class BuilderBase(object): """ Create the build directories. Can safely be called multiple times. """ - commands.getoutput("mkdir -p %s %s %s %s" % ( + getoutput("mkdir -p %s %s %s %s" % ( self.rpmbuild_basedir, self.rpmbuild_dir, self.rpmbuild_sourcedir, self.rpmbuild_builddir)) self._check_build_dirs_access() diff --git a/src/tito/compat.py b/src/tito/compat.py index ca8a15c..90fc1ba 100644 --- a/src/tito/compat.py +++ b/src/tito/compat.py @@ -43,7 +43,4 @@ def getoutput(cmd): Returns output of executing cmd in a shell. Supports Python 2.4 and 3.x. """ - if PY2: - return commands.getoutput(cmd) - else: - return subprocess.getoutput(cmd) + return getstatusoutput(cmd)[1] diff --git a/test/unit/pep8-tests.py b/test/unit/pep8-tests.py index f3671a0..a62808e 100644 --- a/test/unit/pep8-tests.py +++ b/test/unit/pep8-tests.py @@ -90,6 +90,11 @@ class UglyHackishTest(TitoUnitTestFixture): result = int(getoutput(cmd)) self.assertEqual(result, 0, "Found commands module (not supported in Python 3)") + def test_use_commands(self): + cmd = "find . -type f -regex '.*\.py$' -exec egrep 'commands\.' {} + | grep -v 'compat\.py' | wc -l" + result = int(getoutput(cmd)) + self.assertEqual(result, 0, "Found commands module (not supported in Python 3)") + def test_print_function(self): cmd = "find . -type f -regex '.*\.py$' -exec grep '^[[:space:]]*print .*' {} + | wc -l" result = int(getoutput(cmd))