summaryrefslogtreecommitdiffstats
path: root/BaseTools/Scripts/PatchCheck.py
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daude <philmd@redhat.com>2020-01-09 18:55:43 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-01-10 04:06:42 +0000
commit8ffa47fb3abd58ded6fe852ee9f518d19f9f9858 (patch)
treea11dd89b67cb759fa492324c42699a7c2abe896f /BaseTools/Scripts/PatchCheck.py
parent1f0d8096291651e6c20dbbc57d108321c1443563 (diff)
downloadedk2-8ffa47fb3abd58ded6fe852ee9f518d19f9f9858.tar.gz
edk2-8ffa47fb3abd58ded6fe852ee9f518d19f9f9858.tar.bz2
edk2-8ffa47fb3abd58ded6fe852ee9f518d19f9f9858.zip
BaseTools/PatchCheck.py: Extract email check code to EmailAddressCheck
As we are going to reuse this code out of the CommitMessageCheck class, extract it in a new class: EmailAddressCheck. Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com> Signed-off-by: Philippe Mathieu-Daude <philmd@redhat.com>
Diffstat (limited to 'BaseTools/Scripts/PatchCheck.py')
-rwxr-xr-xBaseTools/Scripts/PatchCheck.py83
1 files changed, 54 insertions, 29 deletions
diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 9668025798..3b6d77081e 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.<BR>
+# Copyright (C) 2020, Red Hat, Inc.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -22,6 +23,58 @@ class Verbose:
SILENT, ONELINE, NORMAL = range(3)
level = NORMAL
+class EmailAddressCheck:
+ """Checks an email address."""
+
+ def __init__(self, email):
+ self.ok = 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 = False
+ if Verbose.level < Verbose.NORMAL:
+ return
+ count = 0
+ for line in err:
+ prefix = (' *', ' ')[count > 0]
+ print(prefix, line)
+ count += 1
+
+ email_re1 = re.compile(r'(?:\s*)(.*?)(\s*)<(.+)>\s*$',
+ re.MULTILINE|re.IGNORECASE)
+
+ def check_email_address(self, email):
+ email = email.strip()
+ mo = self.email_re1.match(email)
+ if mo is None:
+ self.error("Email format is invalid: " + email.strip())
+ return
+
+ name = mo.group(1).strip()
+ if name == '':
+ self.error("Name is not provided with email address: " +
+ email)
+ else:
+ quoted = len(name) > 2 and name[0] == '"' and name[-1] == '"'
+ if name.find(',') >= 0 and not quoted:
+ self.error('Add quotes (") around name with a comma: ' +
+ name)
+
+ if mo.group(2) == '':
+ self.error("There should be a space between the name and " +
+ "email address: " + email)
+
+ if mo.group(3).find(' ') >= 0:
+ self.error("The email address cannot contain a space: " +
+ mo.group(3))
+
class CommitMessageCheck:
"""Checks the contents of a git commit message."""
@@ -121,38 +174,10 @@ class CommitMessageCheck:
if s[2] != ' ':
self.error("There should be a space after '" + sig + ":'")
- self.check_email_address(s[3])
+ EmailAddressCheck(s[3])
return sigs
- email_re1 = re.compile(r'(?:\s*)(.*?)(\s*)<(.+)>\s*$',
- re.MULTILINE|re.IGNORECASE)
-
- def check_email_address(self, email):
- email = email.strip()
- mo = self.email_re1.match(email)
- if mo is None:
- self.error("Email format is invalid: " + email.strip())
- return
-
- name = mo.group(1).strip()
- if name == '':
- self.error("Name is not provided with email address: " +
- email)
- else:
- quoted = len(name) > 2 and name[0] == '"' and name[-1] == '"'
- if name.find(',') >= 0 and not quoted:
- self.error('Add quotes (") around name with a comma: ' +
- name)
-
- if mo.group(2) == '':
- self.error("There should be a space between the name and " +
- "email address: " + email)
-
- if mo.group(3).find(' ') >= 0:
- self.error("The email address cannot contain a space: " +
- mo.group(3))
-
def check_signed_off_by(self):
sob='Signed-off-by'
if self.msg.find(sob) < 0: