Esempio n. 1
0
    def _run_arg_parse(self):
        """This method run the arg parse and return the arguments from the UI.
        """
        # main parser
        tool_name = os.path.basename(__file__.split('.')[0])
        parser = argparse.ArgumentParser(prog=tool_name, add_help=False, formatter_class=argparse.RawTextHelpFormatter)

        # required arguments by the parser
        required_named = parser.add_argument_group('required arguments')
        required_named.add_argument(cs.UI_DASHES + cs.UI_ARG_DUMP_FILE.replace("_", "-"),
                                    help='Location of the dump file used for parsing', required=True)
        required_named.add_argument(cs.UI_DASHES + cs.UI_ARG_ADB_FILE.replace("_", "-"),
                                    help='Location of the ADB file', required=True)

        # optional arguments by the parser
        parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
                            help='Shows this help message and exit')
        parser.add_argument('--version', action='version', help="Shows the tool's version and exit",
                            version=tools_version.GetVersionString(tool_name, None))

        parser.add_argument(cs.UI_DASHES + cs.UI_ARG_OUT, help='Location of the output file', required=False)
        parser.add_argument(cs.UI_DASHES + cs.UI_ARG_RAW, help='Prints the raw data in addition to the parsed data',
                            required=False, action="store_true", default=False)
        parser.add_argument(cs.UI_DASHES_SHORT + cs.UI_ARG_VERBOSITY,
                            help='Verbosity notice', dest=cs.UI_ARG_VERBOSITY_COUNT,
                            default=0, action='count')
        arguments = parser.parse_args()
        return arguments
Esempio n. 2
0
def add_args():
    """
    Adding tool arguments and options
    """
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        prog=EXEC_NAME,
        epilog=get_epilog(),
        usage="%s -d|--device DEVICE [options]" % EXEC_NAME)
    parser.add_argument("-v",
                        "--version",
                        '-v',
                        help='Print tool version.',
                        action="version",
                        version=tools_version.GetVersionString(
                            EXEC_NAME, None))
    options_group = parser.add_argument_group('Options')
    options_group.add_argument("-d",
                               "--device",
                               dest="device",
                               help="PCI device name",
                               default=None)
    options_group.add_argument("--tracer_mode",
                               dest="tracer_mode",
                               help="Tracer mode [MEM]",
                               default="MEM")
    options_group.add_argument("--real_ts",
                               action="store_true",
                               dest="real_ts",
                               help="Print real timestamps in [hh:mm:ss:nsec]",
                               default=False)
    options_group.add_argument("--ignore_old_events",
                               action="store_true",
                               dest="ignore_old_events",
                               help="Ignore collecting old events",
                               default=False)
    format_group = parser.add_argument_group('Format')
    format_group.add_argument("-i",
                              "--irisc",
                              dest="irisc",
                              help="Irisc name [all]",
                              default="all")
    format_group.add_argument("-s",
                              "--stream",
                              action="store_true",
                              dest="stream",
                              help="Run in streaming mode",
                              default=False)
    format_group.add_argument("-m", "--mask", dest="mask", help="Trace class mask, use \"+\" to enable multiple classes or use integer format, e.g: -m " \
                                                          "class1+class2+... or 0xff00ff00", default=None)
    format_group.add_argument("-l",
                              "--level",
                              dest="level",
                              help="Trace level",
                              default=None)
    return parser
