gpu: nvgpu: rfr: Notify user of email destination

When sending emails it can be nice to see who you are sending an
email to if you specify multiple '--to' options.

Also update the get_user_message() function to remove comment lines
starting with '#'. This lets the script place information useful
to a developer in the message that won't ultimately make it to the
final email.

[Bump minor revision to 1.0.2]

Change-Id: I3657a787d8e9a8c19de727e050a0b9a18a6d43e0
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1983642
Reviewed-by: Rohit Khanna <rokhanna@nvidia.com>
This commit is contained in:
Alex Waterman
2018-12-28 12:31:17 -08:00
committed by Rohit Khanna
parent dce49c9b2b
commit e2aa359774

View File

@@ -33,7 +33,7 @@ import smtplib
from email.mime.text import MIMEText from email.mime.text import MIMEText
VERSION = '1.0.1' VERSION = '1.0.2'
# Gerrit commit URL formats. These are regular expressions to match the # Gerrit commit URL formats. These are regular expressions to match the
# incoming URLs against. # incoming URLs against.
@@ -232,7 +232,9 @@ def get_user_message(start_msg):
return None return None
filp.seek(0) filp.seek(0)
return filp.read() lines = filp.readlines()
return ''.join(filter(lambda l: not l.startswith('#'), lines))
def indent_lines(text, ind): def indent_lines(text, ind):
""" """
@@ -246,8 +248,7 @@ def format_commits(commits_info, extra_message):
text to print. This can either be directly printed or emailed. text to print. This can either be directly printed or emailed.
""" """
whole_template = """ whole_template = """Hi All,
Hi All,
I would like you to review the following changes. I would like you to review the following changes.
{extra_message} {extra_message}
@@ -284,6 +285,22 @@ Thanks!
extra_message=extra_message, extra_message=extra_message,
cmt_verbose=cmt_verbose) cmt_verbose=cmt_verbose)
def format_to_comment(to_addrs):
"""
Take the list of to_addrs and format them into a comment so that the sender
knows who they are sending an email to.
"""
to_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.
#
"""
for addr in to_addrs:
to_comment += '# To: %s\n' % addr
return to_comment
def display_commits(commits_info, extra_message): def display_commits(commits_info, extra_message):
""" """
Print the list of commits to the directly to the terminal. Print the list of commits to the directly to the terminal.
@@ -297,11 +314,12 @@ def email_commits(commits_info, sender, subject, args):
""" """
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>'
to_addrs = [to_addr] + args.to
if args.no_msg: if args.no_msg:
args.msg = None args.msg = None
body = format_commits(commits_info, args.msg) body = format_to_comment(to_addrs) + format_commits(commits_info, args.msg)
# Most people like to write a little description of their patch series # Most people like to write a little description of their patch series
# in the email body. This aims to take care of that. # in the email body. This aims to take care of that.
@@ -327,8 +345,6 @@ def email_commits(commits_info, sender, subject, args):
else: else:
msg = MIMEText(body) msg = MIMEText(body)
to_addrs = [to_addr] + args.to
msg['To'] = ", ".join(to_addrs) msg['To'] = ", ".join(to_addrs)
msg['From'] = sender msg['From'] = sender
msg['Subject'] = subject msg['Subject'] = subject