<commit_before>#
# Copyright (c) 2007 rPath, Inc.
#
# All rights reserved
#

import os
import logging
log = logging
import popen2

def rewriteFile(template, target, data):
    if not os.path.exists(template):
        return
    f = open(template, 'r')
    templateData = f.read()
    f.close()
    f = open(target, 'w')
    f.write(templateData % data)
    f.close()
    os.unlink(template)


def logCall(cmd, ignoreErrors = False):
    log.debug("+ " + cmd)
    p = popen2.Popen4(cmd)
    if not ignoreErrors:
        code = p.wait()
        err = p.fromchild.read()
        [log.debug("++ " + errLine) for errLine in err.split("\n")]
        raise RuntimeError("Error executing command: %s (return code %d)" % (cmd, code))
    else:
        p.wait()
        err = p.fromchild.read()
        [log.debug("++ " + errLine) for errLine in err.split("\n")]<commit_msg>only raise RuntimeError on nonzero return code<commit_after>#
# Copyright (c) 2007 rPath, Inc.
#
# All rights reserved
#

import os
import logging
log = logging
import popen2

def rewriteFile(template, target, data):
    if not os.path.exists(template):
        return
    f = open(template, 'r')
    templateData = f.read()
    f.close()
    f = open(target, 'w')
    f.write(templateData % data)
    f.close()
    os.unlink(template)


def logCall(cmd, ignoreErrors = False):
    log.debug("+ " + cmd)
    p = popen2.Popen4(cmd)
    if not ignoreErrors:
        code = p.wait()
        err = p.fromchild.read()
        [log.debug("++ " + errLine) for errLine in err.split("\n")]

        if code:
            raise RuntimeError("Error executing command: %s (return code %d)" % (cmd, code))
    else:
        p.wait()
        err = p.fromchild.read()
        [log.debug("++ " + errLine) for errLine in err.split("\n")]
{'fraction_non_alphanumeric': 0.14862591138530568, 'fraction_numerical': 0.007851934941110488, 'mean_word_length': 2.596774193548387, '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': '760428', 'n_tokens_mistral': 611, 'n_tokens_neox': 594, 'n_words': 165}