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