コード例 #1
0
ファイル: help.py プロジェクト: avelino/votacao_paredao_bbb
    def execute(self, *args, **kwargs):
        commands = []

        # Finds command classes in available modules
        for cmd in get_commands():
            module = import_anything(cmd)
            cls = import_anything('Command', module)
            commands.append((cmd.split('.')[-1], module, cls))

        commands.sort(lambda a,b: cmp(a[0], b[0]))

        # Prints their details

        print('Available commands:')

        for cmd, module, cls in commands:
            print('\n%s' % cmd)

            help = ''
            if getattr(cls, 'help', None):
                help = cls.help
            elif cls.__doc__:
                help = cls.__doc__

            if help:
                help = textwrap.wrap(help, 80)
                print('  ' + '\n  '.join(help))
コード例 #2
0
def execute():
    # Arguments parser
    options, args = get_option_parser(basic_option_list, cls=BasicOptionParser, add_help_option=False)
    settings.project_settings = import_anything(options.settings)

    # Command parsing
    subcommand = get_subcommand(sys.argv[1])
    command_class = None
    
    # Find the command in the command directories
    for path in commands.get_commands():
        if path.endswith('.'+subcommand):
            try:
                command_class = import_anything(path+'.Command')
                break
            except ImportError:
                pass

    # If the command doesn't exist...
    if not command_class:
        print('Command not found.')
        sys.exit(1)

    # Arguments parser
    options, args = get_option_parser(command_class.option_list)

    if options.run_with_pdb:
        pdb.set_trace()

    kwargs = dict([(opt.dest, getattr(options, opt.dest, opt.default))
        for opt in command_class.option_list])
    
    # Running the command
    cmd = command_class(settings.project_settings)
    cmd.execute(*args[2:], **kwargs)