<commit_before># vim:fileencoding=utf-8:ft=python
#
# Author: <NAME> <<EMAIL>>
# Last modified: 2015-05-03 22:46:39 +0200
#
# To the extent possible under law, <NAME> has waived all
# copyright and related or neighboring rights to checkfor.py This work
# is published from the Netherlands. See
# http://creativecommons.org/publicdomain/zero/1.0/

from __future__ import division, print_function

import os
import subprocess
import sys


def checkfor(args, rv=0):
    """Make sure that a program necessary for using this script is
    available.

    :param args: String or list of strings of commands. A single string may
    not contain spaces.
    :param rv: Expected return value from evoking the command.
    """
    if isinstance(args, str):
        if ' ' in args:
            raise ValueError('no spaces in single command allowed')
        args = [args]
    try:
        with open(os.devnull, 'w') as bb:
            rc = subprocess.call(args, stdout=bb, stderr=bb)
        if rc != rv:
            raise OSError
    except OSError as oops:
        outs = "Required program '{}' not found: {}."
        print(outs.format(args[0], oops.strerror))
        sys.exit(1)


if __name__ == '__main__':
    for p in ['ls', 'foo']:
        checkfor(p)
        print('found', p)
<commit_msg>Improved docstring in checkfor.py.<commit_after># vim:fileencoding=utf-8:ft=python
#
# Author: <NAME> <<EMAIL>>
# Last modified: 2015-05-15 18:17:13 +0200
#
# To the extent possible under law, <NAME> has waived all
# copyright and related or neighboring rights to checkfor.py This work
# is published from the Netherlands. See
# http://creativecommons.org/publicdomain/zero/1.0/

from __future__ import division, print_function

import os
import subprocess
import sys


def checkfor(args, rv=0):
    """
    Make sure that a program necessary for using this script is available.
    If the required utility is not found, this function will exit the program.

    Arguments:
        args: String or list of strings of commands. A single string may not
            contain spaces.
        rv: Expected return value from evoking the command.
    """
    if isinstance(args, str):
        if ' ' in args:
            raise ValueError('no spaces in single command allowed')
        args = [args]
    try:
        with open(os.devnull, 'w') as bb:
            rc = subprocess.call(args, stdout=bb, stderr=bb)
        if rc != rv:
            raise OSError
    except OSError as oops:
        outs = "Required program '{}' not found: {}."
        print(outs.format(args[0], oops.strerror))
        sys.exit(1)

{'fraction_non_alphanumeric': 0.10227711308375145, 'fraction_numerical': 0.018525665766113468, 'mean_word_length': 2.789473684210526, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4570165', 'n_tokens_mistral': 808, 'n_tokens_neox': 767, 'n_words': 286}