python-mylib/mylib/scripts/report_test.py

47 lines
1.2 KiB
Python
Raw Normal View History

""" Test report """
import logging
import sys
from mylib.report import Report
from mylib.scripts.helpers import add_email_opts, get_opts_parser, init_email_client, init_logging
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
"""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_recipient",
help="Send report to this email",
)
options = parser.parse_args()
if not options.report_recipient:
parser.error("You must specify a report recipient using -t/--to parameter")
# Initialize logs
report = Report(options=options, 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")