<commit_before>'''
These are all the functions that are used when you `cytoplasm build`.
'''

import os, shutil
from cytoplasm import errors, interpreters, configuration
from cytoplasm.controllers import controllerclass

def copy_over(config):
    "Copy the files not beginning with '_' to the site directory"
    interpreter_dictionary = config.interpreters
    # All of the files and directories that don't begin with '_' or '.'
    to_copy = [file for file in os.listdir(".") if not file.startswith(("_", "."))]
    files = [file for file in to_copy if not os.path.isdir(file)]
    for file in files:
        # get the last suffix:
        suffix = file.split(".")[-1]
        # if the suffix is in interpreters.keys() the destination is everything but that last suffix
        if suffix in config.interpreters.keys():
            destination = ".".join(file.split(".")[:-1])
        # otherwise, it's the whole thing.
        else:
            destination = file
        # and pass the origin and destination to interpreters.interpret.
        interpreters.interpret(file, "%s/%s" %(config.build_dir, destination))
    directories = [file for file in to_copy if os.path.isdir(file)]
    for dir in directories:
        if os.path.exists("%s/%s" %(config.build_dir, dir)):
            # if the directory exists, delete it.
            shutil.rmtree("%s/%s" %(config.build_dir, dir))
        # copy all the directories that don't start with "." or "_" completely.
        shutil.copytree(dir, "%s/%s" %(config.build_dir, dir))

def build(dir="."):
    # Set the directory in cytoplasm.configuration, so everything gets the same configuration.
    configuration.source_dir = os.path.join(os.getcwd(), dir)
    # Get the configuration file...
    config = configuration.get_config()
    # save the current working directory, so we can return to it later.
    oldwd = os.getcwd()
    # and then change directories, to the source directory.
    os.chdir(configuration.source_dir)
    # Create the build directory, if it doesn't exist
    if not os.path.exists(config.build_dir):
        os.mkdir(config.build_dir)
    copy_over(config)
    for controller, arguments in config.controllers:
        # create a controller object of the class returned by controllerclass
        controller_object = controllerclass(controller)(*arguments)
        # call the controller object <commit_msg>always use os.path.join, rather than "%s/%s".<commit_after>'''
These are all the functions that are used when you `cytoplasm build`.
'''

import os, shutil
from cytoplasm import errors, interpreters, configuration
from cytoplasm.controllers import controllerclass

def copy_over(config):
    "Copy the files not beginning with '_' to the site directory"
    interpreter_dictionary = config.interpreters
    # All of the files and directories that don't begin with '_' or '.'
    to_copy = [file for file in os.listdir(".") if not file.startswith(("_", "."))]
    files = [file for file in to_copy if not os.path.isdir(file)]
    for file in files:
        # get the last suffix:
        suffix = file.split(".")[-1]
        # if the suffix is in interpreters.keys() the destination is everything but that last suffix
        if suffix in config.interpreters.keys():
            destination = ".".join(file.split(".")[:-1])
        # otherwise, it's the whole thing.
        else:
            destination = file
        # and pass the origin and destination to interpreters.interpret.
        interpreters.interpret(file, os.path.join(config.build_dir, destination))
    directories = [file for file in to_copy if os.path.isdir(file)]
    for dir in directories:
        if os.path.exists(os.path.join(config.build_dir, dir)):
            # if the directory exists, delete it.
            shutil.rmtree(os.path.join(config.build_dir, dir))
        # copy all the directories that don't start with "." or "_" completely.
        shutil.copytree(dir, os.path.join(config.build_dir, dir))

def build(dir="."):
    # Set the directory in cytoplasm.configuration, so everything gets the same configuration.
    configuration.source_dir = os.path.join(os.getcwd(), dir)
    # Get the configuration file...
    config = configuration.get_config()
    # save the current working directory, so we can return to it later.
    oldwd = os.getcwd()
    # and then change directories, to the source directory.
    os.chdir(configuration.source_dir)
    # Create the build directory, if it doesn't exist
    if not os.path.exists(config.build_dir):
        os.mkdir(config.build_dir)
    copy_over(config)
    for controller, arguments in config.controllers:
        # create a controller object of the class returned by controllerclass
        controller_object = controllerclass(controller)(*arguments)
        # call the controller object 
{'fraction_non_alphanumeric': 0.10295341098169718, 'fraction_numerical': 0.0008319467554076539, 'mean_word_length': 3.0823429541595924, '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': '4467470', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1317, 'n_words': 475}