Exemple #1
0
 def to_markdown(self) -> str:
     template = get_template('test_meta.md')
     return template.render(date=self.get_date(),
                            time=self.get_time(),
                            platform=self.platform,
                            config=self.config,
                            version=self.version)
Exemple #2
0
def config():
    template = get_template('config.html')

    with open(get_path('config.toml')) as config_file:
        config_lines = config_file.readlines()
        context = {
            'line_count': len(config_lines),
            'config_content': ''.join(config_lines)
        }

    return template.render(context), 200
Exemple #3
0
def send_report_mail(receiver_email: str, receiver_name: str,
                     build_report: BuildReport):
    message = MIMEMultipart('alternative')
    message['Subject'] = 'UfoTest Report'
    message['To'] = receiver_email

    context = {'name': receiver_name, 'report': build_report, 'config': CONFIG}

    text_template = get_template('report_mail.text')
    text = text_template.render(context)
    text_mime = MIMEText(text, 'plain')
    message.attach(text_mime)

    html_template = get_template('report_mail.html')
    html = html_template.render(context)
    html_mime = MIMEText(html, 'html')
    message.attach(html_mime)

    send_mime_multipart(receiver_email, message)
    click.secho('(+) Sent report email to: {}'.format(receiver_email),
                fg='green')
Exemple #4
0
def builds_list():
    reports = []
    for root, folders, files in os.walk(BUILDS_PATH):
        for folder in folders:
            folder_path = os.path.join(root, folder)
            report_json_path = os.path.join(folder_path, 'report.json')

            if os.path.exists(report_json_path):
                with open(report_json_path, mode='r') as report_json_file:
                    report = json.loads(report_json_file.read())
                    reports.append(report)

        break

    sorted_reports = sorted(
        reports,
        key=lambda r: datetime.datetime.fromisoformat(r['start_iso']),
        reverse=True)

    template = get_template('builds_list.html')
    return template.render({'reports': sorted_reports}), 200
Exemple #5
0
def archive_list():
    reports = []
    for root, folders, files in os.walk(ARCHIVE_PATH):
        for folder in folders:
            folder_path = os.path.join(root, folder)
            report_json_path = os.path.join(folder_path, 'report.json')

            # We really need to check for the existence here because of the following case: A test run has been started
            # but is not yet complete. In this case the test folder already exists, but the report does not. In this
            # case attempting to open the file would cause an exception!
            if os.path.exists(report_json_path):
                with open(report_json_path, mode='r') as report_json_file:
                    report = json.loads(report_json_file.read())
                    reports.append(report)

        break

    sorted_reports = sorted(
        reports,
        key=lambda r: datetime.datetime.fromisoformat(r['start_iso']),
        reverse=True)

    template = get_template('archive_list.html')
    return template.render({'reports': sorted_reports}), 200
Exemple #6
0
 def to_markdown(self) -> str:
     template = get_template('assertion_test_result.md')
     return template.render(exit_code=self.exit_code,
                            assertions=self.assertions,
                            detailed=self.detailed,
                            error_count=self.error_count)
Exemple #7
0
 def get_html_template_string(self) -> str:
     template = get_template(self.HTML_TEMPLATE_NAME)
     return template.render({'data': self.data})
Exemple #8
0
 def to_markdown(self) -> str:
     template = get_template('test_report.md')
     return template.render(report=self,
                            meta=self.meta,
                            results=self.results)
Exemple #9
0
 def to_markdown(self) -> str:
     template = get_template('test_report.md')
     return template.render({'report': self})
Exemple #10
0
def plugins():
    template = get_template('plugins.html')

    return template.render({}), 200
