2021-05-19 18:07:42 +02:00
|
|
|
""" Test report """
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from mylib.report import Report
|
2023-01-16 12:56:12 +01:00
|
|
|
from mylib.scripts.helpers import add_email_opts, get_opts_parser, init_email_client, init_logging
|
2021-05-19 18:07:42 +02:00
|
|
|
|
2023-01-16 12:56:12 +01:00
|
|
|
log = logging.getLogger("mylib.scripts.report_test")
|
2021-05-19 18:07:42 +02:00
|
|
|
|
2021-05-19 19:19:57 +02:00
|
|
|
|
|
|
|
def main(argv=None): # pylint: disable=too-many-locals,too-many-statements
|
2023-01-16 12:56:12 +01:00
|
|
|
"""Script main"""
|
2021-05-19 18:07:42 +02:00
|
|
|
if argv is None:
|
|
|
|
argv = sys.argv[1:]
|
|
|
|
|
|
|
|
# Options parser
|
|
|
|
parser = get_opts_parser(just_try=True)
|
|
|
|
add_email_opts(parser)
|
|
|
|
|
2023-01-16 12:56:12 +01:00
|
|
|
report_opts = parser.add_argument_group("Report options")
|
2021-05-19 18:07:42 +02:00
|
|
|
|
|
|
|
report_opts.add_argument(
|
2023-01-16 12:56:12 +01:00
|
|
|
"-t", "--to", action="store", type=str, dest="report_rcpt", help="Send report to this email"
|
2021-05-19 18:07:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
|
|
if not options.report_rcpt:
|
|
|
|
parser.error("You must specify a report recipient using -t/--to parameter")
|
|
|
|
|
|
|
|
# Initialize logs
|
2023-01-16 12:56:12 +01:00
|
|
|
report = Report(rcpt_to=options.report_rcpt, subject="Test report")
|
|
|
|
init_logging(options, "Test Report", report=report)
|
2021-05-19 18:07:42 +02:00
|
|
|
|
|
|
|
email_client = init_email_client(options)
|
|
|
|
report.send_at_exit(email_client=email_client)
|
|
|
|
|
2023-01-16 12:56:12 +01:00
|
|
|
logging.debug("Test debug message")
|
|
|
|
logging.info("Test info message")
|
|
|
|
logging.warning("Test warning message")
|
|
|
|
logging.error("Test error message")
|