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
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
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
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
def update_reporting(options, is_console_task, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. old_outfile = run_tracker.report.remove_reporter( 'capturing').settings.outfile old_outfile.flush() buffered_output = old_outfile.getvalue() old_outfile.close() log_level = Report.log_level_from_string(options.log_level or 'info') color = not options.no_color timing = options.time cache_stats = options.time # TODO: Separate flag for this? if options.quiet or is_console_task: console_reporter = QuietReporter( run_tracker, QuietReporter.Settings(log_level=log_level, color=color)) else: # Set up the new console reporter. settings = PlainTextReporter.Settings(log_level=log_level, outfile=sys.stdout, color=color, indent=True, timing=timing, cache_stats=cache_stats) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_output) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(options.logdir, '%s.log' % run_id), 'w') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, color=False, indent=True, timing=True, cache_stats=True) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_output) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter)
def update_reporting(options, is_console_task, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. old_outfile = run_tracker.report.remove_reporter('capturing').settings.outfile old_outfile.flush() buffered_output = old_outfile.getvalue() old_outfile.close() log_level = Report.log_level_from_string(options.log_level or 'info') color = not options.no_color timing = options.time cache_stats = options.time # TODO: Separate flag for this? if options.quiet or is_console_task: console_reporter = QuietReporter(run_tracker, QuietReporter.Settings(log_level=log_level, color=color)) else: # Set up the new console reporter. settings = PlainTextReporter.Settings(log_level=log_level, outfile=sys.stdout, color=color, indent=True, timing=timing, cache_stats=cache_stats) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_output) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(options.logdir, '%s.log' % run_id), 'w') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, color=False, indent=True, timing=True, cache_stats=True) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_output) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter)
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
def run(self, lock): # Update the reporting settings, now that we have flags etc. log_level = Report.log_level_from_string(self.options.log_level or 'info') color = not self.options.no_color timing = self.options.time cache_stats = self.options.time # TODO: Separate flag for this? settings_updates_map = { 'console': { 'log_level': log_level, 'color': color, 'timing': timing, 'cache_stats': cache_stats }, 'html': { 'log_level': log_level } } self.run_tracker.update_report_settings(settings_updates_map) # TODO: Do something useful with --logdir. if self.options.dry_run: print '****** Dry Run ******' context = Context(self.config, self.options, self.run_tracker, self.targets, requested_goals=self.requested_goals, lock=lock) # TODO: Time to get rid of this hack. if self.options.recursive_directory: context.log.warn( '--all-recursive is deprecated, use a target spec with the form [dir]:: instead' ) for dir in self.options.recursive_directory: self.add_target_recursive(dir) if self.options.target_directory: context.log.warn( '--all is deprecated, use a target spec with the form [dir]: instead' ) for dir in self.options.target_directory: self.add_target_directory(dir) unknown = [] for phase in self.phases: if not phase.goals(): unknown.append(phase) if unknown: print('Unknown goal(s): %s' % ' '.join(phase.name for phase in unknown)) print('') return Phase.execute(context, 'goals') ret = Phase.attempt(context, self.phases) if self.options.cleanup_nailguns or self.config.get( 'nailgun', 'autokill', default=False): if log: log.debug('auto-killing nailguns') if NailgunTask.killall: NailgunTask.killall(log) return ret
def run(self, lock): # Update the reporting settings, now that we have flags etc. log_level = Report.log_level_from_string(self.options.log_level or 'info') color = not self.options.no_color timing = self.options.time cache_stats = self.options.time # TODO: Separate flag for this? settings_updates_map = { 'console': { 'log_level': log_level, 'color': color, 'timing': timing, 'cache_stats': cache_stats }, 'html': { 'log_level': log_level } } self.run_tracker.update_report_settings(settings_updates_map) # TODO: Do something useful with --logdir. if self.options.dry_run: print '****** Dry Run ******' context = Context( self.config, self.options, self.run_tracker, self.targets, requested_goals=self.requested_goals, lock=lock) # TODO: Time to get rid of this hack. if self.options.recursive_directory: context.log.warn( '--all-recursive is deprecated, use a target spec with the form [dir]:: instead') for dir in self.options.recursive_directory: self.add_target_recursive(dir) if self.options.target_directory: context.log.warn('--all is deprecated, use a target spec with the form [dir]: instead') for dir in self.options.target_directory: self.add_target_directory(dir) unknown = [] for phase in self.phases: if not phase.goals(): unknown.append(phase) if unknown: print('Unknown goal(s): %s' % ' '.join(phase.name for phase in unknown)) print('') return Phase.execute(context, 'goals') ret = Phase.attempt(context, self.phases) if self.options.cleanup_nailguns or self.config.get('nailgun', 'autokill', default = False): if log: log.debug('auto-killing nailguns') if NailgunTask.killall: NailgunTask.killall(log) return ret