mirror of
https://github.com/AdaCore/git-hooks.git
synced 2026-02-12 12:43:11 -08:00
This commit is the result of running the following command in
the testsuite/ directory:
$ sed -i '/^from\s\+__future__\s\+import\s\+print_function\s*$/d' \
`git grep print_function | cut -d: -f1 | sort -u`
Change-Id: Idb18a24f5368434a505af42b347b8f2a1d0481b5
TN: U530-006
55 lines
1.8 KiB
Python
Executable File
55 lines
1.8 KiB
Python
Executable File
#! /usr/bin/env python
|
|
"""A script to be used as a sendmail replacement during testing.
|
|
|
|
Instead of actually sending the email, we dump information about
|
|
the email on standard output.
|
|
"""
|
|
|
|
|
|
from email.parser import Parser
|
|
import os
|
|
import sys
|
|
|
|
|
|
def stdout_sendmail():
|
|
email_str = sys.stdin.read()
|
|
e_msg = Parser().parsestr(email_str)
|
|
|
|
if "GIT_HOOKS_MINIMAL_EMAIL_DEBUG_TRACE" in os.environ:
|
|
# This environment variable is set when the testcase
|
|
# doesn't really care about the full contents of
|
|
# the email. Just print a simple trace showing that
|
|
# the email _is_ being sent, and that's it.
|
|
|
|
subject = e_msg["Subject"]
|
|
if "\n" in subject:
|
|
# The email subject got split across multiple lines during
|
|
# email formatting. Restore it to a single-line subject.
|
|
subject = "".join(subject.splitlines())
|
|
sys.stdout.write("DEBUG: Sending email: {subject}...".format(subject=subject))
|
|
|
|
else:
|
|
sys.stdout.write("DEBUG: ")
|
|
for field, value in e_msg.items():
|
|
sys.stdout.write("{field}: {value}\n".format(field=field, value=value))
|
|
payload = e_msg.get_payload(decode=True)
|
|
# The payload is in bytes; decode it before we send it to stdout
|
|
# (which wants str objects).
|
|
#
|
|
# Only do this decoding when Python >= 3.x, as we are getting
|
|
# some errors with Python 2.x which are not worth investigating
|
|
# at this stage (we are moving away from 2.x support).
|
|
if sys.version_info[0] >= 3:
|
|
# The payload is in bytes, and needs to be decoded
|
|
# in order to be
|
|
charset = e_msg.get_content_charset()
|
|
payload = payload.decode(charset)
|
|
sys.stdout.write("\n")
|
|
sys.stdout.write(payload)
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
stdout_sendmail()
|