From nobody Tue Feb 10 05:45:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43666+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43666+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1562950898; cv=none; d=zoho.com; s=zohoarc; b=Xz/C9hCG/gxuE/OLDrH1TKEdNLYUnKaSns8eM8cG8Q7pSDY5oH1/L7srmSBK5n2nR+cskEZGibLyovNaRSXRiRcZKrfeFDP1HasKKKiEMmHtCgQ6mRjSsBrpFqukvEVm2U3AnuIM05a77Fsj/w/Il5NA+MYomkMn2hY8fYPQXHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562950898; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=FMPSUkGREvu9YIigJSPnCbaJxstxwJiBCOtmy9Yy0qM=; b=oJhgfZ2RqDyCcdTR7udC+Do/75j3Y92+uQX0oADSArEhfc0DVQoA3ZM0iJ6m4scYAWPpvQFkyMs1OxUGW/Mm/hDhXEGaIVIWcHB0E3yD5VzdymFDZkQwAjSASNJwYQzzE+vXlqGdwObkWpS1MOvDmYlu2CgWfQavqyA1PH+QcfE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43666+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562950898815669.2398826093968; Fri, 12 Jul 2019 10:01:38 -0700 (PDT) Return-Path: X-Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by groups.io with SMTP; Fri, 12 Jul 2019 10:01:38 -0700 X-Received: by mail-wm1-f52.google.com with SMTP id x15so9568616wmj.3 for ; Fri, 12 Jul 2019 10:01:37 -0700 (PDT) X-Gm-Message-State: APjAAAXjk+9Eb+R3N8bMpGIrmCiXw62+0W2NvWgOSIcslen0QEGOzzxV /vdOBkSnxFc/RmqrVDGEmYeI+B9JbUA= X-Google-Smtp-Source: APXvYqyronUVZ/qKF1REopyeBEMCVJZxwd0RubhhzkwU0swPRE1ZwtsdAGF25YSXJVLCFROyd+XB6w== X-Received: by 2002:a1c:6454:: with SMTP id y81mr10515263wmb.105.1562950895917; Fri, 12 Jul 2019 10:01:35 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id g11sm9044816wru.24.2019.07.12.10.01.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 12 Jul 2019 10:01:35 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Andrew Fish , Laszlo Ersek , Michael D Kinney , Philippe Mathieu-Daude , Bob Feng , Liming Gao Subject: [edk2-devel] [PATCH 3/3] BaseTools: add GetMaintainer.py script Date: Fri, 12 Jul 2019 18:01:28 +0100 Message-Id: <20190712170128.6495-4-leif.lindholm@linaro.org> In-Reply-To: <20190712170128.6495-1-leif.lindholm@linaro.org> References: <20190712170128.6495-1-leif.lindholm@linaro.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif.lindholm@linaro.org Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562950898; bh=JeGImNdDAjGPXnzo0dBWJ8U0F/zY8cDBGStQeXp3Yb0=; h=Cc:Date:From:Reply-To:Subject:To; b=uq7MKvac9L+GZeI0a6qNkMZ1SjRSreUx4vnEX3re7DreQj4uFfJxRpyKpL1N7vh7llK 7wGMSdC039qXhd+iSBCRvuKbK1OSVdunoEm5VXDcNxI916UQtRCcO58TV4CcLL+LgFUS1 u2Sb+qQSucodeegBK0TCeloFlcrOSmDxIZ4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add a new script GetMaintainer.py that uses the new Maintainer.txt format to determine which addresses to cc on patch submission. Signed-off-by: Leif Lindholm Reviewed-by: Philippe Mathieu-Daude Tested-by: Philippe Mathieu-Daude Acked-by: Laszlo Ersek --- BaseTools/Scripts/GetMaintainer.py | 190 +++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 BaseTools/Scripts/GetMaintainer.py diff --git a/BaseTools/Scripts/GetMaintainer.py b/BaseTools/Scripts/GetMain= tainer.py new file mode 100644 index 000000000000..fbc63522db77 --- /dev/null +++ b/BaseTools/Scripts/GetMaintainer.py @@ -0,0 +1,190 @@ +## @file +# Retrieves the people to request review from on submission of a commit. +# +# Copyright (c) 2019, Linaro Ltd. All rights reserved.
+# +# 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 =3D { + 'exclude': re.compile(r'^X:\s*(?P.*?)\r*$'), + 'file': re.compile(r'^F:\s*(?P.*?)\r*$'), + 'list': re.compile(r'^L:\s*(?P.*?)\r*$'), + 'maintainer': re.compile(r'^M:\s*(?P.*<.*?>)\r*$'), + 'reviewer': re.compile(r'^R:\s*(?P.*?)\r*$'), + 'status': re.compile(r'^S:\s*(?P.*?)\r*$'), + 'tree': re.compile(r'^T:\s*(?P.*?)\r*$'), + 'webpage': re.compile(r'^W:\s*(?P.*?)\r*$') +} + +def printsection(section): + """Prints out the dictionary describing a Maintainers.txt section.""" + print('=3D=3D=3D') + 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 =3D pattern.replace('.', r'\.') + pattern =3D pattern.replace('?', r'.') + pattern =3D pattern.replace('*', r'.*') + + if pattern.endswith('/'): + pattern +=3D r'.*' + elif pattern.endswith('.*'): + pattern =3D pattern[:-2] + pattern +=3D 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 =3D pattern_to_regex(pattern) + + match =3D re.match(regex, path) + if match: + # Check if there is an exclude pattern that applies + for pattern in section['exclude']: + regex =3D pattern_to_regex(pattern) + + match =3D 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 =3D [] + lists =3D [] + + if path_in_section(path, section): + for address in section['maintainer'], section['reviewer']: + # Convert to list if necessary + if isinstance(address, list): + maintainers +=3D address + else: + lists +=3D [address] + for address in section['list']: + # Convert to list if necessary + if isinstance(address, list): + lists +=3D address + else: + lists +=3D [address] + + return maintainers, lists + +def get_maintainers(path, sections, level=3D0): + """For 'path', iterates over all sections, returning maintainers + for matching ones.""" + maintainers =3D [] + lists =3D [] + for section in sections: + tmp_maint, tmp_lists =3D get_section_maintainers(path, section) + if tmp_maint: + maintainers +=3D tmp_maint + if tmp_lists: + lists +=3D tmp_lists + + if not maintainers: + # If no match found, look for match for (nonexistent) file + # REPO.working_dir/ + print('"%s": no maintainers found, looking for default' % path) + if level =3D=3D 0: + maintainers =3D get_maintainers('', sections, level= =3Dlevel + 1) + else: + print("No 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 it= s key.""" + for key, expression in EXPRESSIONS.items(): + match =3D 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 =3D text.readline() + sectionlist =3D [] + section =3D defaultdict(list) + while line: + key, value =3D parse_maintainers_line(line) + if key and value: + section[key].append(value) + + line =3D 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 'ar= gs'.""" + commit =3D repo.commit(args.commit) + return commit.stats.files + +if __name__ =3D=3D '__main__': + PARSER =3D argparse.ArgumentParser( + description=3D'Retrieves information on who to cc for review on a = given commit') + PARSER.add_argument('commit', + action=3D"store", + help=3D'git revision to examine (default: HEAD)', + nargs=3D'?', + default=3D'HEAD') + PARSER.add_argument('-l', '--lookup', + help=3D'Find section matches for path LOOKUP', + required=3DFalse) + ARGS =3D PARSER.parse_args() + + REPO =3D SetupGit.locate_repo() + + CONFIG_FILE =3D os.path.join(REPO.working_dir, 'Maintainers.txt') + + SECTIONS =3D parse_maintainers_file(CONFIG_FILE) + + if ARGS.lookup: + FILES =3D [ARGS.lookup] + else: + FILES =3D get_modified_files(REPO, ARGS) + + ADDRESSES =3D [] + + for file in FILES: + print(file) + addresslist =3D get_maintainers(file, SECTIONS) + if addresslist: + ADDRESSES +=3D addresslist + + for address in list(OrderedDict.fromkeys(ADDRESSES)): + print(' %s' % address) --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43666): https://edk2.groups.io/g/devel/message/43666 Mute This Topic: https://groups.io/mt/32444053/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-