• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import json
17import re
18import openpyxl as op
19from utils.constants import label_comparison_dist
20
21
22def get_start_characters(target_character):
23    pattern = r'([a-z]*)'
24
25    match = re.search(pattern, target_character)
26    if match:
27        return match.group()[:match.end()]
28    else:
29        return ''
30
31
32# 剩余字符
33def get_remaining_characters(start_character, target_character):
34    return target_character[target_character.index(start_character) + len(start_character):]
35
36
37def json_file_data(file_path):  # json文件转为dict数据
38    with open(file_path, 'r', encoding='utf-8') as file:
39        dict_data = json.load(file)
40        file.close()
41
42    return dict_data
43
44
45def label_type_conversion(tagged_value):
46    if tagged_value == '':
47        return False
48    if tagged_value == '-1':
49        return False
50    if not tagged_value:
51        return False
52    return True
53
54
55def get_check_labels(doc_info: dict, label_list):
56    if len(doc_info) > 0:
57        result = {}
58        for label in label_list:
59            result[label_comparison_dist.get(label)] = doc_info[label_comparison_dist.get(label)]
60        return result
61    else:
62        return {}
63
64
65def generate_excel(result_info_list: list, output_address):
66    data = []
67    for diff_info in result_info_list:
68        info_data = [diff_info.file_path, diff_info.error_type, diff_info.defined_text, diff_info.position,
69                     diff_info.error_info]
70        data.append(info_data)
71    wb = op.Workbook()
72    ws = wb['Sheet']
73    ws.append(['文件路径', '错标类型', 'api信息', '位置信息', '漏标详情'])
74    for title in data:
75        d = title[0], title[1], title[2], title[3], title[4]
76        ws.append(d)
77    wb.save(output_address)
78
79
80def get_position_information(pos: dict):
81    return 'line: ' + str(pos['line']) + ', character: ' + str(pos['character'])
82
83
84def set_label_to_result(message, label, mutex_label):
85    return message.replace('$', label).replace('&', mutex_label)
86
87
88def get_js_doc_info(js_doc_info_list: list):
89    if len(js_doc_info_list) > 0:
90        return js_doc_info_list[len(js_doc_info_list) - 1]
91    return None
92
93