From: "Bob Feng" <bob.c.feng@intel.com>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Liming Gao <gaoliming@byosoft.com.cn>,
"Chen, Christine" <yuwei.chen@intel.com>
Subject: Re: [Patch V2 1/3] BaseTools/Scripts: Fix GetMaintainer.py line endings
Date: Fri, 9 Jul 2021 01:08:21 +0000 [thread overview]
Message-ID: <DM6PR11MB407312D7340EAF847CEF97E9C9189@DM6PR11MB4073.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20210708195047.1649-2-michael.d.kinney@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@intel.com>
Sent: Friday, July 9, 2021 3:51 AM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Chen, Christine <yuwei.chen@intel.com>
Subject: [Patch V2 1/3] BaseTools/Scripts: Fix GetMaintainer.py line endings
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
BaseTools/Scripts/GetMaintainer.py | 380 ++++++++++++++---------------
1 file changed, 190 insertions(+), 190 deletions(-)
diff --git a/BaseTools/Scripts/GetMaintainer.py b/BaseTools/Scripts/GetMaintainer.py
index ed7bc7dc2b88..5ec851554d64 100644
--- a/BaseTools/Scripts/GetMaintainer.py
+++ b/BaseTools/Scripts/GetMaintainer.py
@@ -1,194 +1,194 @@
-## @file
-# Retrieves the people to request review from on submission of a commit.
-#
-# Copyright (c) 2019, Linaro Ltd. All rights reserved.<BR> -# -# SPDX-License-Identifier: BSD-2-Clause-Patent -#
-
-from __future__ import print_function
-from collections import defaultdict
-from collections import OrderedDict
-import argparse
-import os
-import re
-import SetupGit
-
-EXPRESSIONS = {
- 'exclude': re.compile(r'^X:\s*(?P<exclude>.*?)\r*$'),
- 'file': re.compile(r'^F:\s*(?P<file>.*?)\r*$'),
- 'list': re.compile(r'^L:\s*(?P<list>.*?)\r*$'),
- 'maintainer': re.compile(r'^M:\s*(?P<maintainer>.*<.*?>)\r*$'),
- 'reviewer': re.compile(r'^R:\s*(?P<reviewer>.*?)\r*$'),
- 'status': re.compile(r'^S:\s*(?P<status>.*?)\r*$'),
- 'tree': re.compile(r'^T:\s*(?P<tree>.*?)\r*$'),
- 'webpage': re.compile(r'^W:\s*(?P<webpage>.*?)\r*$')
-}
-
-def printsection(section):
- """Prints out the dictionary describing a Maintainers.txt section."""
- print('===')
- for key in section.keys():
- print("Key: %s" % key)
- for item in section[key]:
- print(' %s' % item)
-
-def pattern_to_regex(pattern):
- """Takes a string containing regular UNIX path wildcards
- and returns a string suitable for matching with regex."""
-
- pattern = pattern.replace('.', r'\.')
- pattern = pattern.replace('?', r'.')
- pattern = pattern.replace('*', r'.*')
-
- if pattern.endswith('/'):
- pattern += r'.*'
- elif pattern.endswith('.*'):
- pattern = pattern[:-2]
- pattern += r'(?!.*?/.*?)'
-
- return pattern
-
-def path_in_section(path, section):
- """Returns True of False indicating whether the path is covered by
- the current section."""
- if not 'file' in section:
- return False
-
- for pattern in section['file']:
- regex = pattern_to_regex(pattern)
-
- match = re.match(regex, path)
- if match:
- # Check if there is an exclude pattern that applies
- for pattern in section['exclude']:
- regex = pattern_to_regex(pattern)
-
- match = re.match(regex, path)
- if match:
- return False
-
- return True
-
- return False
-
-def get_section_maintainers(path, section):
- """Returns a list with email addresses to any M: and R: entries
- matching the provided path in the provided section."""
- maintainers = []
- lists = []
+## @file
+# Retrieves the people to request review from on submission of a commit.
+#
+# Copyright (c) 2019, Linaro Ltd. All rights reserved.<BR> # #
+SPDX-License-Identifier: BSD-2-Clause-Patent #
+
+from __future__ import print_function
+from collections import defaultdict
+from collections import OrderedDict
+import argparse
+import os
+import re
+import SetupGit
+
+EXPRESSIONS = {
+ 'exclude': re.compile(r'^X:\s*(?P<exclude>.*?)\r*$'),
+ 'file': re.compile(r'^F:\s*(?P<file>.*?)\r*$'),
+ 'list': re.compile(r'^L:\s*(?P<list>.*?)\r*$'),
+ 'maintainer': re.compile(r'^M:\s*(?P<maintainer>.*<.*?>)\r*$'),
+ 'reviewer': re.compile(r'^R:\s*(?P<reviewer>.*?)\r*$'),
+ 'status': re.compile(r'^S:\s*(?P<status>.*?)\r*$'),
+ 'tree': re.compile(r'^T:\s*(?P<tree>.*?)\r*$'),
+ 'webpage': re.compile(r'^W:\s*(?P<webpage>.*?)\r*$')
+}
+
+def printsection(section):
+ """Prints out the dictionary describing a Maintainers.txt section."""
+ print('===')
+ for key in section.keys():
+ print("Key: %s" % key)
+ for item in section[key]:
+ print(' %s' % item)
+
+def pattern_to_regex(pattern):
+ """Takes a string containing regular UNIX path wildcards
+ and returns a string suitable for matching with regex."""
+
+ pattern = pattern.replace('.', r'\.')
+ pattern = pattern.replace('?', r'.')
+ pattern = pattern.replace('*', r'.*')
+
+ if pattern.endswith('/'):
+ pattern += r'.*'
+ elif pattern.endswith('.*'):
+ pattern = pattern[:-2]
+ pattern += r'(?!.*?/.*?)'
+
+ return pattern
+
+def path_in_section(path, section):
+ """Returns True of False indicating whether the path is covered by
+ the current section."""
+ if not 'file' in section:
+ return False
+
+ for pattern in section['file']:
+ regex = pattern_to_regex(pattern)
+
+ match = re.match(regex, path)
+ if match:
+ # Check if there is an exclude pattern that applies
+ for pattern in section['exclude']:
+ regex = pattern_to_regex(pattern)
+
+ match = re.match(regex, path)
+ if match:
+ return False
+
+ return True
+
+ return False
+
+def get_section_maintainers(path, section):
+ """Returns a list with email addresses to any M: and R: entries
+ matching the provided path in the provided section."""
+ maintainers = []
+ lists = []
nowarn_status = ['Supported', 'Maintained']
-
- if path_in_section(path, section):
+
+ if path_in_section(path, section):
for status in section['status']:
if status not in nowarn_status:
print('WARNING: Maintained status for "%s" is \'%s\'!' % (path, status))
- for address in section['maintainer'], section['reviewer']:
- # Convert to list if necessary
- if isinstance(address, list):
- maintainers += address
- else:
- lists += [address]
- for address in section['list']:
- # Convert to list if necessary
- if isinstance(address, list):
- lists += address
- else:
- lists += [address]
-
- return maintainers, lists
-
-def get_maintainers(path, sections, level=0):
- """For 'path', iterates over all sections, returning maintainers
- for matching ones."""
- maintainers = []
- lists = []
- for section in sections:
- tmp_maint, tmp_lists = get_section_maintainers(path, section)
- if tmp_maint:
- maintainers += tmp_maint
- if tmp_lists:
- lists += tmp_lists
-
- if not maintainers:
- # If no match found, look for match for (nonexistent) file
- # REPO.working_dir/<default>
- print('"%s": no maintainers found, looking for default' % path)
- if level == 0:
- maintainers = get_maintainers('<default>', sections, level=level + 1)
- else:
- print("No <default> maintainers set for project.")
- if not maintainers:
- return None
-
- return maintainers + lists
-
-def parse_maintainers_line(line):
- """Parse one line of Maintainers.txt, returning any match group and its key."""
- for key, expression in EXPRESSIONS.items():
- match = expression.match(line)
- if match:
- return key, match.group(key)
- return None, None
-
-def parse_maintainers_file(filename):
- """Parse the Maintainers.txt from top-level of repo and
- return a list containing dictionaries of all sections."""
- with open(filename, 'r') as text:
- line = text.readline()
- sectionlist = []
- section = defaultdict(list)
- while line:
- key, value = parse_maintainers_line(line)
- if key and value:
- section[key].append(value)
-
- line = text.readline()
- # If end of section (end of file, or non-tag line encountered)...
- if not key or not value or not line:
- # ...if non-empty, append section to list.
- if section:
- sectionlist.append(section.copy())
- section.clear()
-
- return sectionlist
-
-def get_modified_files(repo, args):
- """Returns a list of the files modified by the commit specified in 'args'."""
- commit = repo.commit(args.commit)
- return commit.stats.files
-
-if __name__ == '__main__':
- PARSER = argparse.ArgumentParser(
- description='Retrieves information on who to cc for review on a given commit')
- PARSER.add_argument('commit',
- action="store",
- help='git revision to examine (default: HEAD)',
- nargs='?',
- default='HEAD')
- PARSER.add_argument('-l', '--lookup',
- help='Find section matches for path LOOKUP',
- required=False)
- ARGS = PARSER.parse_args()
-
- REPO = SetupGit.locate_repo()
-
- CONFIG_FILE = os.path.join(REPO.working_dir, 'Maintainers.txt')
-
- SECTIONS = parse_maintainers_file(CONFIG_FILE)
-
- if ARGS.lookup:
- FILES = [ARGS.lookup]
- else:
- FILES = get_modified_files(REPO, ARGS)
-
- ADDRESSES = []
-
- for file in FILES:
- print(file)
- addresslist = get_maintainers(file, SECTIONS)
- if addresslist:
- ADDRESSES += addresslist
-
- for address in list(OrderedDict.fromkeys(ADDRESSES)):
- print(' %s' % address)
+ for address in section['maintainer'], section['reviewer']:
+ # Convert to list if necessary
+ if isinstance(address, list):
+ maintainers += address
+ else:
+ lists += [address]
+ for address in section['list']:
+ # Convert to list if necessary
+ if isinstance(address, list):
+ lists += address
+ else:
+ lists += [address]
+
+ return maintainers, lists
+
+def get_maintainers(path, sections, level=0):
+ """For 'path', iterates over all sections, returning maintainers
+ for matching ones."""
+ maintainers = []
+ lists = []
+ for section in sections:
+ tmp_maint, tmp_lists = get_section_maintainers(path, section)
+ if tmp_maint:
+ maintainers += tmp_maint
+ if tmp_lists:
+ lists += tmp_lists
+
+ if not maintainers:
+ # If no match found, look for match for (nonexistent) file
+ # REPO.working_dir/<default>
+ print('"%s": no maintainers found, looking for default' % path)
+ if level == 0:
+ maintainers = get_maintainers('<default>', sections, level=level + 1)
+ else:
+ print("No <default> maintainers set for project.")
+ if not maintainers:
+ return None
+
+ return maintainers + lists
+
+def parse_maintainers_line(line):
+ """Parse one line of Maintainers.txt, returning any match group and its key."""
+ for key, expression in EXPRESSIONS.items():
+ match = expression.match(line)
+ if match:
+ return key, match.group(key)
+ return None, None
+
+def parse_maintainers_file(filename):
+ """Parse the Maintainers.txt from top-level of repo and
+ return a list containing dictionaries of all sections."""
+ with open(filename, 'r') as text:
+ line = text.readline()
+ sectionlist = []
+ section = defaultdict(list)
+ while line:
+ key, value = parse_maintainers_line(line)
+ if key and value:
+ section[key].append(value)
+
+ line = text.readline()
+ # If end of section (end of file, or non-tag line encountered)...
+ if not key or not value or not line:
+ # ...if non-empty, append section to list.
+ if section:
+ sectionlist.append(section.copy())
+ section.clear()
+
+ return sectionlist
+
+def get_modified_files(repo, args):
+ """Returns a list of the files modified by the commit specified in 'args'."""
+ commit = repo.commit(args.commit)
+ return commit.stats.files
+
+if __name__ == '__main__':
+ PARSER = argparse.ArgumentParser(
+ description='Retrieves information on who to cc for review on a given commit')
+ PARSER.add_argument('commit',
+ action="store",
+ help='git revision to examine (default: HEAD)',
+ nargs='?',
+ default='HEAD')
+ PARSER.add_argument('-l', '--lookup',
+ help='Find section matches for path LOOKUP',
+ required=False)
+ ARGS = PARSER.parse_args()
+
+ REPO = SetupGit.locate_repo()
+
+ CONFIG_FILE = os.path.join(REPO.working_dir, 'Maintainers.txt')
+
+ SECTIONS = parse_maintainers_file(CONFIG_FILE)
+
+ if ARGS.lookup:
+ FILES = [ARGS.lookup]
+ else:
+ FILES = get_modified_files(REPO, ARGS)
+
+ ADDRESSES = []
+
+ for file in FILES:
+ print(file)
+ addresslist = get_maintainers(file, SECTIONS)
+ if addresslist:
+ ADDRESSES += addresslist
+
+ for address in list(OrderedDict.fromkeys(ADDRESSES)):
+ print(' %s' % address)
--
2.32.0.windows.1
next prev parent reply other threads:[~2021-07-09 1:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 19:50 [Patch V2 0/3] Add GitHub IDs to Maintainers.txt Michael D Kinney
2021-07-08 19:50 ` [Patch V2 1/3] BaseTools/Scripts: Fix GetMaintainer.py line endings Michael D Kinney
2021-07-09 1:08 ` Bob Feng [this message]
2021-07-08 19:50 ` [Patch V2 2/3] BaseTools/Scripts: Allow GitHub ID at end Maintainers.txt lines Michael D Kinney
2021-07-09 1:25 ` Bob Feng
2021-07-08 19:50 ` [Patch V2 3/3] Maintainers.txt: Add GitHub IDs Michael D Kinney
2021-07-09 12:23 ` Laszlo Ersek
2021-07-09 16:42 ` Michael D Kinney
2021-07-22 4:15 ` Andrew Fish
2021-08-03 10:49 ` Leif Lindholm
2021-07-08 19:55 ` [edk2-devel] [Patch V2 0/3] Add GitHub IDs to Maintainers.txt Sean
2021-07-08 20:02 ` Michael D Kinney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM6PR11MB407312D7340EAF847CEF97E9C9189@DM6PR11MB4073.namprd11.prod.outlook.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox