Exemple #1
0
 def create_html_report(self, force_write):
     contents = ''
     # Use the script corresponding to the result format
     contents += self.get_content_from_file('/%s_format.html' % self.result_format)
     # Use all scripts under html/partials/
     contents += self.get_content_from_folder('partials')
     contents += self.get_content_from_folder('partials/%s' % self.provider)
     # Use all scripts under html/summaries/
     contents += self.get_content_from_folder('summaries')
     contents += self.get_content_from_folder('summaries/%s' % self.provider)
     new_file, first_line = get_filename('REPORT', self.report_name, self.report_dir)
     print_info('Creating %s' % new_file)
     if prompt_for_overwrite(new_file, force_write):
         if os.path.exists(new_file):
             os.remove(new_file)
         with open(os.path.join(self.html_data_path, 'report.html')) as f:
             with open(new_file, 'wt') as nf:
                 for line in f:
                     newline = line
                     newline = newline.replace('<!-- CONTENTS PLACEHOLDER -->', contents)
                     newline = newline.replace('<!-- RESULTS PLACEHOLDER -->',
                                               get_filename('RESULTS',
                                                            self.report_name,
                                                            self.report_dir,
                                                            relative_path=True)[0])
                     newline = newline.replace('<!-- EXCEPTIONS PLACEHOLDER -->',
                                               get_filename('EXCEPTIONS',
                                                            self.report_name,
                                                            self.report_dir,
                                                            relative_path=True)[0])
                     newline = newline.replace('<!-- SQLITE JS PLACEHOLDER -->',
                                               '{}/sqlite.js'.format(DEFAULT_INCLUDES_DIRECTORY))
                     nf.write(newline)
     return new_file
    def __open_file(config_filename, force_write):
        """

        :param config_filename:
        :param force_write:
        :param quiet:
        :return:
        """
        if prompt_for_overwrite(config_filename, force_write):
            try:
                config_dirname = os.path.dirname(config_filename)
                if not os.path.isdir(config_dirname):
                    os.makedirs(config_dirname)
                return open(config_filename, 'wt')
            except Exception as e:
                print_exception(e)
        else:
            return None