Esempio n. 1
0
def list_available(args):
    """List the name and title of the models in the Hub."""

    # Setup.

    mlhub = utils.get_repo(args.mlhub)
    meta = utils.get_repo_meta_data(mlhub)

    # Provide some context.

    if not args.quiet:
        print("The repository '{}' provides the following models:\n".format(
            mlhub))

    # List the meta data.

    for info in meta:
        utils.print_meta_line(info)

    # Suggest next step.

    if not args.quiet:
        msg = "\nInstall a model with:\n\n  $ {} install <model>\n"
        msg = msg.format(CMD)
        print(msg)
Esempio n. 2
0
def list_installed(args):
    """List the installed models."""

    # Find installed models, ignoring special folders like R.

    if os.path.exists(MLINIT):
        msg = " in '{}'.".format(MLINIT)
        models = [f for f in os.listdir(MLINIT)
                  if os.path.isdir(os.path.join(MLINIT, f)) and f != "R" and not f.startswith('.')]
    else:
        msg = ". '{}' does not exist.".format(MLINIT)
        models = []

    models.sort()

    # Only list model names

    if args.name_only:
        print('\n'.join(models))
        return
        
    # Report on how many models we found installed.
        
    mcnt = len(models)
    plural = "s"
    if mcnt == 1: plural = ""
    print("Found {} model{} installed{}".format(mcnt, plural, msg))

    # Report on each of the installed models.
        
    if mcnt > 0: print("")
    for p in models:
        entry = utils.load_description(p)
        utils.print_meta_line(entry)

        # Update available commands for the model for fast bash tab completion.
        utils.update_completion_list(COMPLETION_COMMANDS, set(entry['commands']))

    # Suggest next step.
    
    if not args.quiet:
        if mcnt > 0:
            utils.print_next_step('installed', scenario='exist')
        else:
            utils.print_next_step('installed', scenario='none')
Esempio n. 3
0
def list_available(args):
    """List the name and title of the models in the Hub."""

    # Setup.

    logger = logging.getLogger(__name__)
    logger.info("List available models.")
    logger.debug(f"args: {args}")

    meta, repo = utils.get_repo_meta_data(args.mlhub)
    model_names = [entry["meta"]["name"] for entry in meta]

    # Update bash completion list.

    utils.update_model_completion(set(model_names))

    # List model name only.

    if args.name_only:
        print("\n".join(model_names))
        return

    # Provide some context.

    if not args.quiet:
        msg = "The repository '{}' provides the following models:\n"
        print(msg.format(repo))

    # List the meta data.

    for entry in meta:
        utils.print_meta_line(entry)

    # Suggest next step.

    if not args.quiet:
        utils.print_next_step("available")
        if not os.path.exists(utils.get_init_dir()):
            print(
                "Why not give the 'rain' model a go...\n\n"
                "  $ ml install rain\n"
            )
Esempio n. 4
0
def list_available(args):
    """List the name and title of the models in the Hub."""

    # Setup.

    mlhub = utils.get_repo(args.mlhub)
    meta  = utils.get_repo_meta_data(mlhub)

    # List model name only.

    if args.name_only:
        models = [info["meta"]["name"] for info in meta]
        print('\n'.join(models))
        return

    # Provide some context.

    if not args.quiet:
        print("The repository '{}' provides the following models:\n".format(mlhub))

    # List the meta data.

    for info in meta:
        utils.print_meta_line(info)

    # Update bash tab completion

    utils.update_completion_list(COMPLETION_MODELS, {e['meta']['name'] for e in meta})

    # Suggest next step.
    
    if not args.quiet:
        utils.print_next_step('available')
        if not os.path.exists(MLINIT):
            print("Why not give the 'rain' model a go...\n\n" +
                  "  $ ml install rain\n")
Esempio n. 5
0
def list_installed(args):
    """List the installed models."""

    # Find installed models.

    if os.path.exists(MLINIT):
        msg = "in '{}'.".format(MLINIT)
        models = [
            f for f in os.listdir(MLINIT)
            if os.path.isdir(os.path.join(MLINIT, f))
        ]
    else:
        msg = "since '{}' does not exist.".format(MLINIT)
        models = []

    # Report on how many models we found installed.

    mcnt = len(models)
    plural = "s"
    if mcnt == 1: plural = ""
    print("Found {} model{} installed {}".format(mcnt, plural, msg))

    # Report on each of the installed models.

    if mcnt > 0: print("")

    for p in models:
        entry = utils.load_description(p)
        utils.print_meta_line(entry)

    # Suggest next step.

    if not args.quiet:
        msg = "\nRun a model's demonstration script with:\n\n  $ {} demo <model>\n"
        msg = msg.format(CMD)
        print(msg)
