gpu: nvgpu: rfr: Add address book

Add an address book that lets devs use short hand for specifying
--to and --cc targets. For example, if a dev wants to CC the MISRA
list this can be used:

  $ ./scripts/rfr -e --cc misra ...

The address book also lets devs add their own names/email addresses
since this makes it convenient to CC individual people. For example:

  $ ./scripts/rfr -e --cc alex ...

Several new arguments were added to support the address book. There
are arguments to list/search the address book, ignore the address
book, and to prevent nvgpu-core from being added to the to address
by default. For more details see the help page.

To use an address book there's several options: place one at

  ~/.rfr-addrbook

Export an RFR_ADDRBOOK environment variable pointing to the address
book, or specify one with the `-a' option. The address book contents
is simple. All empty lines and lines beginning with '#' are ignored.
The remaining lines are split by '|' and the first half of the line
is considered a nickname and the latter half the address. An example:

  alex | alex waterman <alexw@nvidia.com>

This will let you specify `--to alex' instead of the full email
address. This is especially useful for mailing lists.

Lastly there is more documentation located at:

  https://confluence.nvidia.com/display/TGS/NVGPU+Request+For+Review

[Bump version to 1.1.0]

Change-Id: Iac7ec05ae28d7e888d2bf36bd23574ec49eb04dc
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1983695
Reviewed-by: Rohit Khanna <rokhanna@nvidia.com>
This commit is contained in:
Alex Waterman
2018-12-28 14:24:00 -08:00
committed by Rohit Khanna
parent 164e387940
commit dd4c60aeb5
2 changed files with 242 additions and 8 deletions

View File

@@ -33,10 +33,14 @@ import smtplib
from email.mime.text import MIMEText
VERSION = '1.0.3'
from rfr_addrbook import rfr_ab_load
from rfr_addrbook import rfr_ab_query
from rfr_addrbook import rfr_ab_lookup
VERSION = '1.1.0'
# Default email address.
to_addr = 'SW-Mobile-nvgpu-core <SW-Mobile-nvgpu-core@exchange.nvidia.com>'
to_addr = 'sw-mobile-nvgpu-core <sw-mobile-nvgpu-core@exchange.nvidia.com>'
# Gerrit commit URL formats. These are regular expressions to match the
# incoming URLs against.
@@ -63,7 +67,7 @@ def parse_args():
"""
ep="""This program will format commit messages into something that can be
sent to the nvgpu mailing list for review
sent to the nvgpu mailing list for review.
"""
help_msg="""Git or gerrit commits to describe. Can be either a git or gerrit
commit ID. If the ID starts with a 'I' then it will be treated as a gerrit ID.
@@ -93,6 +97,18 @@ Otherwise it's treated as a git commit ID.
'Can be repeated (-c a -c b).')
parser.add_argument('-F', '--file', action='store', default=None,
help='File with commits, one per line')
parser.add_argument('-q', '--query-addrbook', action='store', default=None,
nargs='?', const='.', metavar='regex',
help='Regex query for address book')
parser.add_argument('-a', '--addrbook', action='store', default=None,
metavar='addrbook',
help='Specify location to look for address book')
parser.add_argument('-I', '--ignore-addrbook', action='store_true',
default=False,
help='Ignore address book lookup. Default is false.')
parser.add_argument('--no-default-addr', action='store_true',
default=False,
help='Do not use the default address.')
# Positionals: the gerrit URLs.
parser.add_argument('commits', metavar='Commit-IDs',
@@ -297,9 +313,12 @@ def format_msg_comment(subject, to_addrs, cc_addrs):
knows who they are sending an email to.
"""
msg_comment = """# Lines that begin with a '#' will be ignored in the final
# message. This includes white space so ' # blah', for example,
# will _not_ be ignored.
msg_comment = """# RFR commit editor
#
# Lines that begin with a '#' are comments and will be ignored in the final
# message. '#' characters that appear else where in the line will be ignored.
# White space is not stripped from lines so, for example, ' # blah' will not
# be ignored!
#
"""
@@ -324,8 +343,21 @@ def email_commits(commits_info, sender, subject, args):
Directly email commits to the nvgpu-core mailing list for review!
"""
to_addrs = [to_addr] + args.to
cc_addrs = args.cc
# Lets you drop nvgpu-core from the to-addr if you desire. You can then
# add it back to CC if you wish.
if not args.no_default_addr:
args.to.append(to_addr)
to_addrs = rfr_ab_lookup(args.to, args.ignore_addrbook)
if to_addrs == None:
print('Junk address: aborting!')
print('Use `-I\' to ignore.')
return
cc_addrs = rfr_ab_lookup(args.cc, args.ignore_addrbook)
if cc_addrs == None:
print('Junk address: aborting!')
print('Use `-I\' to ignore.')
return
if args.no_msg:
args.msg = None
@@ -380,6 +412,17 @@ def main():
print('Version: %s' % VERSION)
exit(0)
if arg_parser.addrbook:
success = rfr_ab_load(arg_parser.addrbook)
if not success:
exit(1)
else:
rfr_ab_load(None)
if arg_parser.query_addrbook:
rfr_ab_query(arg_parser.query_addrbook)
exit(0)
if arg_parser.file:
filp = open(arg_parser.file, 'r')