<commit_before>import os

from . import constants
from .source import Repo
from .compiler.compose.common import container_code_path
from .systems.docker.common import spec_for_service
from .systems.rsync import sync_local_path_to_vm
from .path import parent_dir

def _write_commands_to_file(list_of_commands, file_location):
    file_location_parent = parent_dir(file_location)
    if not os.path.exists(file_location_parent):
        os.makedirs(file_location_parent)
    with open(file_location, 'w+') as f:
        for command in list_of_commands:
            f.write('{} \n'.format(command))

def _check_piped_command_success():
    return 'test $PIPESTATUS -eq 0'

def _get_once_commands(app_spec):
    once_commands = app_spec['commands']['once']
    commands_with_function = []
    if once_commands:
        commands_with_function.append('dusty_once_fn () {')
        commands_with_function += once_commands
        commands_with_function.append('}')
    commands_with_function.append("if [ ! -f {} ]".format(constants.FIRST_RUN_FILE_PATH))
    commands_with_function.append("then mkdir -p {}".format(constants.RUN_DIR))
    commands_with_function.append("touch {}".format(constants.FIRST_RUN_FILE_PATH))
    if once_commands:
        commands_with_function.append("dusty_once_fn | tee {}".format(constants.ONCE_LOG_PATH))
        commands_with_function.append(_check_piped_command_success())

    commands_with_function.append("fi")
    return commands_with_function

def _get_always_commands(app_spec):
    commands_with_function = []
    always_commands = app_spec['commands']['always']
    if always_commands:
        commands_with_function.append('dusty_always_fn () {')
        commands_with_function += always_commands
        commands_with_function.append('}')
        commands_with_function.append('dusty_always_fn | tee {}'.format(constants.ALWAYS_LOG_PATH))
        commands_with_function.append(_check_piped_command_success())
    return commands_with_function

def _compile_docker_commands(app_name, assembled_specs):
    """ This is used to compile the command that will be run when the docker container starts
    up. This command has to install any libs that the app uses, run the `always` command, and
    run the `once` command if the container is being launched for the first time """<commit_msg>lets redirect stderr to the log file as well<commit_after>import os

from . import constants
from .source import Repo
from .compiler.compose.common import container_code_path
from .systems.docker.common import spec_for_service
from .systems.rsync import sync_local_path_to_vm
from .path import parent_dir

def _write_commands_to_file(list_of_commands, file_location):
    file_location_parent = parent_dir(file_location)
    if not os.path.exists(file_location_parent):
        os.makedirs(file_location_parent)
    with open(file_location, 'w+') as f:
        for command in list_of_commands:
            f.write('{} \n'.format(command))

def _check_piped_command_success():
    return 'test $PIPESTATUS -eq 0'

def _get_once_commands(app_spec):
    once_commands = app_spec['commands']['once']
    commands_with_function = []
    if once_commands:
        commands_with_function.append('dusty_once_fn () {')
        commands_with_function += once_commands
        commands_with_function.append('}')
    commands_with_function.append("if [ ! -f {} ]".format(constants.FIRST_RUN_FILE_PATH))
    commands_with_function.append("then mkdir -p {}".format(constants.RUN_DIR))
    commands_with_function.append("touch {}".format(constants.FIRST_RUN_FILE_PATH))
    if once_commands:
        commands_with_function.append("dusty_once_fn 2>&1 | tee {}".format(constants.ONCE_LOG_PATH))
        commands_with_function.append(_check_piped_command_success())

    commands_with_function.append("fi")
    return commands_with_function

def _get_always_commands(app_spec):
    commands_with_function = []
    always_commands = app_spec['commands']['always']
    if always_commands:
        commands_with_function.append('dusty_always_fn () {')
        commands_with_function += always_commands
        commands_with_function.append('}')
        commands_with_function.append('dusty_always_fn 2>&1 | tee {}'.format(constants.ALWAYS_LOG_PATH))
        commands_with_function.append(_check_piped_command_success())
    return commands_with_function

def _compile_docker_commands(app_name, assembled_specs):
    """ This is used to compile the command that will be run when the docker container starts
    up. This command has to install any libs that the app uses, run the `always` command, and
    run the `once` command if the container is being launched for the first time """
{'fraction_non_alphanumeric': 0.09220917822838848, 'fraction_numerical': 0.0012806830309498398, 'mean_word_length': 4.693803159173754, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186198', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1387, 'n_words': 306}