9 Commits

Author SHA1 Message Date
Joel Brobecker
2d7ef76b2a Remove import of __future__.print_function in hooks/*
Now that Python 3.x is required, this import is no longer useful.
Note that this commit deliberately excludes the imports done
in the testsuite, so as to allow these changes to be reviewed
independently of the changes to be made in the testsuite.

Change-Id: I28e1857df2cf0b2f9e7ddeab00b456d6ef513755
TN: U530-006
2021-11-30 17:58:55 +04:00
Joel Brobecker
23c0aea671 updates/sendmail.py: encode input and decode output when calling sendmail
This is another preparation patch for the transition to Python 3.x.
With Python 3.x, we need to make sure that the input used when
calling sendmail is converted to a byte string. We also then need
to make sure that the script's output is decoded into a string
when printing it.

Change-Id: I1b792638fb77c8d1b4ee2197b29b63922e0fe211
TN: U530-006
2021-10-06 11:27:20 -07:00
Joel Brobecker
f18c10b78c stop bypassing the updates.sendmail module during testsuite runs
The goal of this commit is to include the updates.sendmail module
in our testing strategy, in order to make sure that the hooks are
passing email data down to the sendmail program without issues.
This will become particularly important when we switch over to
using Python 3.x, because of the strong distinction between bytes
and strings with newer versions of Python which can cause a lot
problems. Hence the need to use this code during our testing.

The main strategy introduced by this commit to achieve this is
fairly simple: The testsuite framework introduces a new minimal
script to be called in place of the standard sendmail. A new
environment variable called GIT_HOOKS_SENDMAIL is introduced
allowing the testsuite to tell the hooks to use its own (fake)
sendmail instead of the system one. With that in place,
the old code bypassing the use of updates.sendmail can be removed,
thus allowing the testsuite to include it as part of the testing.
The testsuite's (fake) sendmail script was written in a way to
mimick the old bypassing code, so there is no change in output.

Parallel to that, the hooks are enhanced to check that we can
indeed find sendmail, and otherwise return immediately with
an error if not. This way, we avoid emails silently being
dropped due to the missing sendmail.

A couple of testcases are also added to double-check some
specific error situations.

Note that I tried to think of ways to split this patch into
smaller individual parts, but couldn't really find a way to
do so in a meaningful way, while at the same time producing
a commit where the coverage report stays clean (0 lines missed).

TN: U530-006 (transition to Python 3.x)
TN: U924-032 (test for sendmail not found)
TN: U924-034 (test for sendmail override when in testsuite mode)
Change-Id: I74b993592ec6d701347bbca5283a42e037411f1c
2021-09-24 17:41:10 -07:00
Joel Brobecker
26ee444039 sendmail.py: Remove fallback on smtplib
The implementation of this module was originally inherited from
gnatpython, where it was trying first to call sendmail, and if
not available, then fallback on using Python's smtplib instead.

This commit removes support for using smtplib, and instead assumes
that sendmail is always available.

The reasons for this change are two-fold:

  - For all the users of these scripts I know of, sendmail is always
    available, so we haven't really used the smtplib fallback.

  - While this code is currently excluded during testing (to avoid
    sending emails while running the testsuite), I'd like to enhance
    our testing strategy to start including this code as part of
    the testing. In particular, one thing we can do is for the testuite
    to eventually provide its own version of a sendmail program that
    would dump the traces to stdout rather than actually send an email.

    On the other hand, if we were to keep smtplib support as a fallback,
    I do not see how we could test that part without actually having it
    send email, something we absolutely do not want.

    This is related to the effort of moving to Python 3.x, where Python
    now makes a strong distinction between bytes and strings when
    passing data between processes. With Python 3.x, it's much more
    important to always test that data is passed correctly.

TN: U530-006
Change-Id: Ic2153be62a80906dce709fb3d622e1194ca7c869
2021-09-24 09:09:37 -07:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Simon Marchi
a2909b2c8d Convert print statements to print function
In preparation for the transition to Python 3, convert to using the
print function.  The special import

    from __future__ import print_function

in Python 2.7 makes "print" become the function and not the statement.
In Python 3, it has no effect.  Once the transition is done and we
exclusively use Python 3, we can simply remove the imports.

The testsuite shows no regressions.
2020-11-22 19:29:38 -05:00
Joel Brobecker
17e00b6db9 sendmail.py: Remove dependency on gnatpython...
... to facilitate deployment at non-AdaCore sites.
2014-12-06 12:53:21 +04:00
Joel Brobecker
e079ab73ba Replace use of gnatpython.sendmail module by updates.sendmail.
This is part of the effort trying to remove the dependency on
gnatpython to facilitate the deployment of those scripts outside
of AdaCore.
2014-12-06 12:20:27 +04:00
Joel Brobecker
0a48294a5a Use gnatpython's sendmail module for sending emails.
And since this module appears to be a little too recent to be part
of the latest gnatpython release, make a copy of that module in
our repository as well, to be used as a fallback.

For LC27-008.
2012-12-27 09:04:30 +01:00