Beispiel #1
0
def main():
    cli_helper = Helper()

    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    # args = parser.parse_args(sys.argv[1:2])

    if len(sys.argv) > 1 and \
        sys.argv[1] in cli_helper.get_command_choices():
        command_name = sys.argv[1]
        if command_name == "init":
            command_name = "project"
        command_class = \
            cli_helper.get_command_class(command_name)
    else:
        command_class = BaseCommand

    try:
        command_instance = command_class(os.getcwd(), cli_helper)
    except TypeError as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
        sys.exit()

    try:
        command_instance.parse(sys.argv[1:])
    except CLIArgumentException as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
        sys.exit()

    try:
        command_instance.execute()
    except Exception as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
Beispiel #2
0
def main():
    cli_helper = Helper()
    # Config is required to run first so it can
    # initialize/find datmo home directory (.datmo)
    # This is required for logging to place the logs in a
    # place for the user.
    config = Config()

    log = DatmoLogger.get_logger(__name__)
    log.info("handling command %s", config.home)

    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    # args = parser.parse_args(sys.argv[1:2])

    if len(sys.argv) > 1 and \
        sys.argv[1] in cli_helper.get_command_choices():
        command_name = sys.argv[1]
        if command_name == "init":
            command_name = "project"
        elif command_name == "version" or \
            command_name == "--version" or \
            command_name == "-v":
            command_name = "project"
            sys.argv[1] = "version"
        elif command_name == "status":
            command_name = "project"
            sys.argv[1] = "status"
        elif command_name == "cleanup":
            command_name = "project"
            sys.argv[1] = "cleanup"
        command_class = cli_helper.get_command_class(command_name)
    else:
        command_class = BaseCommand

    # instantiate the command class
    try:
        command_instance = command_class(os.getcwd(), cli_helper)
    except TypeError as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
        return 1

    # parse the command line arguments
    try:
        command_instance.parse(sys.argv[1:])
    except CLIArgumentException as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
        return 1

    try:
        command_instance.execute()
        return 0
    except Exception as ex:
        cli_helper.echo(__("error", "cli.general", str(ex)))
        return 1
Beispiel #3
0
def main():
    cli_helper = Helper()
    # Config is required to run first so it can
    # initialize/find datmo home directory (.datmo)
    # This is required for logging to place the logs in a
    # place for the user.
    config = Config()
    config.set_home(os.getcwd())

    log = DatmoLogger.get_logger(__name__)
    log.info("handling command %s", config.home)

    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    # args = parser.parse_args(sys.argv[1:2])
    if len(sys.argv) > 1 and \
        sys.argv[1] in cli_helper.get_command_choices():
        command_name = sys.argv[1]
        # commands in project.py
        if command_name == "init":
            command_name = "project"
        elif command_name == "version" or \
            command_name == "--version" or \
            command_name == "-v":
            command_name = "project"
            sys.argv[1] = "version"
        elif command_name == "status":
            command_name = "project"
            sys.argv[1] = "status"
        elif command_name == "cleanup":
            command_name = "project"
            sys.argv[1] = "cleanup"
        # commands in workspace.py
        elif command_name in ["notebook", "jupyterlab", "terminal", "rstudio"]:
            sys.argv[1] = command_name
            command_name = "workspace"
        # commands in run.py
        elif command_name == "rerun":
            command_name = "run"
            sys.argv[1] = "rerun"
        elif command_name == "run":
            if len(sys.argv) == 2:
                command_name = "run"
                sys.argv.append("--help")
            else:
                command_name = "run"
        elif command_name == "stop":  # stop command in run.py
            if len(sys.argv) == 2:
                command_name = "run"
                sys.argv.append("--help")
            else:
                command_name = "run"
        elif command_name == "ls":  # ls command in run.py
            command_name = "run"
        elif command_name == "delete":  # delete command in run.py
            command_name = "run"
        command_class = cli_helper.get_command_class(command_name)
    elif len(sys.argv) == 1:
        command_name = "datmo_command"
        command_class = cli_helper.get_command_class(command_name)
    else:
        command_class = BaseCommand

    # instantiate the command class
    try:
        command_instance = command_class(cli_helper)
    except TypeError as ex:
        cli_helper.echo(__("error", "cli.general", "%s %s" % (type(ex), ex)))
        return 1

    # parse the command line arguments
    try:
        command_instance.parse(sys.argv[1:])
    except CLIArgumentError as ex:
        cli_helper.echo(__("error", "cli.general", "%s %s" % (type(ex), ex)))
        return 1

    try:
        command_instance.execute()
        return 0
    except Exception as ex:
        cli_helper.echo(__("error", "cli.general", "%s %s" % (type(ex), ex)))
        return 1