def initial_reporting(config, run_tracker):
    """Sets up the initial reporting configuration.

  Will be changed after we parse cmd-line flags.
  """
    reports_dir = config.get('reporting',
                             'reports_dir',
                             default=os.path.join(
                                 config.getdefault('pants_workdir'),
                                 'reports'))
    link_to_latest = os.path.join(reports_dir, 'latest')
    if os.path.exists(link_to_latest):
        os.unlink(link_to_latest)

    run_id = run_tracker.run_info.get_info('id')
    if run_id is None:
        raise ReportingError('No run_id set')
    run_dir = os.path.join(reports_dir, run_id)
    safe_rmtree(run_dir)

    html_dir = os.path.join(run_dir, 'html')
    safe_mkdir(html_dir)
    os.symlink(run_dir, link_to_latest)

    report = Report()

    # Capture initial console reporting into a buffer. We'll do something with it once
    # we know what the cmd-line flag settings are.
    outfile = StringIO()
    capturing_reporter_settings = PlainTextReporter.Settings(
        outfile=outfile,
        log_level=Report.INFO,
        color=False,
        indent=True,
        timing=False,
        cache_stats=False)
    capturing_reporter = PlainTextReporter(run_tracker,
                                           capturing_reporter_settings)
    report.add_reporter('capturing', capturing_reporter)

    # Set up HTML reporting. We always want that.
    template_dir = config.get('reporting', 'reports_template_dir')
    html_reporter_settings = HtmlReporter.Settings(log_level=Report.INFO,
                                                   html_dir=html_dir,
                                                   template_dir=template_dir)
    html_reporter = HtmlReporter(run_tracker, html_reporter_settings)
    report.add_reporter('html', html_reporter)

    # Add some useful RunInfo.
    run_tracker.run_info.add_info('default_report',
                                  html_reporter.report_path())
    port = ReportingServerManager.get_current_server_port()
    if port:
        run_tracker.run_info.add_info(
            'report_url', 'http://localhost:%d/run/%s' % (port, run_id))

    return report
Example #2
0
def create_run_tracker(info_dir=None):
    """Creates a ``RunTracker`` and starts it.

  :param string info_dir: An optional director for the run tracker to store state; defaults to a
    new temp dir that will be be cleaned up on interpreter exit.
  """
    # TODO(John Sirois): Rework uses around a context manager for cleanup of the info_dir in a more
    # disciplined manner
    info_dir = info_dir or safe_mkdtemp()
    run_tracker = RunTracker(info_dir)
    report = Report()
    run_tracker.start(report)
    return run_tracker
Example #3
0
def default_report(config, run_tracker):
    """Sets up the default reporting configuration."""
    reports_dir = config.get('reporting', 'reports_dir')
    link_to_latest = os.path.join(reports_dir, 'latest')
    if os.path.exists(link_to_latest):
        os.unlink(link_to_latest)

    run_id = run_tracker.run_info.get_info('id')
    if run_id is None:
        raise ReportingError('No run_id set')
    run_dir = os.path.join(reports_dir, run_id)
    safe_rmtree(run_dir)

    html_dir = os.path.join(run_dir, 'html')
    safe_mkdir(html_dir)
    os.symlink(run_dir, link_to_latest)

    report = Report()

    console_reporter_settings = ConsoleReporter.Settings(log_level=Report.INFO,
                                                         color=False,
                                                         indent=True,
                                                         timing=False,
                                                         cache_stats=False)
    console_reporter = ConsoleReporter(run_tracker, console_reporter_settings)

    template_dir = config.get('reporting', 'reports_template_dir')
    html_reporter_settings = HtmlReporter.Settings(log_level=Report.INFO,
                                                   html_dir=html_dir,
                                                   template_dir=template_dir)
    html_reporter = HtmlReporter(run_tracker, html_reporter_settings)

    report.add_reporter('console', console_reporter)
    report.add_reporter('html', html_reporter)

    run_tracker.run_info.add_info('default_report',
                                  html_reporter.report_path())
    port = config.getint('reporting', 'reporting_port', -1)
    run_tracker.run_info.add_info(
        'report_url', 'http://localhost:%d/run/%s' % (port, run_id))

    return report