<commit_before>#!/usr/bin/env python3

# -*- coding: utf8 -*-

import argparse
import os

def read_arg(args):
    """ Read cli argument and check if content the good value """

    parser = __create_parser()

    arg = vars(parser.parse_args())
 
    if arg["unicorn"]:
        __unicorn()

    if not arg["stopword_fr"] and not arg["stopword_en"]:
        if __stopword():
            print("""
            We can't download nltk stop word or you didn't want.
            Please use option --stopword-french and --stopword-english
            """)
            return None

    return arg

def __stopword():
    """ Try if nltk stop word is download if not propose to download it """
    try:
        from nltk.corpus import stopwords
    except ImportError:
        answer = input("You want download nltk stopword [y/n] : ")
        while answer.lower() not in ['y', 'n']:
            answer = input("Please answer with [y/n] : ")

        if answer.lower() == y:
            import nltk
            return nltk.download("stopwords")
        else:
            return false
    
        
def __create_parser():
    """ Create the parser of argument """

    parser = argparse.ArgumentParser(prog="adt_project",
                                     formatter_class=
                                     argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=__isdir, required=True,
                        help="directory content one dir per month")
    parser.add_argument("-o", "--output", type=str, required=True,
                        help="prefix of all output file")
    
    parser.add_argument("--stopword-fr", type=__isfile,
                        help="We read this file for french stop word")
    parser.add_argument("--stopword-en", type=__isfile,
                        help="We read this file for english stop word")
    
    # easter egg
    parser.add_argument("--unicorn", action='store_true',
                        help=argparse.SUPPRESS)

    return parser


def __isfile(val):
    val = str(val)

    if not os.path.isfile(val):
        raise argparse.ArgumentTypeError(val+" is not a file")
    
    return val
    
def __isdir(val):
    val = str(val)

    if not os.path.isdir(val):
        raise argparse.ArgumentTypeError(val+" is not a directory")

    return val

def __unicorn():
    print('\033[92m')
    print('\033[105m')
    print('\033[1m')
    print("""
                                                    /
                                                  .7
                                       \       , //
                                       |\.--._/|//<commit_msg>Now we check if all directory in output prefix is exist<commit_after>#!/usr/bin/env python3

# -*- coding: utf8 -*-

import argparse
import os


def read_arg(args):
    """ Read cli argument and check if content the good value """

    parser = __create_parser()

    arg = vars(parser.parse_args())
 
    if arg["unicorn"]:
        __unicorn()

    if not arg["stopword_fr"] and not arg["stopword_en"]:
        if __stopword():
            print("""
            We can't download nltk stop word or you didn't want.
            Please use option --stopword-french and --stopword-english
            """)
            return None

    return arg


def __stopword():
    """ Try if nltk stop word is download if not propose to download it """
    try:
        from nltk.corpus import stopwords
    except ImportError:
        answer = input("You want download nltk stopword [y/n] : ")
        while answer.lower() not in ['y', 'n']:
            answer = input("Please answer with [y/n] : ")

        if answer.lower() == y:
            import nltk
            return nltk.download("stopwords")
        else:
            return false
    
        
def __create_parser():
    """ Create the parser of argument """

    parser = argparse.ArgumentParser(prog="adt_project",
                                     formatter_class=
                                     argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=__isdir, required=True,
                        help="directory content one dir per month")
    parser.add_argument("-o", "--output", type=__output_check, required=True,
                        help="prefix of all output file")
    
    parser.add_argument("--stopword-fr", type=__isfile,
                        help="We read this file for french stop word")
    parser.add_argument("--stopword-en", type=__isfile,
                        help="We read this file for english stop word")
    
    # easter egg
    parser.add_argument("--unicorn", action='store_true',
                        help=argparse.SUPPRESS)

    return parser


def __isfile(val):
    val = str(val)

    if not os.path.isfile(val):
        raise argparse.ArgumentTypeError(val+" is not a file")
    
    return val


def __isdir(val):
    val = str(val)

    if not os.path.isdir(val):
        raise argparse.ArgumentTypeError(val+" is not a directory")

    return val


def __output_check(val):
    val = str(val)

    total_path = ""
    for dir_name in os.path.splitext(os.path.dirname(val)):
        total_path = os.path.join(total_path, dir_name)
        if not os.path.isdir(total_path):
            raise argparse.ArgumentTypeError(total_path+"  is not a directory")

    return val
    

def __unicorn():
    print('\033[92m')
    print('\033[105m')
    print('\033[1m')
    print("""
                                                    /
                                                  .7
                                       \       , //
                                       |\.--._/|//
{'fraction_non_alphanumeric': 0.11128747795414462, 'fraction_numerical': 0.006349206349206349, 'mean_word_length': 1.6549625468164795, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2792655', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1543, 'n_words': 433}