<commit_before>import os
import subprocess
from .helpers import copy_files


repo_dir = '.gitpress'
templates_path = os.path.join(os.path.dirname(__file__), 'templates')
default_template_path = os.path.join(templates_path, 'default')


class RepositoryAlreadyExistsError(Exception):
    """Indicates 'repo_dir' already exists while attempting to create a new one."""
    def __init__(self, directory=None, repo=None):
        super(RepositoryAlreadyExistsError, self).__init__()
        self.directory = os.path.abspath(directory) if directory else os.getcwd()
        self.repo = repo or repo_path(self.directory)


class RepositoryNotFoundError(Exception):
    """Indicates an existing 'present_dir' is required, but was not found."""
    def __init__(self, directory=None):
        super(RepositoryNotFoundError, self).__init__()
        self.directory = os.path.abspath(directory) if directory else os.getcwd()


def require_repo(directory=None):
    """Checks for a presentation repository and raises an exception if not found."""
    if directory and not os.path.isdir(directory):
        raise ValueError('Directory not found: ' + repr(directory))
    repo = repo_path(directory)
    if not os.path.isdir(repo):
        raise RepositoryNotFoundError(directory)
    return repo


def repo_path(directory=None):
    """Gets the presentation repository from the specified directory."""
    return os.path.join(directory, repo_dir) if directory else repo_dir


def init(directory=None):
    """Initializes a Gitpress presentation repository at the specified directory."""
    repo = repo_path(directory)
    if os.path.isdir(repo):
        raise RepositoryAlreadyExistsError(directory, repo)

    # Initialize repository with default template
    copy_files(default_template_path, repo)

    message = '"Default presentation content."'
    subprocess.call(['git', 'init', '-q', repo])
    subprocess.call(['git', 'add', '.'], cwd=repo)
    subprocess.call(['git', 'commit', '-q', '-m', message], cwd=repo)

    return repo


def presentation_files(directory=None):
    """Gets a list of the repository presentation files relative to 'directory'."""
    return list(iterate_presentation_files(directory))


def iterate_presentation_files(directory=None):
    """Iterates the repository presentation files relative to 'directory'."""
    repo = require_repo(directory)
    for root, dirs, files in os.walk(repo):
        for f in files:
            yield os.path.join(root, f)<commit_msg>Exclude special file names from presentation.<commit_after>import os
import re
import fnmatch
import subprocess
from .helpers import copy_files


repo_dir = '.gitpress'
templates_path = os.path.join(os.path.dirname(__file__), 'templates')
default_template_path = os.path.join(templates_path, 'default')
specials = ['.*', '_*']
specials_re = re.compile('|'.join([fnmatch.translate(x) for x in specials]))


class RepositoryAlreadyExistsError(Exception):
    """Indicates 'repo_dir' already exists while attempting to create a new one."""
    def __init__(self, directory=None, repo=None):
        super(RepositoryAlreadyExistsError, self).__init__()
        self.directory = os.path.abspath(directory) if directory else os.getcwd()
        self.repo = repo or repo_path(self.directory)


class RepositoryNotFoundError(Exception):
    """Indicates an existing 'present_dir' is required, but was not found."""
    def __init__(self, directory=None):
        super(RepositoryNotFoundError, self).__init__()
        self.directory = os.path.abspath(directory) if directory else os.getcwd()


def require_repo(directory=None):
    """Checks for a presentation repository and raises an exception if not found."""
    if directory and not os.path.isdir(directory):
        raise ValueError('Directory not found: ' + repr(directory))
    repo = repo_path(directory)
    if not os.path.isdir(repo):
        raise RepositoryNotFoundError(directory)
    return repo


def repo_path(directory=None):
    """Gets the presentation repository from the specified directory."""
    return os.path.join(directory, repo_dir) if directory else repo_dir


def init(directory=None):
    """Initializes a Gitpress presentation repository at the specified directory."""
    repo = repo_path(directory)
    if os.path.isdir(repo):
        raise RepositoryAlreadyExistsError(directory, repo)

    # Initialize repository with default template
    copy_files(default_template_path, repo)

    message = '"Default presentation content."'
    subprocess.call(['git', 'init', '-q', repo])
    subprocess.call(['git', 'add', '.'], cwd=repo)
    subprocess.call(['git', 'commit', '-q', '-m', message], cwd=repo)

    return repo


def presentation_files(directory=None):
    """Gets a list of the repository presentation files relative to 'directory', not including themes."""
    return list(iterate_presentation_files(directory))


def iterate_presentation_files(directory=None):
    """Iterates the repository presentation files relative to 'directory', not including themes."""
    repo = require_repo(directory)
    for root, dirs, files in os.walk(repo):
        dirs[:] = [d for d in dirs if not specials_re.match(d)]
        files = [f for f in files if not specials_re.match(f)]
        for f in files:
            yield os.path.join(root, f)
{'fraction_non_alphanumeric': 0.11343508573582062, 'fraction_numerical': 0.0, 'mean_word_length': 4.276341948310139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '623018', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1449, 'n_words': 443}