def _render_html()

in azdev/operations/cmdcov/cmdcov.py [0:0]


    def _render_html(self):
        """
        :return: Return a HTML string
        """
        html_path = self.get_html_path()
        description = 'Command' if self.level == 'command' else 'Command Argument'
        j2_loader = FileSystemLoader(self.cmdcov_path)
        env = Environment(loader=j2_loader)
        j2_tmpl = env.get_template('./index.j2')
        for item in self.command_test_coverage.values():
            color, percentage = self._get_color(item)
            item.append({'color': color, 'percentage': percentage})
        total = self.command_test_coverage.pop('Total')

        content = j2_tmpl.render(description=description,
                                 enable_cli_own=self.enable_cli_own,
                                 date=self.date,
                                 Total=total,
                                 command_test_coverage=self.command_test_coverage)
        index_html = os.path.join(html_path, 'index.html')
        with open(index_html, 'w', encoding=ENCODING) as f:
            f.write(content)

        # render child html
        print("\033[31m" + "Render test coverage report".center(self.width, self.fillchar) + "\033[0m")
        time.sleep(0.1)
        for module, coverage in tqdm(self.command_test_coverage.items()):
            if coverage:
                self._render_child_html(module, coverage, self.all_untested_commands[module])

        # copy source
        css_source = os.path.join(self.cmdcov_path, 'component.css')
        ico_source = os.path.join(self.cmdcov_path, 'favicon.ico')
        js_source = os.path.join(self.cmdcov_path, 'component.js')
        try:
            shutil.copy(css_source, html_path)
            shutil.copy(ico_source, html_path)
            shutil.copy(js_source, html_path)
        except IOError as e:
            logger.error("Unable to copy file %s", e)
        except Exception:  # pylint: disable=broad-except
            logger.error("Unexpected error: %s", sys.exc_info())

        return index_html