Example #1
0
    def install(self, challenge=None, force=False):
        if challenge is None:
            challenge = os.getcwd()

        path = Path(challenge)

        if path.name.endswith(".yml") is False:
            path = path / "challenge.yml"

        click.secho(f"Found {path}")
        challenge = load_challenge(path)
        click.secho(f'Loaded {challenge["name"]}', fg="yellow")

        installed_challenges = load_installed_challenges()
        for c in installed_challenges:
            if c["name"] == challenge["name"]:
                click.secho(
                    "Already found existing challenge with same name. Perhaps you meant sync instead of install?",
                    fg="red",
                )
                if force is True:
                    click.secho(
                        "Ignoring existing challenge because of --force",
                        fg="yellow")
                else:
                    return

        click.secho(f'Installing {challenge["name"]}', fg="yellow")
        create_challenge(challenge=challenge)
        click.secho(f"Success!", fg="green")
Example #2
0
    def install(self, challenge=None, force=False, ignore=()):
        if challenge is None:
            # Get all challenges if not specifying a challenge
            config = load_config()
            challenges = dict(config["challenges"]).keys()
        else:
            challenges = [challenge]

        if isinstance(ignore, str):
            ignore = (ignore,)

        for challenge in challenges:
            path = Path(challenge)

            if path.name.endswith(".yml") is False:
                path = path / "challenge.yml"

            click.secho(f"Found {path}")
            challenge = load_challenge(path)
            click.secho(f'Loaded {challenge["name"]}', fg="yellow")

            installed_challenges = load_installed_challenges()
            for c in installed_challenges:
                if c["name"] == challenge["name"]:
                    click.secho(
                        f'Already found existing challenge with same name ({challenge["name"]}). Perhaps you meant sync instead of install?',
                        fg="red",
                    )
                    if force is True:
                        click.secho(
                            "Ignoring existing challenge because of --force",
                            fg="yellow",
                        )
                    else:
                        break
            else:  # If we don't break because of duplicated challenge names
                click.secho(f'Installing {challenge["name"]}', fg="yellow")
                create_challenge(challenge=challenge, ignore=ignore)
                click.secho(f"Success!", fg="green")