Пример #1
0
class TaskSummary(object):
    """Print various stats about the reports"""
    def setup(self, options):
        self.__printer = Printer(options)
        # sanitizer_name.category_name.(new|old)
        self.__data = OrderedDict()

    def process(self, report):
        sanitizer_name = report.sanitizer.name
        category_name = report.category_name
        if not sanitizer_name in self.__data:
            self.__data[sanitizer_name] = OrderedDict()
        if not category_name in self.__data[sanitizer_name]:
            self.__data[sanitizer_name][category_name] = {'new': 0, 'old': 0}
        self.__data[sanitizer_name][category_name]['new' if report.
                                                   is_new else 'old'] += 1

    def teardown(self):
        self.__printer.task_description('Summary:')
        if len(self.__data) < 1:
            self.__printer.task_info('nothing found')
        else:
            for sanitizer_name, categories in sorted(self.__data.items(),
                                                     key=lambda s: s[0]):
                self.__printer.just_print('  ' + sanitizer_name + ':')
                for category_name, count in sorted(categories.items(),
                                                   key=lambda c: c[0]):
                    new = count['new']
                    self.__printer.just_print('    ' + category_name + ': ' +
                                              str(count['old'] + new) + ' (' +
                                              str(new) + ' new)')
        self.__printer.nl()
Пример #2
0
class Enhancitizer(object):
    def __init__(self, options):
        self.__options = options
        self.__printer = Printer(options)
        self.__tasks = []

    def add_tasks(self, task):
        """Add additional tasks that will be executed after the main tasks"""
        self.__tasks.append(task)

    def run(self):
        """Run the enhancitizer"""
        bank = ReportsBank(self.__options)
        self.__printer.welcome() \
                      .settings() \
                      .task_description('Collecting existing reports ...')
        watch = StopWatch().start()
        bank.collect_reports()
        self.__printer.task_info_debug('execution time: ' + str(watch)) \
                      .nl() \
                      .task_description('Extracting new reports ...')
        watch.start()
        for path in self.__options.logfiles_paths:
            bank.extract_reports(path)
        self.__printer.task_info_debug('execution time: ' + str(watch)).nl()
        tasks = [
            TaskEliminateDuplicateReports(bank),  # should be the first thing
            TaskCompactReports(),  # after the elimination, before "real" tasks
            TaskAnalyseReports(),  # after the elimination, before "real" tasks
            TaskCreateTSanBlacklist(),
            TaskBuildSkeleton(),
            TaskCreateCsvSummaries(),
            TaskAddTSanContext(
            ),  # should run late to speed up stack parsing of the previous tasks
            TaskSummary()  # should be the last thing
        ]
        tasks.extend(self.__tasks)
        for task in tasks:
            watch.start()
            if hasattr(task, 'description'):
                self.__printer.task_description(task.description)
            if hasattr(task, 'setup'):
                task.setup(self.__options)
            if hasattr(task, 'process'):
                for report in bank:
                    task.process(report)
            if hasattr(task, 'teardown'):
                task.teardown()
            if hasattr(task, 'description'):
                self.__printer.task_info_debug('execution time: ' +
                                               str(watch)).nl()