Пример #1
0
def main(args=sys.argv):
    if len(args) == 1 or args[1] in ('-h', '--help'):
        print('Usage: python', args[0], 'command', '[options]')
        print('\nWhere command is one of:')
        print()
        for x in sorted(commands.__all__):
            print('{:20} -'.format(x), end=' ')
            c = getattr(commands, x)
            desc = getattr(c, 'short_description', c.description)
            print(desc)

        print('\nTo get help on a particular command, run:')
        print('\tpython', args[0], 'command -h')
        return 1

    command = args[1]
    if command not in commands.__all__:
        print(command, 'is not a recognized command.')
        print('Valid commands:', ', '.join(commands.__all__))
        return 1

    command = getattr(commands, command)

    parser = option_parser()
    command.add_all_options(parser)
    parser.set_usage(
        'Usage: python setup.py {} [options]\n\n'.format(args[1]) +
        command.description)

    opts, args = parser.parse_args(args)
    opts.cli_args = args[2:]

    if opts.clean_backups:
        clean_backups()

    if opts.clean:
        prints('Cleaning', args[1])
        command.clean()
        return 0

    if opts.clean_all:
        for cmd in commands.__all__:
            prints('Cleaning', cmd)
            getattr(commands, cmd).clean()
        return 0

    command.run_all(opts)

    warnings = get_warnings()
    if warnings:
        print()
        prints('There were', len(warnings), 'warning(s):')
        print()
        for args, kwargs in warnings:
            prints('*', *args, **kwargs)
            print()

    return 0
Пример #2
0
def main(args=sys.argv):
    if len(args) == 1 or args[1] in ('-h', '--help'):
        print('Usage: python', args[0], 'command', '[options]')
        print('\nWhere command is one of:')
        print()
        for x in sorted(commands.__all__):
            print('{:20} -'.format(x), end=' ')
            c = getattr(commands, x)
            desc = getattr(c, 'short_description', c.description)
            print(desc)

        print('\nTo get help on a particular command, run:')
        print('\tpython', args[0], 'command -h')
        return 1

    command = args[1]
    if command not in commands.__all__:
        print(command, 'is not a recognized command.')
        print('Valid commands:', ', '.join(commands.__all__))
        return 1

    command = getattr(commands, command)

    parser = option_parser()
    command.add_all_options(parser)
    parser.set_usage(
        'Usage: python setup.py {} [options]\n\n'.format(args[1]) + command.description)

    opts, args = parser.parse_args(args)

    if opts.clean_backups:
        clean_backups()

    if opts.clean:
        prints('Cleaning', args[1])
        command.clean()
        return 0

    if opts.clean_all:
        for cmd in commands.__all__:
            prints('Cleaning', cmd)
            getattr(commands, cmd).clean()
        return 0

    command.run_all(opts)

    warnings = get_warnings()
    if warnings:
        print()
        prints('There were', len(warnings), 'warning(s):')
        print()
        for args, kwargs in warnings:
            prints('*', *args, **kwargs)
            print()

    return 0
Пример #3
0
def main(args=sys.argv):
    if len(args) == 1 or args[1] in ("-h", "--help"):
        print("Usage: python", args[0], "command", "[options]")
        print("\nWhere command is one of:")
        print()
        for x in sorted(commands.__all__):
            print("%-20s -" % x, end=" ")
            c = getattr(commands, x)
            desc = getattr(c, "short_description", c.description)
            print(desc)

        print("\nTo get help on a particular command, run:")
        print("\tpython", args[0], "command -h")
        return 1

    command = args[1]
    if command not in commands.__all__:
        print(command, "is not a recognized command.")
        print("Valid commands:", ", ".join(commands.__all__))
        return 1

    command = getattr(commands, command)

    parser = option_parser()
    command.add_all_options(parser)
    parser.set_usage("Usage: python setup.py %s [options]\n\n" % args[1] + command.description)

    opts, args = parser.parse_args(args)

    if opts.clean_backups:
        clean_backups()

    if opts.clean:
        prints("Cleaning", args[1])
        command.clean()
        return 0

    if opts.clean_all:
        for cmd in commands.__all__:
            prints("Cleaning", cmd)
            getattr(commands, cmd).clean()
        return 0

    command.run_all(opts)

    warnings = get_warnings()
    if warnings:
        print()
        prints("There were", len(warnings), "warning(s):")
        print()
        for args, kwargs in warnings:
            prints("*", *args, **kwargs)
            print()

    return 0