Esempio n. 1
0
 def __create_resources(report_dir):
     """ Create and write the resources. """
     resource_manager = pkg_resources.ResourceManager()
     resource_module = app.__name__
     for resource_type, encoding in (('img', None), ('dist', None), ('html', 'utf-8')):
         resource_dir = (report_dir / resource_type) if resource_type != 'html' else report_dir
         filesystem.create_dir(resource_dir)
         for resource in resource_manager.resource_listdir(resource_module, resource_type):
             filename = resource_dir / resource
             contents = resource_manager.resource_string(resource_module, resource_type + '/' + resource)
             mode = 'w' if encoding else 'wb'
             contents = contents.decode(encoding) if encoding else contents
             filesystem.write_file(contents, filename, mode, encoding)
Esempio n. 2
0
    def __create_report(cls, quality_report, report_dir, create_resources: bool = True):
        """ Format the quality report to HTML and write the files in the report folder. """
        report_dir = pathlib.Path(report_dir or '.').resolve()
        filesystem.create_dir(report_dir)
        filesystem.create_dir(report_dir / 'json')
        if create_resources:
            cls.__create_resources(report_dir)
        json_files = dict(metrics=formatting.MetricsFormatter,
                          meta_history=formatting.MetaMetricsHistoryFormatter,
                          meta_data=formatting.MetaDataJSONFormatter)
        for filename, formatter in json_files.items():
            cls.__create_json_file(quality_report, report_dir, formatter, filename)

        cls.__create_trend_images(quality_report, report_dir)
Esempio n. 3
0
    def __create_trend_images(cls, quality_report, report_dir):
        """ Retrieve and write the trend images. """
        style = pygal.style.Style(background='transparent', plot_background='transparent')
        dates = ''
        filesystem.create_dir(report_dir / 'chart')
        for metric in quality_report.metrics():
            line_chart = pygal.Line(style=style, range=metric.y_axis_range())
            line_chart.add('', metric.recent_history(), stroke_style={'width': 2})
            image = line_chart.render_sparkline()
            filename = report_dir / 'chart' / '{0!s}.svg'.format(metric.id_string())
            filesystem.write_file(image, filename, mode='wb', encoding=None)
            cls.__save_metric_long_history(metric, report_dir)
            if not dates:
                dates = metric.get_long_history_dates()

        filename = report_dir / 'json' / 'dates.txt'
        filesystem.write_file(dates, filename, mode='w', encoding=None)