<commit_before>import logging
import os
import shutil
import subprocess
import time

log = logging.getLogger(__name__)


def checkout_repo(repo_url, dest_path, branch):
    # if os.path.isdir(path):
    #     p = subprocess.Popen('git status', shell=True, cwd=path)
    #     if p.wait() == 128:
    #         log.info("Repo at %s appears corrupt; removing",
    #                  branch)
    #         shutil.rmtree(path)

    if not os.path.isdir(dest_path):
        log.info("Cloning %s %s from upstream", repo_url, branch)
        log.info(
            subprocess.check_output(('git', 'clone', '--branch', branch,
                                     repo_url, dest_path),
                                    cwd=os.path.dirname(dest_path))
        )
    elif time.time() - os.stat('/etc/passwd').st_mtime > 60:
        # only do this at most once per minute
        log.info("Fetching %s from upstream", branch)
        log.info(
            subprocess.check_output(('git', 'fetch', '-p', 'origin'),
                                    cwd=dest_path)
        )
        log.info(
            subprocess.check_output(('touch', dest_path))
        )
    else:
        log.info("%s was just updated; assuming it is current", branch)

    # This try/except block will notice if the requested branch doesn't
    # exist, whether it was cloned or fetched.
    try:
        subprocess.check_output(
            ('git', 'reset', '--hard', 'origin/%s' % branch),
            cwd=dest_path,
        )
    except subprocess.CalledProcessError:
        shutil.rmtree(dest_path)
        raise BranchNotFoundError(branch)


class BranchNotFoundError(ValueError):
    def __init__(self, branch):
        self.branch = branch

    def __str__(self):
        return "teuthology branch not found: '{0}'".format(self.branch)<commit_msg>Generalize error message<commit_after>import logging
import os
import shutil
import subprocess
import time

log = logging.getLogger(__name__)


def checkout_repo(repo_url, dest_path, branch):
    # if os.path.isdir(path):
    #     p = subprocess.Popen('git status', shell=True, cwd=path)
    #     if p.wait() == 128:
    #         log.info("Repo at %s appears corrupt; removing",
    #                  branch)
    #         shutil.rmtree(path)

    if not os.path.isdir(dest_path):
        log.info("Cloning %s %s from upstream", repo_url, branch)
        log.info(
            subprocess.check_output(('git', 'clone', '--branch', branch,
                                     repo_url, dest_path),
                                    cwd=os.path.dirname(dest_path))
        )
    elif time.time() - os.stat('/etc/passwd').st_mtime > 60:
        # only do this at most once per minute
        log.info("Fetching %s from upstream", branch)
        log.info(
            subprocess.check_output(('git', 'fetch', '-p', 'origin'),
                                    cwd=dest_path)
        )
        log.info(
            subprocess.check_output(('touch', dest_path))
        )
    else:
        log.info("%s was just updated; assuming it is current", branch)

    # This try/except block will notice if the requested branch doesn't
    # exist, whether it was cloned or fetched.
    try:
        subprocess.check_output(
            ('git', 'reset', '--hard', 'origin/%s' % branch),
            cwd=dest_path,
        )
    except subprocess.CalledProcessError:
        shutil.rmtree(dest_path)
        raise BranchNotFoundError(branch, repo_url)


class BranchNotFoundError(ValueError):
    def __init__(self, branch, repo):
        self.branch = branch
        self.repo = repo

    def __str__(self):
        return "Branch {branch} not found in repo: {repo}".format(
            branch=self.branch, repo=self.repo)
{'fraction_non_alphanumeric': 0.11767852366943032, 'fraction_numerical': 0.002941963091735758, 'mean_word_length': 2.040650406504065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253256', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1088, 'n_words': 275}