def add_parser(subparsers):
    parser = subparsers.add_parser('worker',
                                      help=description,
                                      epilog=__doc__,
                                      formatter_class=RawDescriptionHelpFormatter,
                                      )

    add_subparser_modules(parser, worker_commands, 'conda_server_build.subcommand')
示例#2
0
def binstar_main(sub_command_module,
                 args=None,
                 exit=True,
                 description=None,
                 version=None,
                 epilog=None):
    parser = ArgumentParser(description=description,
                            epilog=epilog,
                            formatter_class=RawDescriptionHelpFormatter)

    add_default_arguments(parser, version)
    bgroup = parser.add_argument_group('anaconda-client options')
    bgroup.add_argument(
        '-t',
        '--token',
        type=file_or_token,
        help="Authentication token to use. "
        "May be a token or a path to a file containing a token")
    bgroup.add_argument('-s',
                        '--site',
                        help='select the anaconda-client site to use',
                        default=None)

    add_subparser_modules(parser, sub_command_module,
                          'conda_server.subcommand')

    args = parser.parse_args(args)

    _setup_logging(logger,
                   log_level=args.log_level,
                   show_traceback=args.show_traceback,
                   disable_ssl_warnings=args.disable_ssl_warnings)

    try:
        try:
            if not hasattr(args, 'main'):
                parser.error(
                    "A sub command must be given. "
                    "To show all available sub commands, run:\n\n\t anaconda -h\n"
                )
            return args.main(args)
        except errors.Unauthorized:
            if not sys.stdin.isatty() or args.token:
                # Don't try the interactive login
                # Just exit
                raise

            logger.info(
                'The action you are performing requires authentication, '
                'please sign in:')
            interactive_login(args)
            return args.main(args)
    except errors.ShowHelp:
        args.sub_parser.print_help()
        if exit:
            raise SystemExit(1)
        else:
            return 1
示例#3
0
文件: build.py 项目: code-happy/mypy
def add_parser(subparsers):
    parser = subparsers.add_parser('build',
                                      help=description,
                                      epilog=__doc__,
                                      formatter_class=RawDescriptionHelpFormatter,

                                      )

    add_subparser_modules(parser, build_commands, 'conda_server_build.subcommand')
示例#4
0
    def test_add_subparser_modules(self):
        parser = ArgumentParser()

        with mock.patch('clyent.iter_entry_points') as iter_entry_points:

            ep = mock.Mock()
            ep.load.return_value = add_hello_parser
            iter_entry_points.return_value = [ep]
            add_subparser_modules(parser, None, 'entry_point_name')

        args = parser.parse_args(['hello', 'world'])
        self.assertEqual(args.world, 'world')
示例#5
0
    def test_add_subparser_modules(self):
        parser = ArgumentParser()

        with mock.patch('clyent.iter_entry_points') as iter_entry_points:

            ep = mock.Mock()
            ep.load.return_value = add_hello_parser
            iter_entry_points.return_value = [ep]
            add_subparser_modules(parser, None, 'entry_point_name')

        args = parser.parse_args(['hello', 'world'])
        self.assertEqual(args.world, 'world')
示例#6
0
def main(args=None, exit=True):

    parser = ArgumentParser(description=__doc__)

    add_default_arguments(parser, version)
    add_subparser_modules(parser, chalmers.commands)

    args = parser.parse_args(args)
    logfile = join(dirs.user_log_dir, 'cli.log')
    setup_logging(logger, args.log_level, use_color=args.color,
                  show_tb=args.show_traceback, logfile=logfile)

    run_command(args, exit=exit)
示例#7
0
def add_parser(subparsers):
    parser = subparsers.add_parser(
        'build',
        help=description,
        epilog=__doc__,
        formatter_class=RawDescriptionHelpFormatter,
    )

    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='anaconda-build {}'.format(version))

    add_subparser_modules(parser, build_commands,
                          'conda_server_build.subcommand')
示例#8
0
def main(args=None, exit=True):

    parser = ArgumentParser(description=__doc__)

    add_default_arguments(parser, version)
    add_subparser_modules(parser, chalmers.commands)

    args = parser.parse_args(args)
    logfile = config.main_logfile()
    setup_logging(logger, args.log_level, use_color=args.color,
                  show_tb=args.show_traceback, logfile=logfile)

    if not hasattr(args, 'main'):
        parser.error('too few arguments')

    run_command(args, exit=exit)
示例#9
0
def binstar_main(sub_command_module, args=None, exit=True, description=None, version=None, epilog=None):

    parser = ArgumentParser(description=description, epilog=epilog,
                            formatter_class=RawDescriptionHelpFormatter)

    add_default_arguments(parser, version)
    bgroup = parser.add_argument_group('anaconda-client options')
    bgroup.add_argument('-t', '--token', type=file_or_token,
                        help="Authentication token to use. "
                             "May be a token or a path to a file containing a token")
    bgroup.add_argument('-s', '--site',
                        help='select the anaconda-client site to use', default=None)

    add_subparser_modules(parser, sub_command_module, 'conda_server.subcommand')

    if not exists(USER_LOGDIR): makedirs(USER_LOGDIR)
    logfile = join(USER_LOGDIR, 'cli.log')

    args = parser.parse_args(args)

    setup_logging(logger, args.log_level, use_color=args.color,
                  logfile=logfile, show_tb=args.show_traceback)

    try:
        try:
            if not hasattr(args, 'main'):
                parser.error("A sub command must be given. "
                             "To show all available sub commands, run:\n\n\t anaconda -h\n")
            return args.main(args)
        except errors.Unauthorized:
            if not sys.stdin.isatty() or args.token:
                # Don't try the interactive login
                # Just exit
                raise

            logger.info('The action you are performing requires authentication, '
                        'please sign in:')
            interactive_login(args)
            return args.main(args)

    except errors.ShowHelp:
        args.sub_parser.print_help()
        if exit:
            raise SystemExit(1)
        else:
            return 1
示例#10
0
文件: cli.py 项目: coleb/binstar
def binstar_main(sub_command_module, args=None, exit=True, description=None, version=None, epilog=None):

    parser = ArgumentParser(description=description, epilog=epilog,
                            formatter_class=RawDescriptionHelpFormatter)

    add_default_arguments(parser, version)
    bgroup = parser.add_argument_group('binstar options')
    bgroup.add_argument('-t', '--token', type=file_or_token,
                        help="Authentication token to use. "
                             "May be a token or a path to a file containing a token")
    bgroup.add_argument('-s', '--site',
                        help='select the binstar site to use', default=None)

    add_subparser_modules(parser, sub_command_module)

    if not exists(USER_LOGDIR): makedirs(USER_LOGDIR)
    logfile = join(USER_LOGDIR, 'cli.log')

    args = parser.parse_args(args)

    setup_logging(logger, args.log_level, use_color=args.color,
                  logfile=logfile, show_tb=args.show_traceback)

    add_syslog_handler()

    try:
        try:
            if not hasattr(args, 'main'):
                parser.error("A sub command must be given. To show all available sub commands, run:\n\n\t binstar -h\n")
            return args.main(args)
        except errors.Unauthorized:
            if not args.token:
                logger.info('The action you are performing requires authentication, please sign in:')
                interactive_login(args)
                return args.main(args)
            else:
                raise

    except errors.ShowHelp:
        args.sub_parser.print_help()
        if exit:
            raise SystemExit(1)
        else:
            return 1