Beispiel #1
0
def cli(ctx, reset):
    """Config command for Minitrino."""

    if not os.path.isdir(ctx.minitrino_user_dir):
        ctx.logger.log(
            f"No {ctx.minitrino_user_dir} directory found. Creating...")
        os.mkdir(ctx.minitrino_user_dir)

    if os.path.isfile(ctx.config_file) and not reset:
        ctx.logger.log(
            f"Opening existing config file at path: {ctx.config_file}",
            level=ctx.logger.verbose,
        )
        edit_file()
    elif os.path.isfile(ctx.config_file) and reset:
        response = ctx.logger.prompt_msg(
            f"Configuration file exists. Overwrite? [Y/N]")
        if utils.validate_yes(response):
            write_template()
            edit_file()
        else:
            ctx.logger.log(
                f"Opted out of recreating {ctx.minitrino_user_dir} file.")
    else:
        ctx.logger.log(
            f"No config file found at path: {ctx.config_file}. "
            f"Creating template config file and opening for edits...",
            level=ctx.logger.verbose,
        )
        write_template()
        edit_file()
Beispiel #2
0
def check_exists(ctx, name, directory, force):
    """Checks if the resulting tarball exists. If it exists, the user is
    prompted to overwrite the existing file."""

    if force:
        return

    snapshot_file = os.path.abspath(os.path.join(directory, f"{name}.tar.gz"))
    if os.path.isfile(snapshot_file):
        response = ctx.logger.prompt_msg(
            f"Snapshot file {name}.tar.gz already exists. Overwrite? [Y/N]")
        if not utils.validate_yes(response):
            ctx.logger.log(f"Opted to skip snapshot.")
            sys.exit(0)
Beispiel #3
0
def handle_copy_config_file(ctx, snapshot_name_dir, no_scrub):
    """Handles the copying of the user config file to the named snapshot
    directory. Calls `scrub_config_file()` if `no_scrub` is True."""

    if no_scrub:
        response = ctx.logger.prompt_msg(
            f"All sensitive information in user config will be added to the snapshot. Continue? [Y/N]"
        )
        if utils.validate_yes(response):
            copy_config_file(snapshot_name_dir, no_scrub)
        else:
            ctx.logger.log(f"Opted to scrub sensitive user config data.")
            copy_config_file(snapshot_name_dir)
    else:
        copy_config_file(snapshot_name_dir)
Beispiel #4
0
def cli(ctx, version):
    """Library installation command for Minitrino."""

    if not version:
        version = utils.get_cli_ver()

    lib_dir = os.path.join(ctx.minitrino_user_dir, "lib")
    if os.path.isdir(lib_dir):
        response = ctx.logger.prompt_msg(
            f"The Minitrino library at {lib_dir} will be overwritten. "
            f"Continue? [Y/N]")
        if utils.validate_yes(response):
            ctx.logger.log("Removing existing library directory...",
                           level=ctx.logger.verbose)
            shutil.rmtree(lib_dir)
        else:
            ctx.logger.log("Opted to skip library installation.")
            sys.exit(0)

    download_and_extract(version)
    ctx.logger.log("Library installation complete.")
Beispiel #5
0
def cli(ctx, images, volumes, labels, force):
    """Remove command for Minitrino."""

    utils.check_daemon(ctx.docker_client)

    if all((not images, not volumes, not labels)) or all(
        (images, volumes, not labels)):
        response = ctx.logger.prompt_msg(
            "You are about to all remove minitrino images and volumes. Continue? [Y/N]"
        )
        if utils.validate_yes(response):
            remove_items(IMAGE, force)
            remove_items(VOLUME, force)
        else:
            ctx.logger.log(f"Opted to skip resource removal.")
            sys.exit(0)

    if images:
        remove_items(IMAGE, force, labels)
    if volumes:
        remove_items(VOLUME, force, labels)

    ctx.logger.log(f"Removal complete.")