<commit_before>#!/usr/bin/python
"""Run the program and record stdout/stderr/exitcode into the database results.rev_changeset.db

Usage: %prog program [args]
"""
import sys
import os
import sqlite3
import warnings

warnings.simplefilter('ignore')

COMMAND_CHANGESET = r"hg log -r tip | grep changeset"

def record(changeset, argv, stdout, returncode):
    c = sqlite3.connect('results.%s.db' % changeset)
    c.execute('''create table if not exists command_record
              (id integer primary key autoincrement,
               command text,
               stdout text,
               exitcode integer)''')
    c.execute('insert into command_record (command, stdout, exitcode)'
              'values (?, ?, ?)', (`argv`, stdout, returncode))
    c.commit()

def main():
    argv = sys.argv[1:]
    if argv[0]=='-d':
        debug = True
        del argv[0]
    else:
        debug = False
    changeset = os.popen(COMMAND_CHANGESET).read().replace('changeset:', '').strip().replace(':', '_')
    output_name = os.tmpnam()
    arg = ' '.join(argv) + ' &> %s' % output_name
    print arg
    returncode = os.system(arg)>>8
    print arg, 'finished with code', returncode
    stdout = file(output_name).read()
    if not debug:
        record(changeset, argv, stdout, returncode)
        os.unlink(output_name)
    sys.exit(returncode)

if __name__=='__main__':
    main()

<commit_msg>record_results.py: do not record results of the tests interrupted with Ctrl-C<commit_after>#!/usr/bin/python
"""Run the program and record stdout/stderr/exitcode into the database results.rev_changeset.db

Usage: %prog program [args]
"""
import sys
import os
import sqlite3
import warnings

warnings.simplefilter('ignore')

COMMAND_CHANGESET = r"hg log -r tip | grep changeset"

def record(changeset, argv, stdout, returncode):
    c = sqlite3.connect('results.%s.db' % changeset)
    c.execute('''create table if not exists command_record
              (id integer primary key autoincrement,
               command text,
               stdout text,
               exitcode integer)''')
    c.execute('insert into command_record (command, stdout, exitcode)'
              'values (?, ?, ?)', (`argv`, stdout, returncode))
    c.commit()

def main():
    argv = sys.argv[1:]
    if argv[0]=='-d':
        debug = True
        del argv[0]
    else:
        debug = False
    changeset = os.popen(COMMAND_CHANGESET).read().replace('changeset:', '').strip().replace(':', '_')
    output_name = os.tmpnam()
    arg = ' '.join(argv) + ' &> %s' % output_name
    print arg
    returncode = os.system(arg)>>8
    print arg, 'finished with code', returncode
    stdout = file(output_name).read()
    if not debug:
        if returncode!=1:
            record(changeset, argv, stdout, returncode)
            os.unlink(output_name)
    sys.exit(returncode)

if __name__=='__main__':
    main()


{'fraction_non_alphanumeric': 0.13509749303621169, 'fraction_numerical': 0.004526462395543176, 'mean_word_length': 2.9195088676671213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7290906', 'n_tokens_mistral': 911, 'n_tokens_neox': 894, 'n_words': 238}