<commit_before>#!/usr/bin/python
import os
import subprocess
from string import uppercase
import sys
from textutil import asblocks, sanitize

DEBUG=False

def get_path_for_tool_by_toolname(toolname):
    default_path = os.path.dirname(sys.modules[__name__].__file__)
    path_options = [
                os.path.join(default_path, '..', '..', '..', '..', '..', '..', 'parts', 'poppler', 'bin'),
                os.path.join(default_path)
                    ]
    path_prefix_candidate_list = path_options + os.environ['PATH'].split(":")

    for path_prefix_option in path_prefix_candidate_list:
        path_option = os.path.join(path_prefix_option, toolname)
        if os.path.exists(path_option):
            return path_option
    else:
        raise Exception(toolname + " not found. Check your PATH environment variable and installation of poppler")

PDFTOTEXT=get_path_for_tool_by_toolname('pdftotext')
PDFINFO=get_path_for_tool_by_toolname('pdfinfo')

def pdftotext_version():
    if not PDFTOTEXT:
        return ('0', '0', '0')
    p = subprocess.Popen(executable=PDFTOTEXT, args=[PDFTOTEXT, '-v'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    major, minor, patchlevel = map(lambda x,y:y if x is None else x,p.stderr.readlines()[0].strip().split()[-1].split('.'),[0]*3)
    p.kill()
    return major, minor, patchlevel

PDFTOTEXT_VERSION = pdftotext_version()

if DEBUG:
    print "pdftotext from %s, version %s" % (PDFTOTEXT, str(PDFTOTEXT_VERSION))
    print "pdfinfo from %s" % PDFINFO

def pdftotext_version_pass():<commit_msg>Refactor exception when not finding tool name in command path<commit_after>#!/usr/bin/python
import os
import subprocess
from string import uppercase
import sys
from textutil import asblocks, sanitize

DEBUG=False


class PdfToolnameNotFoundException(object):
    pass


def get_path_for_tool_by_toolname(toolname):
    default_path = os.path.dirname(sys.modules[__name__].__file__)
    path_options = [
                os.path.join(default_path, '..', '..', '..', '..', '..', '..', 'parts', 'poppler', 'bin'),
                os.path.join(default_path)
                    ]
    path_prefix_candidate_list = path_options + os.environ['PATH'].split(":")

    for path_prefix_option in path_prefix_candidate_list:
        path_option = os.path.join(path_prefix_option, toolname)
        if os.path.exists(path_option):
            return path_option
    else:
        raise PdfToolnameNotFoundException(
            toolname + " not found. Check your PATH environment variable and installation of poppler")

PDFTOTEXT=get_path_for_tool_by_toolname('pdftotext')
PDFINFO=get_path_for_tool_by_toolname('pdfinfo')

def pdftotext_version():
    if not PDFTOTEXT:
        return ('0', '0', '0')
    p = subprocess.Popen(executable=PDFTOTEXT, args=[PDFTOTEXT, '-v'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    major, minor, patchlevel = map(lambda x,y:y if x is None else x,p.stderr.readlines()[0].strip().split()[-1].split('.'),[0]*3)
    p.kill()
    return major, minor, patchlevel

PDFTOTEXT_VERSION = pdftotext_version()

if DEBUG:
    print "pdftotext from %s, version %s" % (PDFTOTEXT, str(PDFTOTEXT_VERSION))
    print "pdfinfo from %s" % PDFINFO

def pdftotext_version_pass():
{'fraction_non_alphanumeric': 0.12948084054388134, 'fraction_numerical': 0.004326328800988875, 'mean_word_length': 3.8098068350668646, 'pattern_counts': {'":': 2, '<': 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': '5268415', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1082, 'n_words': 226}