Exemplo n.º 1
0
    def process(self):
        keys = self.artifact.inputs().keys()
        rb_file = self.artifact.doc.name.replace(".feature", "\.rb")
        matches = [k for k in keys if re.match(re.compile("^%s" % rb_file), k)]

        if len(matches) == 0:
            err_msg = "no file matching %s was found in %s" % (rb_file, keys)
            raise Exception(err_msg)
        if len(matches) > 1:
            err_msg = "too many files matching %s were found in %s: %s" % (rb_file, keys, matches)
            raise Exception(err_msg)

        key = matches[0]
        rb_art = self.artifact.inputs()[key]
        rf = rb_art.filename()
        self.artifact.generate_workfile()
        wf = self.artifact.work_filename()
        command = "%s -r %s %s" % (self.executable(), rf, wf)
        self.log.debug(command)
        env=None
        proc = subprocess.Popen(command, shell=True,
                                cwd=self.artifact.artifacts_dir,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                env=env)
        stdout, stderr = proc.communicate()

        # TODO detect output extension and convert appropriately
        # for now assume HTML
        html = ansi_output_to_html(stdout, self.log)
        self.artifact.data_dict['1'] = html
Exemplo n.º 2
0
    def run(self):
        report_dir = os.path.join(self.controller.logs_dir, "run-%s" %
                                  datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S"))
        latest_report_dir = os.path.join(self.controller.logs_dir, "run-latest")
        report_filename = os.path.join(report_dir, 'index.html')
        shutil.rmtree(report_dir, ignore_errors=True)

        template_dir = os.path.join(os.path.dirname(__file__), 'run_reporter')
        shutil.copytree(template_dir, report_dir)

        formatter = HtmlFormatter()
        js_lexer = JavascriptLexer()

        for doc in self.controller.docs:
            if len(doc.args) > 0:
                doc.args_html = highlight(json.dumps(doc.args, sort_keys=True, indent=4), js_lexer, formatter)
            for a in doc.artifacts:
                if hasattr(a, 'stdout'):
                    html = ansi_output_to_html(a.stdout, self.controller.log)
                    a.stdout_html = """stdout:<br />%s""" % html

        env_data = {}
        j = json.dumps(self.controller.config, sort_keys = True, indent=4)
        html = highlight(j, js_lexer, formatter)

        env_data['dexy_config'] = html
        env_data['docs'] = self.controller.docs
        env_data['controller'] = self.controller

        env = Environment()
        env.loader = FileSystemLoader(os.path.dirname(__file__))
        template = env.get_template('run_reporter_template.html')
        template.stream(env_data).dump(report_filename)

        shutil.rmtree(latest_report_dir, ignore_errors=True)
        shutil.copytree(report_dir, latest_report_dir)