Ejemplo n.º 1
0
    def _render(self, result, output_path):
        context = ReportModel(result=result, html_output=output_path)
        template = pkg_resources.resource_string(
            'avocado_result_html', 'resources/templates/report.mustache')

        # pylint: disable=E0611
        try:
            if hasattr(pystache, 'Renderer'):
                renderer = pystache.Renderer('utf-8', 'utf-8')
                report_contents = renderer.render(template, context)
            else:
                from pystache import view
                v = view.View(template, context)
                report_contents = v.render('utf8')
        except UnicodeDecodeError as details:
            # FIXME: Remove me when UnicodeDecodeError problem is fixed
            LOG_UI.critical("\n" + ("-" * 80))
            LOG_UI.critical("HTML failed to render the template: %s\n\n",
                            template)
            LOG_UI.critical("-" * 80)
            LOG_UI.critical("%s:\n\n", details)
            LOG_UI.critical("%r", getattr(details, "object",
                                          "object not found"))
            LOG_UI.critical("-" * 80)
            raise

        with codecs.open(output_path, 'w', 'utf-8') as report_file:
            report_file.write(report_contents)
Ejemplo n.º 2
0
    def _render_report(self):
        context = ReportModel(json_input=self.json, html_output=self.output)
        base_path = os.path.dirname(sys.modules[__name__].__file__)
        html_resources_path = os.path.join(base_path, 'resources',
                                           'htmlresult')
        template = os.path.join(html_resources_path, 'templates',
                                'report.mustache')

        # pylint: disable=E0611
        try:
            if hasattr(pystache, 'Renderer'):
                renderer = pystache.Renderer('utf-8', 'utf-8')
                report_contents = renderer.render(
                    open(template, 'r').read(), context)
            else:
                from pystache import view
                v = view.View(open(template, 'r').read(), context)
                report_contents = v.render('utf8')  # encodes into ascii
                report_contents = codecs.decode("utf8")  # decode to unicode
        except UnicodeDecodeError as details:
            # FIXME: Removeme when UnicodeDecodeError problem is fixed
            import logging
            ui = logging.getLogger("avocado.app")
            ui.critical("\n" + ("-" * 80))
            ui.critical("HTML failed to render the template: %s\n\n",
                        open(template, 'r').read())
            ui.critical("-" * 80)
            ui.critical("%s:\n\n", details)
            ui.critical("%r\n\n", self.json)
            ui.critical("%r", getattr(details, "object", "object not found"))
            ui.critical("-" * 80)
            raise

        static_basedir = os.path.join(html_resources_path, 'static')
        output_dir = os.path.dirname(os.path.abspath(self.output))
        utils_path.init_dir(output_dir)
        for resource_dir in os.listdir(static_basedir):
            res_dir = os.path.join(static_basedir, resource_dir)
            out_dir = os.path.join(output_dir, resource_dir)
            if os.path.exists(out_dir):
                shutil.rmtree(out_dir)
            shutil.copytree(res_dir, out_dir)
        with codecs.open(self.output, 'w', 'utf-8') as report_file:
            report_file.write(report_contents)

        if self.args is not None:
            if getattr(self.args, 'open_browser', False):
                # if possible, put browser in separate process group, so
                # keyboard interrupts don't affect browser as well as Python
                setsid = getattr(os, 'setsid', None)
                if not setsid:
                    setsid = getattr(os, 'setpgrp', None)
                inout = file(os.devnull, "r+")
                cmd = ['xdg-open', self.output]
                subprocess.Popen(cmd,
                                 close_fds=True,
                                 stdin=inout,
                                 stdout=inout,
                                 stderr=inout,
                                 preexec_fn=setsid)
Ejemplo n.º 3
0
    def _render_report(self):
        context = ReportModel(result=self,
                              html_output=self.output)
        template = pkg_resources.resource_string(
            'avocado.core',
            'resources/htmlresult/templates/report.mustache')

        # pylint: disable=E0611
        try:
            if hasattr(pystache, 'Renderer'):
                renderer = pystache.Renderer('utf-8', 'utf-8')
                report_contents = renderer.render(template, context)
            else:
                from pystache import view
                v = view.View(template, context)
                report_contents = v.render('utf8')  # encodes into ascii
                report_contents = codecs.decode("utf8")  # decode to unicode
        except UnicodeDecodeError as details:
            # FIXME: Removeme when UnicodeDecodeError problem is fixed
            import logging
            ui = logging.getLogger("avocado.app")
            ui.critical("\n" + ("-" * 80))
            ui.critical("HTML failed to render the template: %s\n\n",
                        template)
            ui.critical("-" * 80)
            ui.critical("%s:\n\n", details)
            ui.critical("%r", getattr(details, "object", "object not found"))
            ui.critical("-" * 80)
            raise

        self._copy_static_resources()
        with codecs.open(self.output, 'w', 'utf-8') as report_file:
            report_file.write(report_contents)

        if self.args is not None:
            if getattr(self.args, 'open_browser', False):
                # if possible, put browser in separate process group, so
                # keyboard interrupts don't affect browser as well as Python
                setsid = getattr(os, 'setsid', None)
                if not setsid:
                    setsid = getattr(os, 'setpgrp', None)
                inout = file(os.devnull, "r+")
                cmd = ['xdg-open', self.output]
                subprocess.Popen(cmd, close_fds=True, stdin=inout, stdout=inout,
                                 stderr=inout, preexec_fn=setsid)
Ejemplo n.º 4
0
    def _render_report(self):
        context = ReportModel(json_input=self.json, html_output=self.output)
        html = HTML()
        template = html.get_resource_path('templates', 'report.mustache')

        # pylint: disable=E0611
        if hasattr(pystache, 'Renderer'):
            renderer = pystache.Renderer('utf-8', 'utf-8')
            report_contents = renderer.render(
                open(template, 'r').read(), context)
        else:
            from pystache import view
            v = view.View(open(template, 'r').read(), context)
            report_contents = v.render('utf8')

        static_basedir = html.get_resource_path('static')
        output_dir = os.path.dirname(os.path.abspath(self.output))
        utils_path.init_dir(output_dir)
        for resource_dir in os.listdir(static_basedir):
            res_dir = os.path.join(static_basedir, resource_dir)
            out_dir = os.path.join(output_dir, resource_dir)
            if os.path.exists(out_dir):
                shutil.rmtree(out_dir)
            shutil.copytree(res_dir, out_dir)
        with codecs.open(self.output, 'w', 'utf-8') as report_file:
            report_file.write(report_contents)

        if self.args is not None:
            if getattr(self.args, 'open_browser'):
                # if possible, put browser in separate process group, so
                # keyboard interrupts don't affect browser as well as Python
                setsid = getattr(os, 'setsid', None)
                if not setsid:
                    setsid = getattr(os, 'setpgrp', None)
                inout = file(os.devnull, "r+")
                cmd = ['xdg-open', self.output]
                subprocess.Popen(cmd,
                                 close_fds=True,
                                 stdin=inout,
                                 stdout=inout,
                                 stderr=inout,
                                 preexec_fn=setsid)