예제 #1
0
def puts(r):
    stdout = sys.stdout.write
    type_ = type(r)
    if type_ == list:
        return [puts(i) for i in r]
    elif type_ == dict:
        for key in r:
            puts(cli.blue(cli.min_width(key, 25) + str(r[key])))
        return
    elif type_ == Error:
        return puts(cli.red(str(r)))
    elif type_ == bool:
        if r:
            return puts(cli.green('OK'))
        return puts(cli.red('FAILED'))
    elif r is not None:
        return cli.puts(str(r).rstrip('\n'), stream=stdout)
예제 #2
0
def puts(r):
    stdout = sys.stdout.write
    type_ = type(r)
    if type_ == list:
        return [puts(i) for i in r]
    elif type_ == dict:
        for key in r:
            puts(cli.blue(cli.min_width(key, 25) + r[key]))
        return
    elif type_ == Error:
        return puts(cli.red(str(r)))
    elif type_ == bool:
        if r:
            return puts(cli.green('OK'))
        return puts(cli.red('FAILED'))
    elif r is not None:
        return cli.puts(str(r).rstrip('\n'), stream=stdout)
예제 #3
0
def main():
    try:
        sys.path.append(os.getcwd())
        imp.load_source('manage_file', os.path.join(os.getcwd(), 'manage.py'))
    except IOError as exc:
        return puts(cli.red(exc))

    from manage_file import manager

    manager.main()
예제 #4
0
def main():
    try:
        sys.path.append(os.getcwd())
        imp.load_source('manager', os.path.join(os.getcwd(), 'manage.py'))
    except IOError:
        return puts(cli.red('No such file manage.py'))

    from manager import manager

    manager.main()
예제 #5
0
    def main(self, args=None):
        args = cli.Args(args)
        if len(args) == 0 or args[0] in ('-h', '--help'):
            return self.usage()

        command = args.get(0)
        try:
            command = self.commands[command]
        except KeyError:
            puts(cli.red('Invalid command `%s`\n' % command))
            return self.usage()
        self.update_env()
        command.parse(args.all[1:])
예제 #6
0
    def main(self, args=None):
        args = cli.Args(args)
        if len(args) == 0 or args[0] in ('-h', '--help'):
            return self.usage()

        command = args.get(0)
        try:
            command = self.commands[command]
        except KeyError:
            puts(cli.red('Invalid command `%s`\n' % command))
            return self.usage()
        self.update_env()
        command.parse(args.all[1:])
예제 #7
0
    def usage(self):
        def format_line(command, w):
            return "%s%s" % (cli.min_width(command.name, w), command.description)

        self.parser.print_help()
        if len(self.commands) > 0:
            puts("\navailable commands:")
            with cli.indent(2):
                namespace = None
                for command_path in sorted(self.commands, key=lambda c: "%s%s" % (c.count("."), c)):
                    command = self.commands[command_path]
                    if command.namespace is not None:
                        if command.namespace != namespace:
                            puts(cli.red("\n[%s]" % command.namespace))
                        with cli.indent(2):
                            puts(format_line(command, 23))
                    else:
                        puts(format_line(command, 25))
                    namespace = command.namespace
예제 #8
0
    def usage(self):
        def format_line(command, w):
            return "%s%s" % (cli.min_width(command.name,
                                           w), command.description)

        self.parser.print_help()
        if len(self.commands) > 0:
            puts('\navailable commands:')
            with cli.indent(2):
                namespace = None
                for command_path in sorted(self.commands,
                                           key=lambda c: '%s%s' %
                                           (c.count('.'), c)):
                    command = self.commands[command_path]
                    if command.namespace is not None:
                        if command.namespace != namespace:
                            puts(cli.red('\n[%s]' % command.namespace))
                        with cli.indent(2):
                            puts(format_line(command, 23))
                    else:
                        puts(format_line(command, 25))
                    namespace = command.namespace