<commit_before>import os.path
from swidgenerator import DpkgEnvironment, YumEnvironment


def autodetect_env():
    envs = {
        DpkgEnvironment: '/usr/bin/dpkg-query',
        YumEnvironment: '/usr/bin/yum'
    }

    for environment_string, path in envs.iteritems():
        if os.path.isfile(path):
            return environment_string

    return None<commit_msg>tnc-ba/strongTNC#43 implemented executable lookup in path, thx @d22 good idea<commit_after>import os.path
from swidgenerator import DpkgEnvironment, YumEnvironment
from distutils.spawn import find_executable


def autodetect_env():
    """
    Tries to detect the used packetmanager by searching for a given executable in the path.
    Returns a static class representing the packetmanager environment or None if autodetection fails.
    """
    envs = {
        DpkgEnvironment: 'dpkg-query',
        YumEnvironment: 'yum'
    }

    for environment_string, path in envs.iteritems():
        if find_executable(path):
            return environment_string

    return None
{'fraction_non_alphanumeric': 0.07272727272727272, 'fraction_numerical': 0.003827751196172249, 'mean_word_length': 3.269387755102041, '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': '4098250', 'n_tokens_mistral': 302, 'n_tokens_neox': 290, 'n_words': 90}