<commit_before>import time
import subprocess
import logging
import re
import glob
import os
import pdb


def unmount(cmd, mountpoint, tries=20):
    '''
    A method that unmounts the given mountpoint using the given unmounting
    command, giving it a couple of tries if necessary
    '''
    cmd.append(mountpoint)
    try_persistent(cmd, tries=tries)
    for _ in range(tries):
        if os.listdir(mountpoint) == []:
            # Unmount was successful, remove mountpoint
            os.rmdir(mountpoint)
            break
        else:
            time.sleep(1)
    if os.path.isdir(mountpoint):
        logging.warning(u'Could not unmount "{0}"!'.format(mountpoint))
    else:
        return True
    return False


def try_persistent(cmd, tries=20, wait=1):
    '''
    A subprocess helper method that will try a given command a few times, each
    with a given wait period between the commands and starting with one wait
    period. This helps with commands that require some time before they can be
    handled successfully, such as unmounting images
    '''
    for i in range(tries):
        try:
            time.sleep(wait)
            subprocess.check_call(cmd)
            break
        except subprocess.CalledProcessError:
            pass
        except OSError:
            logging.exception('Error while calling external program:')
            pdb.set_trace()


def is_encase(path):
    return re.match(r'^.*\.E\w\w$', path)


def expand_path(path):
    '''
    Expand the given path to either an Encase image or a dd image
    i.e. if path is '/path/to/image.E01' then the result of this method will be
    /path/to/image.E*'
    and if path is '/path/to/image.001' then the result of this method will be 
    '/path/to/image.[0-9][0-9]?'
    '''
    if is_encase(path):<commit_msg>Add infinite unmount loop<commit_after>import time
import subprocess
import logging
import re
import glob
import os


def unmount(cmd, mountpoint, tries=20):
    '''
    A method that unmounts the given mountpoint using the given unmounting
    command, giving it a couple of tries if necessary
    '''
    cmd.append(mountpoint)
    while True:
        try:
            subprocess.check_call(cmd)
            break
        except:
            try:
                print u'There are still files open in the mountpoint! Press [enter] to try again. If you want to skip unmounting, press ^C!'
                raw_input('>>>')
            except KeyboardInterrupt:
                break

    for _ in range(tries):
        if os.listdir(mountpoint) == []:
            # Unmount was successful, remove mountpoint
            os.rmdir(mountpoint)
            break
        else:
            time.sleep(1)
    if os.path.isdir(mountpoint):
        logging.warning(u'Could not unmount "{0}"!'.format(mountpoint))
    else:
        return True
    return False


def is_encase(path):
    return re.match(r'^.*\.E\w\w$', path)


def expand_path(path):
    '''
    Expand the given path to either an Encase image or a dd image
    i.e. if path is '/path/to/image.E01' then the result of this method will be
    /path/to/image.E*'
    and if path is '/path/to/image.001' then the result of this method will be
    '/path/to/image.[0-9][0-9]?'
    '''
    if is_encase(path):
{'fraction_non_alphanumeric': 0.09366391184573003, 'fraction_numerical': 0.008876645240281604, 'mean_word_length': 2.301010101010101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '991566', 'n_tokens_mistral': 989, 'n_tokens_neox': 960, 'n_words': 332}