Esempio n. 3
0
def parse_args():
    parser = argparse.ArgumentParser(
        prog=PROG,
        description=DESCRIPTION,
        formatter_class=argparse.RawTextHelpFormatter)
    version = tools_version.GetVersionString(PROG, TOOL_VERSION)
    parser.add_argument("-v",
                        "--version",
                        action="version",
                        version=version,
                        help="show program's version number and exit")
    # options arguments
    options_group = parser.add_argument_group('Options')
    options_group.add_argument('--device',
                               '-d',
                               required=True,
                               help='Device to work with.')

    # command arguments
    command_group = parser.add_argument_group('Commands')
    command_group.add_argument(
        'command',
        nargs=1,
        choices=["r", "restrict", "p", "privilege", "q", "query"],
        help=CMD_HELP)
    options_group.add_argument('--disable_rshim',
                               action="store_true",
                               help=DISABLE_RSHIM_HELP)
    options_group.add_argument('--disable_tracer',
                               action="store_true",
                               help=DISABLE_TRACER_HELP)
    options_group.add_argument('--disable_counter_rd',
                               action="store_true",
                               help=DISABLE_COUNTER_RD_HELP)
    options_group.add_argument('--disable_port_owner',
                               action="store_true",
                               help=DISABLE_PORT_OWNER_HELP)
    args = parser.parse_args()

    disable_flags = args.disable_rshim or args.disable_tracer or \
                args.disable_counter_rd or args.disable_port_owner
    rest_flags = args.command[0] in ("r", "restrict")
    priv_flags = args.command[0] in ("p", "privilege")
    query_flags = args.command[0] in ("q", "query")
    if priv_flags and disable_flags:
        parser.error("disable flags are not allowed in privilege mode")
    if query_flags and (priv_flags or rest_flags or disable_flags):
        parser.error(
            "privilege or restrict commands are not allowed with query")
    return args
Esempio n. 4
0
def parse_args():
    parser = argparse.ArgumentParser(
        prog=PROG,
        description=DESCRIPTION,
        formatter_class=argparse.RawTextHelpFormatter,
        version=tools_version.GetVersionString(PROG, TOOL_VERSION))
    # options arguments
    options_group = parser.add_argument_group('Options')
    options_group.add_argument('--device',
                               '-d',
                               required=True,
                               help='Device to work with.')

    # command arguments
    command_group = parser.add_argument_group('Commands')
    command_group.add_argument('command',
                               nargs=1,
                               choices=["r", "restrict", "p", "privilege"],
                               help=CMD_HELP)
    options_group.add_argument('--disable_rshim',
                               action="store_true",
                               help=DISABLE_RSHIM_HELP)
    options_group.add_argument('--disable_tracer',
                               action="store_true",
                               help=DISABLE_TRACER_HELP)
    options_group.add_argument('--disable_counter_rd',
                               action="store_true",
                               help=DISABLE_COUNTER_RD_HELP)
    options_group.add_argument('--disable_port_owner',
                               action="store_true",
                               help=DISABLE_PORT_OWNER_HELP)
    args = parser.parse_args()
    if args.command[0] in ("p", "privilege"):
        if args.disable_rshim or args.disable_tracer or \
                args.disable_counter_rd or args.disable_port_owner:
            parser.error("disable flags are not allowed in privilege mode")
    return args
