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

from __future__ import print_function

import subprocess
import select
import os
import logger
import time


class BashCommand():
    READ_SIZE = 1024

    class ExecutionError(Exception):
        '''
        For more convenient analysis of bash command execution errors
        '''
        def __init__(self, command, exitCode, stdErr):
            '''
            @param command bash command which caused an execution error
            @param exitCode exit code of the command returned by bash
            @param stdErr output passed to stderr by the command
            '''
            Exception.__init__(self)
            self.command = command
            self.exitCode = exitCode
            self.stdErr = stdErr

        def __str__(self):
            return '\nBash command: %s\nExit code: %s\nStd err: %s' % \
                    (self.command, self.exitCode, self.stdErr)

    def __init__(self, command, description='', input=''):
        self.command = command
        self.description = description
        self.input = input

        self.startTime = 0
        self.endTime = 0
        self.duration = 0

        self._cleanupTemporaryData()

    def __str__(self):
        return '<BashCommand> "%s" "%s"' % (self.description, self.command)

    def _cleanupTemporaryData(self):
        self.logger = None
        self.inputLines = []
        self.process = None
        self.inputStreams = []
        self.outputStreams = []
        self.errMsg = ''

    def execute(self, logger=None):
        # Set logger
        self.logger = logger
        self.startTime = time.time()
        self._createSubprocess()
        self._prepareInputStreamsAndData()
        self._prepareOutputStreams()
        self._waitForIOCompletion()
        self.process.wait()
        self.endTime = time.time()
        self.duration = self.endTime - self.startTime
        self._checkReturnCode()

        self._cleanupTemporaryData()

    def _createSubprocess(self):
        self.process = subprocess.Popen(
            ['/usr/bin/bash', '-c', self.command],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

    def _prepareInputStreamsAndData(self):
        if self.input:<commit_msg>Change bash path to distribution independant<commit_after>#!/usr/bin/env python2

from __future__ import print_function

import subprocess
import select
import os
import logger
import time


class BashCommand():
    READ_SIZE = 1024

    class ExecutionError(Exception):
        '''
        For more convenient analysis of bash command execution errors
        '''
        def __init__(self, command, exitCode, stdErr):
            '''
            @param command bash command which caused an execution error
            @param exitCode exit code of the command returned by bash
            @param stdErr output passed to stderr by the command
            '''
            Exception.__init__(self)
            self.command = command
            self.exitCode = exitCode
            self.stdErr = stdErr

        def __str__(self):
            return '\nBash command: %s\nExit code: %s\nStd err: %s' % \
                    (self.command, self.exitCode, self.stdErr)

    def __init__(self, command, description='', input=''):
        self.command = command
        self.description = description
        self.input = input

        self.startTime = 0
        self.endTime = 0
        self.duration = 0

        self._cleanupTemporaryData()

    def __str__(self):
        return '<BashCommand> "%s" "%s"' % (self.description, self.command)

    def _cleanupTemporaryData(self):
        self.logger = None
        self.inputLines = []
        self.process = None
        self.inputStreams = []
        self.outputStreams = []
        self.errMsg = ''

    def execute(self, logger=None):
        # Set logger
        self.logger = logger
        self.startTime = time.time()
        self._createSubprocess()
        self._prepareInputStreamsAndData()
        self._prepareOutputStreams()
        self._waitForIOCompletion()
        self.process.wait()
        self.endTime = time.time()
        self.duration = self.endTime - self.startTime
        self._checkReturnCode()

        self._cleanupTemporaryData()

    def _createSubprocess(self):
        self.process = subprocess.Popen(
            ['/usr/bin/env', 'bash', '-c', self.command],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

    def _prepareInputStreamsAndData(self):
        if self.input:
{'fraction_non_alphanumeric': 0.09520697167755991, 'fraction_numerical': 0.003485838779956427, 'mean_word_length': 2.0709030100334447, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7079016', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1215, 'n_words': 315}