41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
""" 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")
|
|
|
|
|
|
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_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")
|