<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Synchronizes patches and packaging between this repo and a local copy of ungoogled-chromium-debian
'''

import argparse
import logging
import shutil
import stat
from pathlib import Path

import git # GitPython

# Prefix of packaging and patches branch names
_BRANCH_PREFIX = 'ungoogled_'

_ENCODING = 'UTF-8'


def _get_logger():
    '''Gets logger'''

    logger = logging.getLogger(__name__)

    if logger.level == logging.NOTSET:
        logger.setLevel(logging.DEBUG)

        if not logger.hasHandlers():
            console_handler = logging.StreamHandler()
            console_handler.setLevel(logging.DEBUG)

            formatter = logging.Formatter('%(levelname)s: %(message)s')
            console_handler.setFormatter(formatter)

            logger.addHandler(console_handler)
    return logger


def _get_current_repo():
    '''Returns the git.Repo for ungoogled-chromium'''
    repo_path = str(Path(__file__).parent.parent)
    try:
        return git.Repo(repo_path)
    except git.InvalidGitRepositoryError:
        _get_logger().error('Not a valid git repo (for ungoogled-chromium): %s', repo_path)
        exit(1)


def _get_other_repo(args):
    '''Returns the git.Repo for ungoogled-chromium-debian'''
    try:
        return git.Repo(args.repo_path)
    except git.InvalidGitRepositoryError:
        _get_logger().error('Not a valid git repo (for ungoogled-chromium-debian): %s',
                            args.repo_path)
        exit(1)


def _generate_ungoogled_heads(repo):
    '''Returns an iterable of ungoogled_* git.Head branch heads'''
    for head in repo.branches:
        if head.name.startswith(_BRANCH_PREFIX):
            yield head.name[len(_BRANCH_PREFIX):], head


class _NoMatchingPathError(BaseException):
    '''No git.Tree or git.Blob matching the parameters could be found'''
    pass


def _get_path_safely(base_tree, file_path, must_exist=True):
    '''
    Returns the git.Tree or git.Blob at base_tree / file_path safely.
<commit_msg>devutils: Remove unnecessary pass statement for pylint<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Synchronizes patches and packaging between this repo and a local copy of ungoogled-chromium-debian
'''

import argparse
import logging
import shutil
import stat
from pathlib import Path

import git # GitPython

# Prefix of packaging and patches branch names
_BRANCH_PREFIX = 'ungoogled_'

_ENCODING = 'UTF-8'


def _get_logger():
    '''Gets logger'''

    logger = logging.getLogger(__name__)

    if logger.level == logging.NOTSET:
        logger.setLevel(logging.DEBUG)

        if not logger.hasHandlers():
            console_handler = logging.StreamHandler()
            console_handler.setLevel(logging.DEBUG)

            formatter = logging.Formatter('%(levelname)s: %(message)s')
            console_handler.setFormatter(formatter)

            logger.addHandler(console_handler)
    return logger


def _get_current_repo():
    '''Returns the git.Repo for ungoogled-chromium'''
    repo_path = str(Path(__file__).parent.parent)
    try:
        return git.Repo(repo_path)
    except git.InvalidGitRepositoryError:
        _get_logger().error('Not a valid git repo (for ungoogled-chromium): %s', repo_path)
        exit(1)


def _get_other_repo(args):
    '''Returns the git.Repo for ungoogled-chromium-debian'''
    try:
        return git.Repo(args.repo_path)
    except git.InvalidGitRepositoryError:
        _get_logger().error('Not a valid git repo (for ungoogled-chromium-debian): %s',
                            args.repo_path)
        exit(1)


def _generate_ungoogled_heads(repo):
    '''Returns an iterable of ungoogled_* git.Head branch heads'''
    for head in repo.branches:
        if head.name.startswith(_BRANCH_PREFIX):
            yield head.name[len(_BRANCH_PREFIX):], head


class _NoMatchingPathError(BaseException):
    '''No git.Tree or git.Blob matching the parameters could be found'''


def _get_path_safely(base_tree, file_path, must_exist=True):
    '''
    Returns the git.Tree or git.Blob at base_tree / file_path safely.

{'fraction_non_alphanumeric': 0.10237173281703775, 'fraction_numerical': 0.002420135527589545, 'mean_word_length': 3.2433264887063653, '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': '3368589', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1240, 'n_words': 319}