]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
ceph-pr-commits: port test_commits.py to py3
authorKefu Chai <kchai@redhat.com>
Tue, 6 Oct 2020 15:20:32 +0000 (23:20 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 6 Oct 2020 16:00:07 +0000 (00:00 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
ceph-pr-commits/build/test_commits.py

index d474ad565933eaa7edca80d2b6c823bcf1d9fd9a..b23988f27e264693b38ea961435c3d750ff7a956 100644 (file)
@@ -1,9 +1,13 @@
+from __future__ import print_function
 from subprocess import check_output
 import os
-from os.path import dirname
 import shlex
 import re
-from itertools import ifilterfalse
+from os.path import dirname
+try:
+    from itertools import filterfalse
+except ImportError:
+    from itertools import ifilterfalse as filterfalse
 
 import pytest
 
@@ -15,13 +19,14 @@ class TestCommits(object):
     target_branch = os.getenv('ghprbTargetBranch', 'master')
     source_branch = 'HEAD'
 
-    workspace = os.getenv('WORKSPACE') or dirname(dirname(dirname(dirname(os.path.abspath(__file__)))))
+    workspace = os.getenv('WORKSPACE') or dirname(
+        dirname(dirname(dirname(os.path.abspath(__file__)))))
     ceph_checkout = os.path.join(workspace, 'ceph')
 
     @classmethod
     def command(cls, command):
-        print "Running command: %s" % (command,)
-        return check_output(shlex.split(command), cwd=cls.ceph_checkout)
+        print("Running command:", command)
+        return check_output(shlex.split(command), cwd=cls.ceph_checkout).decode()
 
     @classmethod
     def setup_class(cls):
@@ -35,17 +40,15 @@ class TestCommits(object):
         signed_off_regex = r'Signed-off-by: \S.* <[^@]+@[^@]+\.[^@]+>'
         # '-z' puts a '\0' between commits, see later split('\0')
         check_signed_off_commits = 'git log -z --no-merges origin/%s..%s' % (
-                self.target_branch, self.source_branch)
-        wrong_commits = list(ifilterfalse(
-                re.compile(signed_off_regex).search,
-                self.command(check_signed_off_commits).split('\0')))
+            self.target_branch, self.source_branch)
+        wrong_commits = list(filterfalse(
+            re.compile(signed_off_regex).search,
+            self.command(check_signed_off_commits).split('\0')))
         if wrong_commits:
             raise AssertionError("\n".join([
                 "Following commit/s is/are not signed, please make sure all TestCommits",
                 "are signed following the 'Submitting Patches' guide:",
                 "https://github.com/ceph/ceph/blob/master/SubmittingPatches.rst#1-sign-your-work",
-                ""] + 
+                ""] +
                 wrong_commits
-                )
-            )
-
+            ))