Exemple #1
0
    def add(self, repo):
        config = load_config()

        if repo.endswith(".git"):
            # Get relative path from project root to current directory
            challenge_path = Path(
                os.path.relpath(os.getcwd(), get_project_path()))

            # Get new directory that will exist after clone
            base_repo_path = Path(
                os.path.basename(repo).rsplit(".", maxsplit=1)[0])

            # Join targets
            challenge_path = challenge_path / base_repo_path
            print(challenge_path)

            config["challenges"][str(challenge_path)] = repo

            with open(get_config_path(), "w+") as f:
                config.write(f)

            subprocess.call(["git", "clone", "--depth", "1", repo])
            shutil.rmtree(str(base_repo_path / ".git"))
        elif Path(repo).exists():
            config["challenges"][repo] = repo
            with open(get_config_path(), "w+") as f:
                config.write(f)
        else:
            click.secho(
                "Couldn't process that challenge path. Please check it for errors.",
                fg="red",
            )
Exemple #2
0
    def add(self, repo):
        config = load_config()

        if repo.endswith(".git"):
            # Get relative path from project root to current directory
            challenge_path = Path(os.path.relpath(os.getcwd(), get_project_path()))

            # Get new directory that will add the git subtree
            base_repo_path = Path(os.path.basename(repo).rsplit(".", maxsplit=1)[0])

            # Join targets
            challenge_path = challenge_path / base_repo_path
            print(challenge_path)

            config["challenges"][str(challenge_path)] = repo

            head_branch = get_git_repo_head_branch(repo)
            subprocess.call(
                [
                    "git",
                    "subtree",
                    "add",
                    "--prefix",
                    challenge_path,
                    repo,
                    head_branch,
                    "--squash",
                ],
                cwd=get_project_path(),
            )
            with open(get_config_path(), "w+") as f:
                config.write(f)

            subprocess.call(
                ["git", "add", ".ctf/config"], cwd=get_project_path(),
            )
            subprocess.call(
                ["git", "commit", "-m", f"Added {str(challenge_path)}"],
                cwd=get_project_path(),
            )

        elif Path(repo).exists():
            config["challenges"][repo] = repo
            with open(get_config_path(), "w+") as f:
                config.write(f)
        else:
            click.secho(
                "Couldn't process that challenge path. Please check it for errors.",
                fg="red",
            )
Exemple #3
0
    def view(self, color=True, json=False):
        config = get_config_path()
        with open(config) as f:
            if json is True:
                config = preview_config(as_string=True)
                if color:
                    config = highlight(config, JsonLexer(), TerminalFormatter())
            else:
                config = f.read()
                if color:
                    config = highlight(config, IniLexer(), TerminalFormatter())

            print(config)
Exemple #4
0
 def path(self):
     click.echo(get_config_path())
Exemple #5
0
 def edit(self):
     editor = os.getenv("EDITOR", "vi")
     command = editor, get_config_path()
     subprocess.call(command)