From: Kefu Chai Date: Tue, 6 Oct 2020 15:20:32 +0000 (+0800) Subject: ceph-pr-commits: port test_commits.py to py3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=483bc8efe2437b997556939653d217f9e7c2a769;p=ceph-build.git ceph-pr-commits: port test_commits.py to py3 Signed-off-by: Kefu Chai --- diff --git a/ceph-pr-commits/build/test_commits.py b/ceph-pr-commits/build/test_commits.py index d474ad56..b23988f2 100644 --- a/ceph-pr-commits/build/test_commits.py +++ b/ceph-pr-commits/build/test_commits.py @@ -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 - ) - ) - + ))