From 5a8c201079043987945eb260169d56ab68f527c4 Mon Sep 17 00:00:00 2001 From: huangduirong Date: Fri, 31 Dec 2021 03:58:12 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eadvisors/upgrade=5Fcompatibil?= =?UTF-8?q?ity.py=E6=96=87=E4=BB=B6=20advisors/upgrade=5Fcompatibility.py?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=94=A8=E4=BA=8E=E8=A7=A3=E6=9E=90src-openE?= =?UTF-8?q?uler=E4=B8=AD=E5=90=84=E4=B8=AA=E8=BD=AF=E4=BB=B6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E7=9A=84=E5=B7=AE=E5=BC=82=E5=88=86=E6=9E=90=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=B9=B6=E5=AF=BC=E5=87=BA=E5=88=B0=E4=B8=80?= =?UTF-8?q?=E4=B8=AACSV=E6=96=87=E4=BB=B6=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增upgrade_compatibility文件 该文件主要是对upgrade_compatibility.py的命令行封装。 --- advisors/upgrade_compatibility.py | 147 ++++++++++++++++++++++++++++++ command/upgrade_compatibility | 26 ++++++ 2 files changed, 173 insertions(+) create mode 100644 advisors/upgrade_compatibility.py create mode 100644 command/upgrade_compatibility diff --git a/advisors/upgrade_compatibility.py b/advisors/upgrade_compatibility.py new file mode 100644 index 00000000..fd1c08d6 --- /dev/null +++ b/advisors/upgrade_compatibility.py @@ -0,0 +1,147 @@ +#!/usr/bin/python3 +#coding:utf-8 +# ****************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# +# ******************************************************************************/ +""" +This is a script to capture software package upgrade changes in the software upgrade ISSUE. +""" +import os +import sys +import argparse +import csv + +from advisors import gitee + + +# 抓取结果分析数据 +DST_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), "result.csv") + + +def mrkd2json(inp): + """ + Convert the Markdown list to JSON format. + """ + variance_classification = [u"特性变化", u"配置文件", u"ABI差异", u"命令行/功能", u"SPEC文件"] + variance_default_msg = [[u"", u"无", u"不涉及", u"NA", u"新增特性/删除特性/变更特性实现"], + [u"", u"无", u"不涉及", u"NA", u"新增/变更/删除配置项"], + [u"", u"无", u"不涉及", u"NA", u"新增/变更/删除API", + u"新增/变更/删除结构体"], + [u"", u"无", u"不涉及", u"NA", u"新增/变更/删除命令", + u"新增/变更/删除命令选项", u"新增/变更/删除日志输出"], + [u"", u"无", u"不涉及", u"NA", + u"新增/变更/删除 编译依赖、安装依赖、依赖的软件版本变更", + u"拆分软件包方式变更"]] + variance_details = [u"", u"", u"", u"", u""] + line_list = inp.split('\n')[1:] + classification_index = -1 + for line_info in line_list: + table_info = line_info.split('|') + one_line = table_info[1:] + if len(one_line) < 4: + continue + if one_line[0].strip(): + for index, variance in enumerate(variance_classification): + if one_line[0].find(variance) != -1: + classification_index = index + temp_clasify = one_line[1] + temp_detail = one_line[2] + temp_solution = one_line[3] + if ((temp_clasify.strip() in variance_default_msg[classification_index] \ + or temp_clasify.strip().strip("*") in variance_default_msg[classification_index]) \ + and (temp_detail.strip() in variance_default_msg[classification_index] \ + or temp_detail.strip().startswith(u"无"))\ + and (temp_solution.strip() in variance_default_msg[classification_index] \ + or temp_solution.strip().startswith(u"无"))): + continue + variance_details[classification_index] += u"差异项: " + temp_clasify + "\n" + variance_details[classification_index] += u"差异说明: " + temp_detail + "\n" + variance_details[classification_index] += u"影响评估与适配方案: " + temp_solution + "\n\n" + elif classification_index != -1: + temp_clasify = one_line[1] + temp_detail = one_line[2] + temp_solution = one_line[3] + if ((temp_clasify.strip() in variance_default_msg[classification_index] \ + or temp_clasify.strip().strip("*") in variance_default_msg[classification_index]) \ + and (temp_detail.strip() in variance_default_msg[classification_index] \ + or temp_detail.strip().startswith(u"无"))\ + and (temp_solution.strip() in variance_default_msg[classification_index] \ + or temp_solution.strip().startswith(u"无"))): + continue + variance_details[classification_index] += u"差异项: " + temp_clasify + "\n" + variance_details[classification_index] += u"差异说明: " + temp_detail + "\n" + variance_details[classification_index] += u"影响评估与适配方案: " + temp_solution + "\n\n" + + return variance_details + +def process_one_repo(repo): + """ + Main process of the functionality + """ + try: + user_gitee = gitee.Gitee() + except NameError: + sys.exit(1) + issues_list = user_gitee.get_issues(repo, state="all") + if not issues_list: + print("WARNING: Can't find any issues of {pkg}".format(pkg=repo)) + return [] + + template = None + for issue in issues_list: + if issue["issue_type"] == u"开源软件变更管理": + template = issue["body"] + break + if not template: + return [] + variance_details = mrkd2json(template) + return variance_details + +def main(): + """ + Main entrance of the functionality + """ + parameters = argparse.ArgumentParser() + parameters.add_argument("-f", "--path", type=str, help="file path of repo list") + + args = parameters.parse_args() + soft_changes = {} + with open(args.path, "r", encoding="utf-8") as f_repo: + repo_list = list(x for x in list([x.strip().split() for x in f_repo.read().splitlines()]) if len(x) > 0) + repo_size = len(repo_list) + index = 0 + for repo in repo_list: + index += 1 + print("processing %s/%s" % (index, repo_size)) + soft_name = repo[0] + try: + soft_change_info = process_one_repo(soft_name) + if soft_change_info: + soft_changes[soft_name] = process_one_repo(soft_name) + else: + print("processing %s, can not get the upgrade issue." % soft_name) + except Exception as e_msg: + print("processing %s failed. error: %s" % (soft_name, e_msg)) + + rows = [] + rows.append(["name", u"特性变化", u"配置文件", u"ABI差异", u"命令行/功能", u"SPEC文件"]) + for soft_name in soft_changes: + one_row = [soft_name] + one_row.extend(soft_changes[soft_name]) + rows.append(one_row) + with open(DST_FILE, "w+", encoding="utf-8-sig", newline='') as f_out: + writer = csv.writer(f_out) + writer.writerows(rows) + +if __name__ == "__main__": + main() + diff --git a/command/upgrade_compatibility b/command/upgrade_compatibility new file mode 100644 index 00000000..bda46b80 --- /dev/null +++ b/command/upgrade_compatibility @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +#coding:utf-8 +#****************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# +# ******************************************************************************/ +""" +This is a script to capture software package upgrade changes in the software upgrade ISSUE. +""" +from advisors.upgrade_compatibility import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) -- Gitee