|
| 1 | +# Copyright (C) Jan 2020 Mellanox Technologies Ltd. All rights reserved. |
| 2 | +# |
| 3 | +# This software is available to you under a choice of one of two |
| 4 | +# licenses. You may choose to be licensed under the terms of the GNU |
| 5 | +# General Public License (GPL) Version 2, available from the file |
| 6 | +# COPYING in the main directory of this source tree, or the |
| 7 | +# OpenIB.org BSD license below: |
| 8 | +# |
| 9 | +# Redistribution and use in source and binary forms, with or |
| 10 | +# without modification, are permitted provided that the following |
| 11 | +# conditions are met: |
| 12 | +# |
| 13 | +# - Redistributions of source code must retain the above |
| 14 | +# copyright notice, this list of conditions and the following |
| 15 | +# disclaimer. |
| 16 | +# |
| 17 | +# - Redistributions in binary form must reproduce the above |
| 18 | +# copyright notice, this list of conditions and the following |
| 19 | +# disclaimer in the documentation and/or other materials |
| 20 | +# provided with the distribution. |
| 21 | +# |
| 22 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 23 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 24 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 25 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 26 | +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 27 | +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 28 | +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 29 | +# SOFTWARE. |
| 30 | +# -- |
| 31 | + |
| 32 | + |
| 33 | +####################################################### |
| 34 | +# |
| 35 | +# resourceparse.py |
| 36 | +# Python implementation of the Class ResourceParse |
| 37 | +# Generated by Enterprise Architect |
| 38 | +# Created on: 16-Dec-2019 14:11:58 AM |
| 39 | +# Original author: talve |
| 40 | +# |
| 41 | +####################################################### |
| 42 | +import sys |
| 43 | +import os |
| 44 | + |
| 45 | +if sys.version_info[0] < 3: |
| 46 | + print("Error: This tool supports python 3.x only. Exiting...") |
| 47 | + exit(1) |
| 48 | + |
| 49 | +import argparse |
| 50 | +from utils import constants as cs |
| 51 | +from parsers.Parser import Parser |
| 52 | + |
| 53 | +sys.path.append(os.path.join("common")) |
| 54 | +import tools_version |
| 55 | + |
| 56 | + |
| 57 | +class ResourceParse: |
| 58 | + """This class is responsible for the resource dump UI by handling the user inputs and |
| 59 | + and running the right command. |
| 60 | + """ |
| 61 | + |
| 62 | + @classmethod |
| 63 | + def _run_arg_parse(self): |
| 64 | + """This method run the arg parse and return the arguments from the UI. |
| 65 | + """ |
| 66 | + # main parser |
| 67 | + tool_name = os.path.basename(__file__.split('.')[0]) |
| 68 | + parser = argparse.ArgumentParser(prog=tool_name, add_help=False, formatter_class=argparse.RawTextHelpFormatter) |
| 69 | + |
| 70 | + # required arguments by the parser |
| 71 | + required_named = parser.add_argument_group('required arguments') |
| 72 | + required_named.add_argument(cs.UI_DASHES + cs.UI_ARG_DUMP_FILE.replace("_", "-"), |
| 73 | + help='Location of the dump file used for parsing', required=True) |
| 74 | + required_named.add_argument(cs.UI_DASHES + cs.UI_ARG_ADB_FILE.replace("_", "-"), |
| 75 | + help='Location of the ADB file', required=True) |
| 76 | + |
| 77 | + # optional arguments by the parser |
| 78 | + parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, |
| 79 | + help='Shows this help message and exit') |
| 80 | + parser.add_argument('--version', action='version', help="Shows the tool's version and exit", |
| 81 | + version=tools_version.GetVersionString(tool_name, None)) |
| 82 | + |
| 83 | + parser.add_argument(cs.UI_DASHES + cs.UI_ARG_OUT, help='Location of the output file', required=False) |
| 84 | + parser.add_argument(cs.UI_DASHES + cs.UI_ARG_RAW, help='Prints the raw data in addition to the parsed data', |
| 85 | + required=False, action="store_true", default=False) |
| 86 | + parser.add_argument(cs.UI_DASHES_SHORT + cs.UI_ARG_VERBOSITY, |
| 87 | + help='Verbosity notice', dest=cs.UI_ARG_VERBOSITY_COUNT, |
| 88 | + default=0, action='count') |
| 89 | + arguments = parser.parse_args() |
| 90 | + return arguments |
| 91 | + |
| 92 | + def run(self): |
| 93 | + """This method run the parser with the needed arguments |
| 94 | + """ |
| 95 | + arguments = self._run_arg_parse() |
| 96 | + resource_parser = Parser(**vars(arguments)) |
| 97 | + resource_parser.parse() |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == '__main__': |
| 101 | + try: |
| 102 | + ResourceParse().run() |
| 103 | + except Exception as e: |
| 104 | + print("Error: {0}. Exiting...".format(e)) |
| 105 | + sys.exit(1) |
0 commit comments