def add_result_files_table(self): result_files_data = sorted( FileUtils.find_files(self.summary_data.output_dir, regex=".*", full_path_result=True) ) table_type = RenderedTableType.RESULT_FILES header = [HEADER_ROW, HEADER_FILE, HEADER_NO_OF_LINES] gen_tables = ResultPrinter.print_tables( result_files_data, lambda file: (file, len(FileUtils.read_file(file).splitlines())), header=header, print_result=False, max_width=200, max_width_separator=os.sep, tabulate_fmts=DEFAULT_TABLE_FORMATS, ) for table_fmt, table in gen_tables.items(): self.add_table( table_type, TableWithHeader( table_type.header, header, result_files_data, table, table_fmt=table_fmt, colorized=False, branch=None, ), )
def run(self): LOG.info( f"Starting sending latest command data in email.\n Config: {str(self.config)}" ) zip_extract_dest = FileUtils.join_path(os.sep, "tmp", "extracted_zip") ZipFileUtils.extract_zip_file(self.config.email.attachment_file, zip_extract_dest) # Pick file from zip that will be the email's body email_body_file = FileUtils.join_path(os.sep, zip_extract_dest, self.config.email_body_file) FileUtils.ensure_file_exists(email_body_file) email_body_contents: str = FileUtils.read_file(email_body_file) body_mimetype: EmailMimeType = self._determine_body_mimetype_by_attachment( email_body_file) email_service = EmailService(self.config.email.email_conf) try: email_service.send_mail( self.config.email.sender, self.config.email.subject, email_body_contents, self.config.email.recipients, self.config.email.attachment_file, body_mimetype=body_mimetype, override_attachment_filename=self.config.email. attachment_filename, ) except SMTPAuthenticationError as smtpe: ignore_smpth_auth_env: str = OsUtils.get_env_value( EnvVar.IGNORE_SMTP_AUTH_ERROR.value, "") LOG.info( f"Recognized env var '{EnvVar.IGNORE_SMTP_AUTH_ERROR.value}': {ignore_smpth_auth_env}" ) if not ignore_smpth_auth_env: raise smtpe else: # Swallow exeption LOG.exception( f"SMTP auth error occurred but env var " f"'{EnvVar.IGNORE_SMTP_AUTH_ERROR.value}' was set", exc_info=True, ) LOG.info("Finished sending email to recipients")