Exemplo n.º 1
0
def main(arguments):

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('taxit', help='path to taxit executable')
    parser.add_argument('-d', '--outdir', help="Output directory")

    args = parser.parse_args(arguments)

    try:
        os.makedirs(args.outdir)
    except OSError:
        pass

    # execute each subcommand in a subshell because calling
    # taxit.main(args) exits after printing help text for first
    # subcommand.
    for name, module in subcommands.itermodules():
        with open(os.path.join(args.outdir, name + '.txt'), 'w') as f:
            subprocess.call([args.taxit, name, '-h'], stdout=f)
Exemplo n.º 2
0
def main(arguments):

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('taxit', help='path to taxit executable')
    parser.add_argument('-d', '--outdir', help="Output directory")

    args = parser.parse_args(arguments)

    try:
        os.makedirs(args.outdir)
    except OSError:
        pass

    # execute each subcommand in a subshell because calling
    # taxit.main(args) exits after printing help text for first
    # subcommand.
    for name, module in subcommands.itermodules():
        with open(os.path.join(args.outdir, name + '.txt'), 'w') as f:
            subprocess.call([args.taxit, name, '-h'], stdout=f)
Exemplo n.º 3
0
def parse_arguments(argv):
    """Create the argument parser

    """
    parser = argparse.ArgumentParser(description=DESCRIPTION)
    base_parser = argparse.ArgumentParser(add_help=False)

    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='taxit v' + version,
                        help='Print the version number and exit')

    parser.add_argument(
        '-v',
        '--verbose',
        action='count',
        dest='verbosity',
        default=1,
        help='Increase verbosity of screen output (eg, -v is verbose, '
        '-vv more so)')
    parser.add_argument('-q',
                        '--quiet',
                        action='store_const',
                        dest='verbosity',
                        const=0,
                        help='Suppress output')

    ##########################
    # Setup all sub-commands #
    ##########################

    subparsers = parser.add_subparsers(dest='subparser_name')

    # Begin help sub-command
    parser_help = subparsers.add_parser(
        'help', help='Detailed help for actions using `help <action>`')
    parser_help.add_argument('action', nargs=1)
    # End help sub-command

    actions = {}

    for name, mod in subcommands.itermodules(
            os.path.split(subcommands.__file__)[0]):
        # set up subcommand help text. The first line of the dosctring
        # in the module is displayed as the help text in the
        # script-level help message (`script -h`). The entire
        # docstring is displayed in the help message for the
        # individual subcommand ((`script action -h`)).
        subparser = subparsers.add_parser(
            name,
            prog='taxit {}'.format(name),
            help=mod.__doc__.lstrip().split('\n', 1)[0],
            description=mod.__doc__,
            formatter_class=RawDescriptionHelpFormatter,
            parents=[base_parser])

        mod.build_parser(subparser)
        actions[name] = mod.action

    # Determine we have called ourself (e.g. "help <action>")
    # Set arguments to display help if parameter is set
    #           *or*
    # Set arguments to perform an action with any specified options.
    arguments = parser.parse_args(argv)
    # Determine which action is in play.
    action = arguments.subparser_name

    # Support help <action> by simply having this function call itself and
    # translate the arguments into something that argparse can work with.
    if action == 'help':
        return parse_arguments([str(arguments.action[0]), '-h'])

    return actions[action], arguments
Exemplo n.º 4
0
def parse_arguments(argv):
    """
    """
    # Create the argument parser
    parser = argparse.ArgumentParser(description=DESCRIPTION, prog=PROG)

    parser.add_argument('-V', '--version', action='version',
        version='taxit v' + version,
        help='Print the version number and exit')

    parser.add_argument('-v', '--verbose',
        action='count', dest='verbosity', default=1,
        help='Increase verbosity of screen output (eg, -v is verbose, '
             '-vv more so)')
    parser.add_argument('-q', '--quiet',
        action='store_const', dest='verbosity', const=0,
        help='Suppress output')


    ##########################
    # Setup all sub-commands #
    ##########################

    subparsers = parser.add_subparsers(dest='subparser_name')

    # Begin help sub-command
    parser_help = subparsers.add_parser(
        'help', help='Detailed help for actions using `help <action>`')
    parser_help.add_argument('action', nargs=1)
    # End help sub-command

    actions = {}
    
    for name, mod in subcommands.itermodules(os.path.split(subcommands.__file__)[0]):
        # set up subcommand help text. The first line of the dosctring
        # in the module is displayed as the help text in the
        # script-level help message (`script -h`). The entire
        # docstring is displayed in the help message for the
        # individual subcommand ((`script action -h`)).
        subparser = subparsers.add_parser(
            name,
            help = mod.__doc__.lstrip().split('\n', 1)[0],
            description = mod.__doc__,
            formatter_class = RawDescriptionHelpFormatter)

        mod.build_parser(subparser)
        actions[name] = mod.action

    # Determine we have called ourself (e.g. "help <action>")
    # Set arguments to display help if parameter is set
    #           *or*
    # Set arguments to perform an action with any specified options.
    arguments = parser.parse_args(argv)
    # Determine which action is in play.
    action = arguments.subparser_name

    # Support help <action> by simply having this function call itself and
    # translate the arguments into something that argparse can work with.
    if action == 'help':
        return parse_arguments([str(arguments.action[0]), '-h'])

    return actions[action], arguments
Exemplo n.º 5
0
def parse_arguments(argv):
    """
    """
    # Create the argument parser
    parser = argparse.ArgumentParser(description=DESCRIPTION)
    base_parser = argparse.ArgumentParser(add_help=False)

    parser.add_argument(
        "-V", "--version", action="version", version="taxit v" + version, help="Print the version number and exit"
    )

    parser.add_argument(
        "-v",
        "--verbose",
        action="count",
        dest="verbosity",
        default=1,
        help="Increase verbosity of screen output (eg, -v is verbose, " "-vv more so)",
    )
    parser.add_argument("-q", "--quiet", action="store_const", dest="verbosity", const=0, help="Suppress output")

    ##########################
    # Setup all sub-commands #
    ##########################

    subparsers = parser.add_subparsers(dest="subparser_name")

    # Begin help sub-command
    parser_help = subparsers.add_parser("help", help="Detailed help for actions using `help <action>`")
    parser_help.add_argument("action", nargs=1)
    # End help sub-command

    actions = {}

    for name, mod in subcommands.itermodules(os.path.split(subcommands.__file__)[0]):
        # set up subcommand help text. The first line of the dosctring
        # in the module is displayed as the help text in the
        # script-level help message (`script -h`). The entire
        # docstring is displayed in the help message for the
        # individual subcommand ((`script action -h`)).
        subparser = subparsers.add_parser(
            name,
            prog="taxit {}".format(name),
            help=mod.__doc__.lstrip().split("\n", 1)[0],
            description=mod.__doc__,
            formatter_class=RawDescriptionHelpFormatter,
            parents=[base_parser],
        )

        mod.build_parser(subparser)
        actions[name] = mod.action

    # Determine we have called ourself (e.g. "help <action>")
    # Set arguments to display help if parameter is set
    #           *or*
    # Set arguments to perform an action with any specified options.
    arguments = parser.parse_args(argv)
    # Determine which action is in play.
    action = arguments.subparser_name

    # Support help <action> by simply having this function call itself and
    # translate the arguments into something that argparse can work with.
    if action == "help":
        return parse_arguments([str(arguments.action[0]), "-h"])

    return actions[action], arguments