Esempio n. 5
0
    def run(self):
        # main parser
        tool_name = os.path.basename(__file__.split('.')[0])
        parser = argparse.ArgumentParser(
            epilog="Use '{0} <command> -h' to read about a specific command.".
            format(tool_name))
        parser.add_argument('-v',
                            '--version',
                            action='version',
                            help='Shows tool version',
                            version=tools_version.GetVersionString(
                                cs.TOOL_NAME, None))

        # commands sub parser
        commands = parser.add_subparsers(title='commands')

        # dump sub parser
        dump_parser = commands.add_parser(cs.RESOURCE_DUMP_COMMAND_TYPE_DUMP)
        dump_parser.set_defaults(parser=cs.RESOURCE_DUMP_COMMAND_TYPE_DUMP)

        # required arguments by dump sub parser
        dump_required_args = dump_parser.add_argument_group(
            'required arguments')
        dump_required_args.add_argument(cs.UI_DASHES + cs.UI_ARG_DEVICE,
                                        cs.UI_DASHES_SHORT +
                                        cs.UI_ARG_DEVICE_SHORT,
                                        help='The device name',
                                        required=True)
        dump_required_args.add_argument(cs.UI_DASHES + cs.UI_ARG_SEGMENT,
                                        help='The segment to dump',
                                        required=True,
                                        type=self._decimal_hex_to_str_hex)

        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_VHCAID.replace("_", "-"),
            help=argparse.SUPPRESS
        )  # help='The virtual HCA (host channel adapter, NIC) ID')
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_INDEX1,
            help=
            'The first context index to dump (if supported for this segment)',
            type=self._decimal_hex_check)
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_INDEX2,
            help=
            'The second context index to dump (if supported for this segment)',
            type=self._decimal_hex_check)
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_NUMOFOBJ1.replace("_", "-"),
            help=
            'The number of objects to be dumped (if supported for this segment). accepts: ["all", "active", number, depends on the capabilities]',
            type=self._num_of_objs_check)
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_NUMOFOBJ2.replace("_", "-"),
            help=
            'The number of objects to be dumped (if supported for this segment). accepts: ["all", "active", number, depends on the capabilities]',
            type=self._num_of_objs_check)
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_DEPTH,
            help=
            'The depth of walking through reference segments. 0 stands for flat, '
            '1 allows crawling of a single layer down the struct, etc. "inf" for all',
            type=self._depth_check)
        dump_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_BIN,
            help=
            'The output to a binary file that replaces the default print in hexadecimal,'
            ' a readable format')

        # query sub parser
        query_parser = commands.add_parser(cs.RESOURCE_DUMP_COMMAND_TYPE_QUERY)
        query_parser.set_defaults(parser=cs.RESOURCE_DUMP_COMMAND_TYPE_QUERY)
        query_parser.add_argument(
            cs.UI_DASHES + cs.UI_ARG_VHCAID.replace("_", "-"),
            help=argparse.SUPPRESS
        )  # help='The virtual HCA (host channel adapter, NIC) ID')

        # required arguments by query sub parser
        query_required_args = query_parser.add_argument_group(
            'required arguments')
        query_required_args.add_argument(cs.UI_DASHES + cs.UI_ARG_DEVICE,
                                         cs.UI_DASHES_SHORT +
                                         cs.UI_ARG_DEVICE_SHORT,
                                         help='The device name',
                                         required=True)

        # args = parser.parse_args(
        #     'dump -d test --source test2 --vHCAid 15 --index 1 --index2 2 --numOfObj1 10 --numOfObj2 20
        #           --depth inf --bin tt.txt'.split())
        arguments = parser.parse_args()
        return arguments
Esempio n. 6
0
def parse_args():
    parser = argparse.ArgumentParser(
        prog=PROG,
        description=DESCRIPTION,
        formatter_class=argparse.RawTextHelpFormatter)
    version = tools_version.GetVersionString(PROG, TOOL_VERSION)
    parser.add_argument("-v",
                        "--version",
                        action="version",
                        version=version,
                        help="show program's version number and exit")
    # options arguments
    options_group = parser.add_argument_group('Options')
    options_group.add_argument('-d',
                               '--device',
                               required=True,
                               metavar='<dev>',
                               help=DEV_HELP)
    restrict_options_group = parser.add_argument_group('Restrict Options')
    restrict_options_group.add_argument('--disable_rshim',
                                        action="store_true",
                                        help=DISABLE_RSHIM_HELP)
    restrict_options_group.add_argument('--disable_tracer',
                                        action="store_true",
                                        help=DISABLE_TRACER_HELP)
    restrict_options_group.add_argument('--disable_counter_rd',
                                        action="store_true",
                                        help=DISABLE_COUNTER_RD_HELP)
    restrict_options_group.add_argument('--disable_port_owner',
                                        action="store_true",
                                        help=DISABLE_PORT_OWNER_HELP)
    query_options_group = parser.add_argument_group('Query Options')
    query_options_group.add_argument('--full',
                                     '-f',
                                     action="store_true",
                                     help=QUERY_FULL_HELP)
    # command arguments
    command_group = parser.add_argument_group('Commands')
    command_group.add_argument(
        'command',
        nargs='?',
        choices=["r", "restrict", "p", "privilege", "q", "query"],
        help=CMD_HELP)

    args = parser.parse_args()

    if args.command is None:
        parser.error(
            "Please provide a command to execute, check the help menu")

    disable_flags = args.disable_rshim or args.disable_tracer or \
        args.disable_counter_rd or args.disable_port_owner
    q_full_flag = args.full
    rest_flags = args.command in ("r", "restrict")
    priv_flags = args.command in ("p", "privilege")
    query_flags = args.command in ("q", "query")
    if priv_flags and disable_flags:
        parser.error("disable flags are not allowed in privilege mode")
    if query_flags and (priv_flags or rest_flags or disable_flags):
        parser.error(
            "privilege or restrict commands are not allowed with query")
    if q_full_flag and not query_flags:
        parser.error("The verbose option is allowed with query only")

    return args