Exemple #11
0
def home():
    """
    This method returns the HTML content which will display the home page for the ufotest web interface.
    On default the home page consists of various informative panels, which show the current state of the ufotest
    project, the current installation, the current hardware and a list for both the most recent builds and the most
    recent test reports.

    :return: The rendered string HTML template
    """
    template = get_template('home.html')
    template = CONFIG.pm.apply_filter('home_template', template)

    # The integer amount of how many items to be shown for both the most recent test and most recent build reports.
    recent_count = CONFIG.pm.apply_filter('home_recent_count', 5)

    test_reports = get_test_reports()

    recent_builds = get_build_reports()[:recent_count]
    recent_tests = test_reports[:recent_count]

    # So we derive the summary values about the state of the hardware and firmware from the most recent test report. On
    # default the test reports returned by "get_test_reports" are sorted by recentness, which would mean that we would
    # only need to get the first item from the respective list. BUT, a filter hook applies to the return value of these
    # functions which could mean that possibly a filter is applied which changes the ordering, so to be sure that this
    # is the most recent one, we sort it again.
    if len(recent_tests) != 0:
        most_recent_test_report = sorted(recent_tests,
                                         key=lambda d: d['start_iso'],
                                         reverse=True)[0]

    if len(recent_builds) != 0:
        most_recent_build_report = sorted(recent_builds,
                                          key=lambda d: d['start_iso'],
                                          reverse=True)[0]

    camera_class = CONFIG.pm.apply_filter('camera_class', UfoCamera)
    camera = camera_class(CONFIG)

    status_summary = [
        # UFOTEST INFORMATION
        {
            'id': 'ufotest-version',
            'label': 'UfoTest Version',
            'value': get_version()
        },
        {
            'id': 'installation-folder',
            'label': 'Installation Folder',
            'value': CONFIG.get_path()
        },
        {
            'id': 'report-count',
            'label': 'Total Test Reports',
            'value': len(test_reports)
        },
        {
            'id': 'loaded-plugins',
            'label': 'Loaded Plugins',
            'value': len(CONFIG.pm.plugins)
        },
        False,
        {
            'id': 'repository',
            'label': 'Source Repository',
            'value': f'<a href="{CONFIG.get_repository_url()}">GitHub</a>'
        },
        {
            'id': 'documentation',
            'label': 'Project Documentation',
            'value':
            f'<a href="{CONFIG.get_documentation_url()}">ReadTheDocs</a>'
        },
        False,
        # FIRMWARE / BUILD INFORMATION
        {
            'id': 'firmware-version',
            'label': 'Firmware Version',
            'value': '1.0'
        },
        {
            'id':
            'recent-build',
            'label':
            'Recent Build',
            'value':
            most_recent_build_report['start_iso']
            if len(recent_builds) != 0 else 'No build yet'
        },
        # HARDWARE INFORMATION
        False,
        {
            'id': 'camera-class',
            'label': 'Camera Class',
            'value': str(camera_class.__name__)
        },
        {
            'id':
            'available',
            'label':
            'Camera Available',
            'value':
            f'<i class="fas fa-circle {"green" if camera.poll() else "red"}"> </i>'
        },
        {
            'id': 'hardware-version',
            'label': 'Hardware Version',
            'value': camera.get_prop('hardware_version')
        },
        {
            'id': 'sensor-dimensions',
            'label': 'Sensor Dimensions',
            'value':
            f'{CONFIG.get_sensor_width()} x {CONFIG.get_sensor_height()}'
        },
        {
            'id': 'sensor-version',
            'label': 'Sensor Version',
            'value': camera.get_prop('sensor_version')
        }
    ]
    status_summary = CONFIG.pm.apply_filter('home_status_summary',
                                            status_summary)

    # ~ CALCULATING DISK USAGE
    # TODO: The unit is hardcoded. This could be part of the config. Super low prio though
    used_space = get_folder_size(CONFIG.get_path())

    # https://stackoverflow.com/questions/48929553/get-hard-disk-size-in-python
    _, _, free_space = shutil.disk_usage('/')

    context = {
        'status_summary': status_summary,
        'recent_builds': recent_builds,
        'recent_tests': recent_tests,
        # 13.09.2021: I decided that displaying the amount of used space would be a good idea for the home screen,
        # because now the complete source repo content is saved for each build report and depending how large the
        # source repo is (gigabytes?) This could fill up the disk rather quickly...
        'used_space': used_space,
        'free_space': free_space
    }

    return template.render(context), 200
Exemple #12
0
 def to_html(self) -> str:
     template = get_template('build_report.html')
     return template.render({'report': self})
Exemple #13
0
 def to_string(self) -> str:
     template = get_template('build_report.text')
     return template.render({'report': self})