Пример #1
0
def readme(args):
    """Display the model's README information."""

    model = args.model

    # Correct model name if possible.

    matched_model = utils.get_misspelled_pkg(model)
    if matched_model is not None:
        model = matched_model

    # Setup.

    logger = logging.getLogger(__name__)
    logger.info("Get README of {}.".format(model))

    path = utils.get_package_dir(model)
    readme_file = os.path.join(path, README)

    # Check that the model is installed.

    utils.check_model_installed(model)

    # Display the README.

    if not os.path.exists(
            readme_file):  # Try to generate README from README.md
        readme_raw = readme_file[:readme_file.rfind('.')] + '.md'
        if not os.path.exists(readme_raw):
            readme_raw = readme_raw[:readme_raw.rfind('.')] + '.rst'
            if not os.path.exists(readme_raw):
                raise utils.ModelReadmeNotFoundException(model, readme_file)

        script = os.path.join(os.path.dirname(__file__), 'scripts',
                              'convert_readme.sh')
        command = "/bin/bash {} {} {}".format(script, readme_raw, README)
        proc = subprocess.Popen(command,
                                shell=True,
                                cwd=path,
                                stderr=subprocess.PIPE)
        output, errors = proc.communicate()
        if proc.returncode != 0:
            errors = errors.decode("utf-8")
            command_not_found = re.compile(r"\d: (.*):.*not found").search(
                errors)
            if command_not_found is not None:
                raise utils.LackPrerequisiteException(
                    command_not_found.group(1))

            print("An error was encountered:\n")
            print(errors)
            raise utils.ModelReadmeNotFoundException(model, readme_file)

    with open(readme_file, 'r') as f:
        print(utils.drop_newline(f.read()))

    # Suggest next step.

    if not args.quiet:
        utils.print_next_step('readme', model=model)
Пример #2
0
def readme(args):
    """Display the model's README information."""

    # Setup.
    
    model  = args.model
    path   = MLINIT + model
    readme = os.path.join(path, README)

    # Check that the model is installed.

    utils.check_model_installed(model)
    
    # Display the README.
    
    with open(readme, 'r') as f:
        print(utils.drop_newline(f.read()))
    
    # Suggest next step.

    if not args.quiet:
        utils.print_next_step('readme', model=model)