Ejemplo n.º 1
0
def InternalMain(argv):
    """Main method called when invoked as stand-alone script."""
    LoadRequiredModules()

    console = console_mod.TtyConsole(sys.stdout)

    commands = commands_mod.GetCommands()

    # Parse arguments.
    try:
        cmd, args, options = commands_mod.Parse(argv, commands)
    except commands_mod.ParseError as e:
        console.PrintError(str(e))
        return 1

    if options.quiet:
        console.set_quiet()

    graph = CreateTaskGraph(options)

    ui = ui_mod.UiContext(options, console, commands, graph)

    if options.help:
        cmd.PrintHelp(ui)
        return 0

    # Check system.
    if not CheckSystem(ui):
        return 1

    # Try to load config files.
    project = LoadProject(os.getcwd(), ui)
    if ui.errors.HasError():
        return 1
    if not project:
        console.PrintError(
            'PROJECT not found. Make sure you are in Rime subtree.')
        return 1

    # Run the task.
    task = None
    try:
        hooks.pre_command(ui)
        task = cmd.Run(project, tuple(args), ui)
        if task:
            graph.Run(task)
        hooks.post_command(ui)
    except KeyboardInterrupt:
        if ui.options.debug >= 1:
            traceback.print_exc()
        raise

    if task:
        console.Print()
        console.Print(console.BOLD, 'Error Summary:', console.NORMAL)
        ui.errors.PrintSummary()
    if ui.errors.HasError():
        return 1
    return 0
Ejemplo n.º 2
0
Archivo: main.py Proyecto: puyopop/coin
def InternalMain(argv):
    """Main method called when invoked as stand-alone script."""
    LoadRequiredModules()

    console = console_mod.TtyConsole(sys.stdout)

    commands = commands_mod.GetCommands()

    # Parse arguments.
    try:
        cmd, args, options = commands_mod.Parse(argv, commands)
    except commands_mod.ParseError, e:
        console.PrintError(str(e))
        return 1
Ejemplo n.º 3
0
def LoadRequiredModules():
    # TODO(nya): Fix this hacky implementation.
    module_loader.LoadPackage('rime.basic')
    while True:
        commands = commands_mod.GetCommands()
        default_options = struct.Struct(commands[None].GetDefaultOptionDict())
        null_console = console_mod.NullConsole()
        graph = taskgraph.SerialTaskGraph()
        fake_ui = ui_mod.UiContext(default_options, null_console, commands,
                                   graph)
        try:
            LoadProject(os.getcwd(), fake_ui)
            break
        except targets.ConfigurationError:
            # Configuration errors should be processed later.
            break
        except targets.ReloadConfiguration:
            # Processed use_plugin(). Retry.
            pass