Esempio n. 1
0
def main():
    e = Environment()
    e.load()

    conf = configure()

    try:
        current_command = sys.argv[1]
    except IndexError:
        current_command = None

    parser = argparse.ArgumentParser(prog='ino',
                                     formatter_class=FlexiFormatter,
                                     description=__doc__)
    subparsers = parser.add_subparsers()
    is_command = lambda x: inspect.isclass(x) and issubclass(x, Command
                                                             ) and x != Command
    commands = [
        cls(e) for _, cls in inspect.getmembers(ino.commands, is_command)
    ]
    for cmd in commands:
        p = subparsers.add_parser(cmd.name,
                                  formatter_class=FlexiFormatter,
                                  help=cmd.help_line)
        if current_command != cmd.name:
            continue
        cmd.setup_arg_parser(p)
        p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name))

    args = parser.parse_args()

    try:
        run_anywhere = "init clean list-models serial"

        in_project_dir = os.path.isdir(e.src_dir)
        if not in_project_dir and current_command not in run_anywhere:
            raise Abort("No project found in this directory.")

        e.process_args(args)

        if current_command not in run_anywhere:
            # For valid projects create .build & lib
            if not os.path.isdir(e.build_dir):
                os.makedirs(e.build_dir)

            if not os.path.isdir(e.lib_dir):
                os.makedirs(e.lib_dir)
                with open('lib/.holder', 'w') as f:
                    f.write("")

        args.func(args)
    except Abort as exc:
        print colorize(str(exc), 'red')
        sys.exit(1)
    except KeyboardInterrupt:
        print 'Terminated by user'
    finally:
        e.dump()
def main(arguments=None, compiled_dir=""):
    if arguments is not None:
        sys.argv = arguments

    e = Environment()
    e.load()
    #e.output_dir = compiled_dir + ".build"

    conf = configure()

    try:
        current_command = sys.argv[1]
    except IndexError:
        current_command = None

    parser = argparse.ArgumentParser(prog='ino', formatter_class=FlexiFormatter, description=__doc__)
    subparsers = parser.add_subparsers()
    is_command = lambda x: inspect.isclass(x) and issubclass(x, Command) and x != Command
    commands = [cls(e) for _, cls in inspect.getmembers(ino.commands, is_command)]
    for cmd in commands:
        p = subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line)
        if current_command != cmd.name:
            continue
        cmd.setup_arg_parser(p)
        p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name))

    args = parser.parse_args()

    try:
        run_anywhere = "init clean list-models serial"

        in_project_dir = os.path.isdir(e.src_dir)
        if not in_project_dir and current_command not in run_anywhere:
            raise Abort("No project found in this directory.")

        e.process_args(args)

        if current_command not in run_anywhere:
            # For valid projects create .build & lib
            if not os.path.isdir(e.build_dir):                
                os.makedirs(e.build_dir)

            if not os.path.isdir(e.lib_dir):
                os.makedirs(e.lib_dir)
                with open('lib/.holder', 'w') as f:
                    f.write("")

        args.func(args)
    #except Abort as exc:
    #    print colorize(str(exc), 'red')
    #    sys.exit(1)
    except KeyboardInterrupt:
        print 'Terminated by user'
    finally:
        e.dump()
Esempio n. 3
0
def build_args(environment):
    parser = argparse.ArgumentParser(prog='ino', formatter_class=FlexiFormatter, description=__doc__)
    subparsers = parser.add_subparsers()
    config = configure()

    if len(sys.argv) > 1 and sys.argv[1] in commands:
        cmd_name = sys.argv[1]
        cmd = commands[cmd_name](environment)
        subparser = subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line)
        cmd.setup_arg_parser(subparser)
        subparser.set_defaults(func=cmd.run, **config.as_dict(cmd.name))
    else:
        cmd_name = None
        for cmd in tuple(commands.itervalues()):
            subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line)

    return cmd_name, parser.parse_args()
Esempio n. 4
0
def main():
    e = Environment()
    e.load()

    conf = configure()

    try:
        current_command = sys.argv[1]
    except IndexError:
        current_command = None

    parser = argparse.ArgumentParser(prog='ino',
                                     formatter_class=FlexiFormatter,
                                     description=__doc__)
    subparsers = parser.add_subparsers()
    is_command = lambda x: inspect.isclass(x) and issubclass(x, Command
                                                             ) and x != Command
    commands = [
        cls(e) for _, cls in inspect.getmembers(ino.commands, is_command)
    ]
    for cmd in commands:
        p = subparsers.add_parser(cmd.name,
                                  formatter_class=FlexiFormatter,
                                  help=cmd.help_line)
        if current_command != cmd.name:
            continue
        cmd.setup_arg_parser(p)
        p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name))

    args = parser.parse_args()

    try:
        e.process_args(args)

        if current_command not in 'clean init' and not os.path.isdir(
                e.build_dir):
            os.makedirs(e.build_dir)

        args.func(args)
    except Abort as exc:
        print colorize(str(exc), 'red')
        sys.exit(1)
    except KeyboardInterrupt:
        print 'Terminated by user'
    finally:
        e.dump()
Esempio n. 5
0
def main():
    e = Environment()
    e.load()

    conf = configure()

    try:
        current_command = sys.argv[1]
    except IndexError:
        current_command = None

    parser = argparse.ArgumentParser(prog='ino-cocoduino', formatter_class=FlexiFormatter, description=__doc__)
    subparsers = parser.add_subparsers()
    is_command = lambda x: inspect.isclass(x) and issubclass(x, Command) and x != Command
    commands = [cls(e) for _, cls in inspect.getmembers(ino.commands, is_command)]
    for cmd in commands:
        p = subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line)
        if current_command != cmd.name:
            continue
        cmd.setup_arg_parser(p)
        p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name))

    args = parser.parse_args()

    try:
        e.process_args(args)

        if current_command not in 'clean' and not os.path.isdir(e.build_dir):
            os.mkdir(e.build_dir)

        args.func(args)
    except Abort as exc:
        print colorize(str(exc), 'red')
        sys.exit(1)
    except KeyboardInterrupt:
        print 'Terminated by user'
    finally:
        e.dump()