Esempio n. 6
0
def list_installed(args):
    """List the installed models."""

    logger = logging.getLogger(__name__)
    logger.info('List installed models.')

    # Find installed models, ignoring special folders like R.

    init = utils.get_init_dir()
    if os.path.exists(init):
        msg = " in '{}'.".format(init)
        models = [
            f for f in os.listdir(init) if os.path.isdir(os.path.join(init, f))
            and f != "R" and not f.startswith('.') and not f.startswith('_')
        ]
    else:
        msg = ". '{}' does not exist.".format(init)
        models = []

    models.sort()

    # Only list model names

    if args.name_only:
        print('\n'.join(models))
        return

    # Report on how many models we found installed.

    mcnt = len(models)
    plural = "s" if mcnt != 1 else ""
    print("Found {} model{} installed{}".format(mcnt, plural, msg))

    # Report on each of the installed models.

    if mcnt > 0:
        print("")

    invalid_models = []
    for p in models:
        try:
            entry = utils.load_description(p)
            utils.print_meta_line(entry)
        except (utils.DescriptionYAMLNotFoundException,
                utils.MalformedYAMLException, KeyError):
            mcnt -= 1
            invalid_models.append(p)
            continue

        # Update bash completion list.

        if 'commands' in entry:
            utils.update_command_completion(set(entry['commands']))

    invalid_mcnt = len(invalid_models)
    if invalid_mcnt > 0:
        print("\nOf which {} model package{} {} broken:\n".format(
            invalid_mcnt, 's' if invalid_mcnt > 1 else '',
            'are' if invalid_mcnt > 1 else 'is'))
        print("  ====> \033[31m" + ', '.join(invalid_models) + "\033[0m")
        print(utils.get_command_suggestion('remove'))

    # Suggest next step.

    if not args.quiet:
        if mcnt > 0:
            utils.print_next_step('installed', scenario='exist')
        else:
            utils.print_next_step('installed', scenario='none')
Esempio n. 7
0
def list_installed(args):
    """List the installed models."""

    logger = logging.getLogger(__name__)
    logger.info("List installed models.")

    # Find installed models, ignoring special folders like R.

    init = utils.get_init_dir()
    if os.path.exists(init):
        msg = f" in '{init}'."
        models = [
            f
            for f in os.listdir(init)
            if os.path.isdir(os.path.join(init, f))
            and f != "R"
            and not f.startswith(".")
            and not f.startswith("_")
        ]
    else:
        msg = f". '{init}' does not exist."
        models = []

    models.sort()

    # Only list model names

    if args.name_only:
        print("\n".join(models))
        return

    # Report on how many models we found installed.

    mcnt = len(models)
    plural = "s" if mcnt != 1 else ""
    print(f"Found {mcnt} model{plural} installed{msg}")

    # Report on each of the installed models.

    if mcnt > 0:
        print("")

    invalid_models = []
    for p in models:
        try:
            entry = utils.load_description(p)
            utils.print_meta_line(entry)
        except (
            utils.DescriptionYAMLNotFoundException,
            utils.MalformedYAMLException,
            KeyError,
        ):
            mcnt -= 1
            invalid_models.append(p)
            continue

        # Update bash completion list.

        if "commands" in entry:
            utils.update_command_completion(set(entry["commands"]))

    invalid_mcnt = len(invalid_models)
    if invalid_mcnt > 0:
        print(
            "\nOf which {} model package{} {} broken:\n".format(
                invalid_mcnt,
                "s" if invalid_mcnt > 1 else "",
                "are" if invalid_mcnt > 1 else "is",
            )
        )
        print("  ====> \033[31m" + ", ".join(invalid_models) + "\033[0m")
        print(utils.get_command_suggestion("remove"))

    # Suggest next step.

    if not args.quiet:
        if mcnt > 0:
            utils.print_next_step("installed", scenario="exist")
        else:
            utils.print_next_step("installed", scenario="none")