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