Ejemplo n.º 1
0
Archivo: app.py Proyecto: hdeweirdt/imp
def app():
    """
        Run the compiler
    """
    parser = ArgumentParser()

    parser.add_argument("-p", action="store_true", dest="profile",
                      help='Profile this run of the program')
    parser.add_argument("--dbg", dest = "debugger", action = "store_true",
                        help="Connect to the pydev debugger at startup")
    parser.add_argument("-d", "--debug", dest = "debug", action = "store_true",
                        help="Enable debug logging")
    parser.add_argument("-c", "--config", dest = "config_file", help="Use this config file")

    subcommands = parser.add_subparsers()

    for cmd in Commander.get_commands():
        sub_cmd = subcommands.add_parser(cmd)
        sub_cmd.set_defaults(command = cmd)

        arguments = Commander.get_arguments(cmd)
        for argument in arguments:
            if len(argument) == 3:
                sub_cmd.add_argument(argument[0], help = argument[1],
                                     dest = argument[2])
            elif len(argument) == 2:
                sub_cmd.add_argument(argument[0], help = argument[1])
            else:
                sub_cmd.add_argument(argument[0], help = argument[1],
                                     dest = argument[3], action = argument[2])


    options, other = parser.parse_known_args()
    options.other = other

    if options.debug:
        # TODO: fix logging
        logging.basicConfig(level=logging.DEBUG)

    if options.debugger:
        try:
            import pydevd; pydevd.settrace()
        except:
            print("Unable to start pydev debugger")

    Config.load_config(options.config_file)
    config = Config.get()

    if not hasattr(options, "command"):
        # show help
        parser.print_usage()
        return

    Commander.run(options.command, options, config)
Ejemplo n.º 2
0
Archivo: app.py Proyecto: hdeweirdt/imp
def list_commands(**kwargs):
    print("The following commands are available:")
    for cmd in Commander.get_commands():
        print(" %s: %s" % (cmd, Commander.get_help(cmd)))