From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web11.7110.1578566972430854943 for ; Thu, 09 Jan 2020 02:49:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Sx/BYuxS; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578566971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3j66EwJb1AqYkGkuiudzOI2o2yW7RIPbfZTn+TklXtw=; b=Sx/BYuxSRSfkuoo293eTdpPLAJiNyigetsXBEH6aHmceigEaRWjn4lVFlNojYE+kDtRfi/ FaHJIkxMfEfawkQGNHaYndpqCRlLNh0NXu2Sn8z244oSEW2x8WjxAvulP4kW/Q9hEmyuZt cIh7S+jPxLClHNdrnWYojT5Dpxlz9/c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-251-WE3Db63jMlu2B42lAa10gA-1; Thu, 09 Jan 2020 05:49:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43286DB20; Thu, 9 Jan 2020 10:49:29 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-107.brq.redhat.com [10.40.204.107]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F01FF60E1C; Thu, 9 Jan 2020 10:49:26 +0000 (UTC) From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= To: Liming Gao , Bob Feng , devel@edk2.groups.io Cc: Philippe Mathieu-Daude , Jordan Justen Subject: [PATCH v3 1/4] BaseTools/PatchCheck.py: Extract email check code to EmailAddressCheck Date: Thu, 9 Jan 2020 11:49:15 +0100 Message-Id: <20200109104918.29750-2-philmd@redhat.com> In-Reply-To: <20200109104918.29750-1-philmd@redhat.com> References: <20200109104918.29750-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: WE3Db63jMlu2B42lAa10gA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable As we are going to reuse this code out of the CommitMessageCheck class, extract it in a new class: EmailAddressCheck. Cc: Liming Gao Cc: Jordan Justen Reviewed-by: Bob Feng Signed-off-by: Philippe Mathieu-Daude --- BaseTools/Scripts/PatchCheck.py | 83 +++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck= .py index 9668025798da..3b6d77081e7e 100755 --- a/BaseTools/Scripts/PatchCheck.py +++ b/BaseTools/Scripts/PatchCheck.py @@ -2,6 +2,7 @@ # Check a patch for various format issues # # Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
+# Copyright (C) 2020, Red Hat, Inc.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -22,6 +23,58 @@ class Verbose: SILENT, ONELINE, NORMAL =3D range(3) level =3D NORMAL =20 +class EmailAddressCheck: + """Checks an email address.""" + + def __init__(self, email): + self.ok =3D True + + if email is None: + self.error('Email address is missing!') + return + + self.check_email_address(email) + + def error(self, *err): + if self.ok and Verbose.level > Verbose.ONELINE: + print('The email address is not valid:') + self.ok =3D False + if Verbose.level < Verbose.NORMAL: + return + count =3D 0 + for line in err: + prefix =3D (' *', ' ')[count > 0] + print(prefix, line) + count +=3D 1 + + email_re1 =3D re.compile(r'(?:\s*)(.*?)(\s*)<(.+)>\s*$', + re.MULTILINE|re.IGNORECASE) + + def check_email_address(self, email): + email =3D email.strip() + mo =3D self.email_re1.match(email) + if mo is None: + self.error("Email format is invalid: " + email.strip()) + return + + name =3D mo.group(1).strip() + if name =3D=3D '': + self.error("Name is not provided with email address: " + + email) + else: + quoted =3D len(name) > 2 and name[0] =3D=3D '"' and name[-1] = =3D=3D '"' + if name.find(',') >=3D 0 and not quoted: + self.error('Add quotes (") around name with a comma: ' + + name) + + if mo.group(2) =3D=3D '': + self.error("There should be a space between the name and " + + "email address: " + email) + + if mo.group(3).find(' ') >=3D 0: + self.error("The email address cannot contain a space: " + + mo.group(3)) + class CommitMessageCheck: """Checks the contents of a git commit message.""" =20 @@ -121,38 +174,10 @@ class CommitMessageCheck: if s[2] !=3D ' ': self.error("There should be a space after '" + sig + ":'") =20 - self.check_email_address(s[3]) + EmailAddressCheck(s[3]) =20 return sigs =20 - email_re1 =3D re.compile(r'(?:\s*)(.*?)(\s*)<(.+)>\s*$', - re.MULTILINE|re.IGNORECASE) - - def check_email_address(self, email): - email =3D email.strip() - mo =3D self.email_re1.match(email) - if mo is None: - self.error("Email format is invalid: " + email.strip()) - return - - name =3D mo.group(1).strip() - if name =3D=3D '': - self.error("Name is not provided with email address: " + - email) - else: - quoted =3D len(name) > 2 and name[0] =3D=3D '"' and name[-1] = =3D=3D '"' - if name.find(',') >=3D 0 and not quoted: - self.error('Add quotes (") around name with a comma: ' + - name) - - if mo.group(2) =3D=3D '': - self.error("There should be a space between the name and " + - "email address: " + email) - - if mo.group(3).find(' ') >=3D 0: - self.error("The email address cannot contain a space: " + - mo.group(3)) - def check_signed_off_by(self): sob=3D'Signed-off-by' if self.msg.find(sob) < 0: --=20 2.21.1