diff --git a/GenReport/NotoSansSCRegular.ttf b/GenReport/NotoSansSCRegular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..6599a2be043a5573a9048b1b9ccda1c868ad409d Binary files /dev/null and b/GenReport/NotoSansSCRegular.ttf differ diff --git a/GenReport/README.md b/GenReport/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f4ae80572e8bcaa8120d772bfe232d086fe066f9 --- /dev/null +++ b/GenReport/README.md @@ -0,0 +1,27 @@ +# OSAPIChecker + +#### 介绍 +json结果转pdf工具 + +#### 依赖安装 + +1. pip3 install reportlab + +#### 使用说明 +1. 基本用法,直接执行使用默认路径生成pdf + ```shell + cd Pdf + ./pdf.py + ``` + +2. 使用参数指定文件路径 + - -r : 指定pdf生成结果路径 + - -l : 指定运行库检查结果文件路径 + - -f : 指定文件系统层次结构检查结果文件路径 + - -c : 指定常用命令检查结果文件路径 + - -s : 指定服务检查结果文件路径 + + ```shell + cd Pdf + ./pdf.py -r ./result.pdf -l ../Outputs/libchecker-output.json -f ../Outputs/fs.json -c ../Outputs/cmd.json -s ../Outputs/service_result.json + ``` diff --git a/GenReport/pdf.py b/GenReport/pdf.py new file mode 100755 index 0000000000000000000000000000000000000000..658aa7dc1f3b0b409448ccfde008644c73aec48f --- /dev/null +++ b/GenReport/pdf.py @@ -0,0 +1,590 @@ +#!/usr/bin/python3 + +from pdfmaker import PdfMaker +from reportlab.platypus import PageBreak +from reportlab.lib import colors # 颜色模块 +from reportlab.platypus import Spacer +import json +import argparse +import os + +total_width = 700 +table_background_color = '#d5dae6' + +g_env = "../Outputs/environments-info.json" +g_lib = "../Outputs/libchecker-output.json" +g_fs = "../Outputs/fs.json" +g_cmd = "../Outputs/cmd.json" +g_server = "../Outputs/service_result.json" +g_result = "./操作系统应用编程接口要求标准符合性测试报告.pdf" +g_isConform = "符合" + +#table_background_color = '#87CEEB' +default_style = [ + ('FONTNAME', (0, 0), (-1, -1), 'SimSun'), # 字体 + ('ALIGN', (0, 0), (-1, -1), 'CENTER'), # 水平居中 + ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), # 垂直居中对齐 + # ('ALIGN', (0, 1), (-1, -1), 'CENTER'), # 第二行到最后一行左右左对齐 + ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), # 所有表格上下居中对齐 + ('TEXTCOLOR', (0, 0), (-1, -1), colors.darkslategray), # 设置表格内文字颜色 + ('GRID', (0, 0), (-1, -1), 0.5, colors.black), # 设置表格框线为grey色,线宽为0.5 + ] + +home_table_style = [ + ('FONTNAME', (0, 0), (-1, -1), 'SimSun'), # 字体 + ('FONTSIZE', (0, 0), (-1, -1), 20), + ('ALIGN', (0, 0), (-1, -1), 'CENTER'), # 第一行水平居中 + ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), # 所有表格上下居中对齐 + ('ALIGN', (0, 0), (0, -1), 'RIGHT'), + ('ALIGN', (1, 0), (1, -1), 'CENTER'), +] + +def make_pdf_cover(content): + # 添加标题 + content.append(Spacer(1, 30)) + content.append(PdfMaker.draw_title('《操作系统应用编程接口要求》\n标准符合性测试报告',30)) + + # 添加日期等内容 + content.append(Spacer(1, 50)) + + if not os.path.exists(g_env): + print("未发现测试环境结果文件") + content.append(PdfMaker.draw_little_title('未发现测试环境结果文件', 12, colors.red)) + return + + with open(g_env,'r',encoding='utf8') as fp: + json_data = json.load(fp) + data = [ + ('产品名称:', json_data["测试对象"]["系统名称"]), + ('产品版本:', json_data["测试对象"]["版本"]), + ('测试日期:', json_data["测试时间"]) + ] + content.append(PdfMaker.draw_table(home_table_style, totalWidth=500, rates=[2,7], *data)) + + # 添加检测机构 + content.append(Spacer(1, 100)) + + unit = json_data["送测单位"] + content.append(PdfMaker.draw_title(unit,20)) + +def make_pdf_test_env(content): + # 添加小标题 + content.append(PdfMaker.draw_little_title('一、测试环境')) + + if not os.path.exists(g_env): + print("未发现测试环境结果文件") + content.append(PdfMaker.draw_little_title('未发现测试环境结果文件', 12, colors.red)) + return + + data = [] + with open(g_env,'r',encoding='utf8') as fp: + json_data = json.load(fp) + data = [ + ('测试对象', '系统名称', json_data["测试对象"]["系统名称"]), + ('测试对象', '版本', json_data["测试对象"]["版本"]), + ('送测单位', '送测单位', json_data["送测单位"]), + ('系统环境', '内核版本', json_data["系统环境"]["内核版本"]), + ('系统环境', '编译器版本', json_data["系统环境"]["编译器版本"]), + ('系统环境', 'Python版本', json_data["系统环境"]["Python版本"]), + ('环境配置', '机器型号', json_data["环境配置"]["CPU型号"]), + ('环境配置', 'CPU指令集', json_data["环境配置"]["CPU指令集"]), + ('环境配置', 'CPU型号', json_data["环境配置"]["CPU型号"]), + ('环境配置', '内存', json_data["环境配置"]["内存"]), + ('环境配置', '硬盘', json_data["环境配置"]["硬盘"]), + ('环境配置', '固件', json_data["环境配置"]["固件"]), + ('测试工具', '名称', json_data["测试工具"]["名称"]), + ('测试工具', '版本', json_data["测试工具"]["版本"]), + ('测试时间', '测试时间', json_data["测试时间"]), + ] + + extra_style = default_style + [ + ('SPAN', (0, 0), (0, 1)), + ('SPAN', (0, 2), (1, 2)), + ('SPAN', (0, 3), (0, 5)), + ('SPAN', (0, 6), (0, 11)), + ('SPAN', (0, 12), (0, 13)), + ] + + content.append(PdfMaker.draw_table(extra_style, totalWidth=total_width, rowHeight=27, rates=[1,1,3], *data)) + + + +def make_pdf_lib(content): + content.append(Spacer(1, 10)) + # 1.运行库 + content.append(PdfMaker.draw_little_title('1.运行库', 15)) + content.append(Spacer(1, 10)) + + if not os.path.exists(g_lib): + print("未发现运行库检查结果文件") + content.append(PdfMaker.draw_little_title('未发现运行库检查结果文件', 12, colors.red)) + return + + # (1)库包检查 + content.append(PdfMaker.draw_little_title('(1)库包检查', 12)) + # 添加表格 + data = [ + ('包名', '检测信息', '--', '--', '--'), + ('包名', '检测信息', '--', '--', '--'), + ] + + with open(g_lib,'r',encoding='utf8') as fp: + json_data = json.load(fp) + row = 2 + for r in json_data: + + require_version = json_data[r]["Required version"] + level = json_data[r]["Level"] + data.append((r, '版本要求', '级别', '--', '--')) + data.append((r, require_version, level, '--', '--')) + data.append((r, '二进制包名', '当前版本', '--', '测试结果')) + + # local_version = "-" + # status = "" + for pack in json_data[r]["Binary package"]: + if isinstance(json_data[r]["Binary package"][pack], dict): + for lib in json_data[r]["Binary package"][pack]: + local_version = json_data[r]["Binary package"][pack][lib]["version"] + status = json_data[r]["Binary package"][pack][lib]["status"] + + if status == "compatible" : + status = "通过" + elif status == "not installed": + continue + else: + status = "不通过" + data.append((r, lib, local_version, '--', status)) + + data.append((r, '共享对象名', '存储路径', '归属包名', '测试结果')) + if isinstance(json_data[r]["Shared library"],dict): + for shared in json_data[r]["Shared library"]: + result = json_data[r]["Shared library"][shared]["status"] + if result == "compatible" : + result = "通过" + else: + result = "不通过" + + belongs = "-" + + if json_data[r]["Shared library"][shared]["belongs"] != "None": + belongs = json_data[r]["Shared library"][shared]["belongs"] + path = json_data[r]["Shared library"][shared]["path"] + if len(path) > 65: + path_list =list(path) + path_list.insert(60, '\n') + path = ''.join(path_list) + data.append((r, shared, path, belongs, result)) + + lib_table_style = default_style + [ + ('FONTSIZE', (0, 0), (-1, 1), 15), # 第一,二行的字体大小 + ('FONTSIZE', (0, 2), (-1, -1), 10), # 第三行到最后一行的字体大小 + ('BACKGROUND', (0, 0), (-1, 0), table_background_color), # 设置第一行背景颜色 + ('BACKGROUND', (0, 1), (-1, 1), table_background_color), # 设置第二行背景颜色 + ('SPAN', (0, 0), (0, 1)), # 合并第一列一二行 + ('SPAN', (1, 0), (-1, 1)), # 合并第四列一二行 + ] + + row = 10 + i = 2 + new_data = data[0:row] + is_merge = False + while i < row: + if new_data[i][1] == "版本要求": + lib_table_style.append(('BACKGROUND', (1, i), (-1, i), table_background_color)) + lib_table_style.append(('SPAN', (2, i), (-1, i))) + lib_table_style.append(('SPAN', (2, i+1), (-1, i+1))) + if new_data[i][1] == "二进制包名": + lib_table_style.append(('BACKGROUND', (1, i), (-1, i), table_background_color)) + is_merge = True + + + if new_data[i][1] == "共享对象名": + lib_table_style.append(('BACKGROUND', (1, i), (-1, i), table_background_color)) + + is_merge = False + + if is_merge: + lib_table_style.append(('SPAN', (2, i), (3, i))) + + if new_data[i][-1] == "不通过": + lib_table_style.append(('TEXTCOLOR', (0, i), (-1, i), colors.red)) + + i += 1 + + content.append(PdfMaker.draw_mul_table(lib_table_style, totalWidth=total_width, rates=[2,3,7,2,1], *new_data)) + while row