|
| 1 | +#!/usr/bin/env python3 |
1 | 2 |
|
2 | 3 |
|
3 | | -import json |
4 | 4 | from datetime import datetime |
5 | 5 | from os.path import normpath |
6 | 6 | from pathlib import Path |
|
27 | 27 | from qc_tool.common import CONFIG |
28 | 28 |
|
29 | 29 |
|
| 30 | +MAX_WORD_LENGTH = 40 |
| 31 | + |
| 32 | + |
| 33 | +def truncate_long_words(sentence, max_length): |
| 34 | + words = sentence.split() |
| 35 | + for word in words: |
| 36 | + if len(word) > max_length: |
| 37 | + for i in range(0, len(word), max_length): |
| 38 | + yield word[i:i+max_length] |
| 39 | + else: |
| 40 | + yield word |
| 41 | + |
| 42 | + |
30 | 43 | def generate_pdf_report(job_report_filepath, job_uuid): |
31 | 44 | job_report = compile_job_report_data(job_uuid) |
32 | 45 |
|
@@ -86,7 +99,8 @@ def footer(canvas, doc): |
86 | 99 | # Add summary table |
87 | 100 | text.append(Paragraph("", styles["Heading1"])) |
88 | 101 | text.append(Paragraph("Report summary", styles["Heading2"])) |
89 | | - status_file = ["File name", job_report["filename"]] |
| 102 | + wrapped_filename = "\n".join(truncate_long_words(job_report["filename"], MAX_WORD_LENGTH)) |
| 103 | + status_file = ["File name", wrapped_filename] |
90 | 104 | status_product = ["Product", job_report["description"]] |
91 | 105 | display_date = datetime.strptime(job_report["job_finish_date"], TIME_FORMAT).strftime("%Y-%m-%d %H:%M:%S") |
92 | 106 | status_date = ["Checked on", display_date] |
@@ -162,7 +176,9 @@ def footer(canvas, doc): |
162 | 176 | messages = [] |
163 | 177 | display_messages = [] |
164 | 178 | for message in messages: |
165 | | - display_messages.append(Paragraph(message, style_body)) |
| 179 | + # Split long words in a message |
| 180 | + wrapped_message = " ".join(truncate_long_words(message, MAX_WORD_LENGTH)) |
| 181 | + display_messages.append(Paragraph(wrapped_message, style_body)) |
166 | 182 |
|
167 | 183 | check_info = [display_ident, |
168 | 184 | display_layers, |
|
0 commit comments