1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 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 enum 17from coreImpl.parser import parser 18from coreImpl.check import check 19from coreImpl.diff import diff 20 21 22class ToolNameType(enum.Enum): 23 COLLECT = 'collect' 24 DIFF = 'diff' 25 CHECK = 'check' 26 COLLECT_H = 'collect_h' 27 COLLECT_FILE = 'collect_file' 28 29 30tool_name_type_set = [ 31 member.value for name_tool, 32 member in ToolNameType.__members__.items() 33] 34 35 36class FormatType(enum.Enum): 37 JSON = 'json' 38 EXCEL = 'excel' 39 40 41format_set = [ 42 member.value for name_format, 43 member in FormatType.__members__.items() 44] 45 46 47def run_tools(options): 48 tool_name = options.tool_name 49 print(tool_name) 50 if tool_name == ToolNameType["COLLECT"].value: 51 parser.parser(options.parser_path) 52 elif tool_name == ToolNameType["DIFF"].value: 53 diff.process_dir(options.diff_path_old, options.diff_path_new, options.output_path) 54 elif tool_name == ToolNameType["CHECK"].value: 55 check.curr_entry(options.path, options.checker, options.output) 56 elif tool_name == ToolNameType['COLLECT_H'].value: 57 parser.parser_direct(options.parser_path) 58 elif tool_name == ToolNameType['COLLECT_FILE'].value: 59 parser.parser_file_level(options.output_path) 60 else: 61 print("工具名称错误") 62 63 64class Config(object): 65 name = 'parser' 66 version = '0.1.0' 67 description = 'Compare the parser the NDKS' 68 commands = [ 69 { 70 "name": "--tool-name", 71 "abbr": "-N", 72 "required": False, 73 "choices": tool_name_type_set, 74 "type": str, 75 "default": ToolNameType["CHECK"].value, 76 "help": "工具名称,命令中不写-N的话,默认为check工具" 77 }, 78 { 79 "name": "--parser-path", 80 "abbr": "-P", 81 "required": False, 82 "type": str, 83 "help": "解析路径" 84 }, 85 { 86 "name": "--output-path", 87 "abbr": "-O", 88 "required": False, 89 "type": str, 90 "help": "工具输出文件路径" 91 }, 92 { 93 "name": "--codecheck--path", 94 "abbr": "--path", 95 "required": False, 96 "type": str, 97 "help": "codecheck解析文件路径" 98 }, 99 { 100 "name": "--check-command", 101 "abbr": "--checker", 102 "required": False, 103 "type": str, 104 "help": "校验命令" 105 }, 106 { 107 "name": "--check-output", 108 "abbr": "--output", 109 "required": False, 110 "type": str, 111 "help": "输出路径" 112 }, 113 { 114 "name": "--diff-path-old", 115 "abbr": "-old", 116 "required": False, 117 "type": str, 118 "help": "旧文件路径" 119 }, 120 { 121 "name": "--diff-path-new", 122 "abbr": "-new", 123 "required": False, 124 "type": str, 125 "help": "新文件路径" 126 } 127 128 ] 129