#!/usr/bin/env python3
# coding: utf-8
"""
Copyright (c) 2024 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: utils for test suite
"""
import json
import os
def generate_html_table(data):
table_rows = ""
for project, items in data.items():
for item_idx, item in enumerate(items):
if item_idx == 0:
table_rows = ''.join([table_rows, f"
| {project} | "])
else:
table_rows = ''.join([table_rows, "
"])
if item['committer'] is None:
table_rows = ''.join([table_rows, f"| {item['title']} | "])
else:
table_rows = ''.join([table_rows, f"{item['title']} | "])
table_rows = ''.join([table_rows, f"{item['committer']} | "])
table_rows = ''.join([table_rows, f"{item['commit_time_str']} | "])
table_rows = ''.join([table_rows, f"点击查看 |
\n"])
return table_rows
def get_table_style():
table_style = f"""
"""
return table_style
def render_html(data):
table_rows = generate_html_table(data)
table_style = get_table_style()
html = f"""
提交记录
{table_style}
提交记录
| 仓库 |
描述 |
作者 |
时间 |
链接 |
{table_rows}
"""
return html
def get_result():
data_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data.txt')
with open(data_file, 'r', encoding='utf-8') as file:
lines = file.readlines()
data = {}
for line in lines:
item = json.loads(line)
repo_name = item['repo_name']
if repo_name in data:
data[repo_name].append(item)
else:
data[repo_name] = [item]
html = render_html(data)
commit_log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'commit_log.html')
with open(commit_log_file, 'w', encoding='utf-8') as file:
file.write(html)
if __name__ == '__main__':
get_result()