<commit_before>import optparse
import sys

import rollbar

VERSION = '0.1'

verbose = False

def _gen_report_message(level):
    def _wrapped(lines):
        line_data = '\n'.join(lines)
        if verbose:
            print 'Rollbar [%s]: %s' % (level, line_data)
        rollbar.report_message(line_data, level=level, extra_data={'cli_version': VERSION})
    return _wrapped


CMDS = {
    'debug': _gen_report_message('debug'),
    'info': _gen_report_message('info'),
    'warning': _gen_report_message('warning'),
    'error': _gen_report_message('error'),
    'critical': _gen_report_message('critical'),
}

def main():
    global verbose
    parser = optparse.OptionParser(version='%prog version ' + VERSION)
    parser.add_option('-t', '--access_token',
                      dest='access_token',
                      help="You project's access token from rollbar.com.",
                      metavar='ACCESS_TOKEN')
    parser.add_option('-e', '--environment',
                      dest='environment',
                      help="The environment to report errors and messages to.",
                      metavar='ENVIRONMENT')
    parser.add_option('-u', '--url',
                      dest='endpoint_url',
                      help="The Rollbar API endpoint url to send data to.",
                      metavar='ENDPOINT_URL',
                      default=rollbar.DEFAULT_ENDPOINT)
    parser.add_option('-v', '--verbose',
                      dest='verbose',
                      help="Print verbose output.",
                      action='store_true',
                      default=False)

    options, args = parser.parse_args()

    access_token = options.access_token
    env = options.environment
    endpoint = options.endpoint_url
    verbose = options.verbose

    if not access_token:
        parser.error('missing access_token')
    if not env:
        parser.error('missing environment')

    rollbar.init(access_token, environment=env, endpoint=endpoint)

    def _do_cmd(cmd_name, line):
        cmd = CMDS.get(cmd_name.lower())
        if cmd:
            cmd([line])
            return True

        return False

    if len(args) > 1:
        sent = _do_cmd(args[0], ' '.join(args[1:]))
        sys.exit(0 if sent else 1)

    cur_cmd_name = None
    try:
        cur_line = sys.stdin.readline()
        while cur_line:
            cur_line = cur_line.strip()
            parts = cur_line.split(' ')<commit_msg>try fileinput instead of stdin directly because I think it buffers...<commit_after>import fileinput
import optparse
import sys

import rollbar

VERSION = '0.1'

verbose = False

def _gen_report_message(level):
    def _wrapped(lines):
        line_data = '\n'.join(lines)
        if verbose:
            print 'Rollbar [%s]: %s' % (level, line_data)
        rollbar.report_message(line_data, level=level, extra_data={'cli_version': VERSION})
    return _wrapped


CMDS = {
    'debug': _gen_report_message('debug'),
    'info': _gen_report_message('info'),
    'warning': _gen_report_message('warning'),
    'error': _gen_report_message('error'),
    'critical': _gen_report_message('critical'),
}

def main():
    global verbose
    parser = optparse.OptionParser(version='%prog version ' + VERSION)
    parser.add_option('-t', '--access_token',
                      dest='access_token',
                      help="You project's access token from rollbar.com.",
                      metavar='ACCESS_TOKEN')
    parser.add_option('-e', '--environment',
                      dest='environment',
                      help="The environment to report errors and messages to.",
                      metavar='ENVIRONMENT')
    parser.add_option('-u', '--url',
                      dest='endpoint_url',
                      help="The Rollbar API endpoint url to send data to.",
                      metavar='ENDPOINT_URL',
                      default=rollbar.DEFAULT_ENDPOINT)
    parser.add_option('-v', '--verbose',
                      dest='verbose',
                      help="Print verbose output.",
                      action='store_true',
                      default=False)

    options, args = parser.parse_args()

    access_token = options.access_token
    env = options.environment
    endpoint = options.endpoint_url
    verbose = options.verbose

    if not access_token:
        parser.error('missing access_token')
    if not env:
        parser.error('missing environment')

    rollbar.init(access_token, environment=env, endpoint=endpoint)

    def _do_cmd(cmd_name, line):
        cmd = CMDS.get(cmd_name.lower())
        if cmd:
            cmd([line])
            return True

        return False

    if len(args) > 1:
        sent = _do_cmd(args[0], ' '.join(args[1:]))
        sys.exit(0 if sent else 1)

    cur_cmd_name = None
    try:
        for cur_line in fileinput.input():
            cur_line = cur_line.strip()
            parts = cur_line.split(' ')
{'fraction_non_alphanumeric': 0.11761133603238866, 'fraction_numerical': 0.002834008097165992, 'mean_word_length': 2.0919899874843555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1147366', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1380, 'n_words': 314}