<commit_before>#!/usr/bin/env python
#
# Copyright 2012, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import requests
import time
import os
import sys
import socket
import urlparse


def dump_info(endpoint, task_id):
    log_request_url = '%s/tasks/%d/logs' % (endpoint, task_id)
    task_request_url = '%s/tasks/%d' % (endpoint, task_id)

    task_info = requests.get(task_request_url)

    if (task_info.status_code >= 200 and task_info.status_code < 300):
        task_status = task_info.json['task']['state']

    log = requests.get(log_request_url + '?watch')

    if (log.status_code >= 200 and log.status_code < 300):
        txid = log.json['request']
    else:
        print 'error getting transaction'
        sys.exit(1)

    urlinfo = urlparse.urlparse(endpoint)

    fd = socket.socket()
    fd.connect((urlinfo.hostname, urlinfo.port))
    fd.send('GET /tasks/%d/logs/%s HTTP/1.0\n\n' % (task_id, txid))

    linedata = []

    while linedata == []:
        data = fd.recv(4096)
        linedata = data.split('\n')

        while(len(linedata) > 0 and \
                  linedata[0] != '' and \
                  linedata[0] != '\r'):
            linedata.pop(0)

    sys.stdout.write('\n'.join(linedata))
<commit_msg>add support for new requests api in logtail<commit_after>#!/usr/bin/env python
#
# Copyright 2012, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import requests
import time
import os
import sys
import socket
import urlparse

def ensure_callable(item):
    """nasty hack to get round requests api change"""
    if callable(item):
        return item
    else:
        return lambda: item

def dump_info(endpoint, task_id):
    log_request_url = '%s/tasks/%d/logs' % (endpoint, task_id)
    task_request_url = '%s/tasks/%d' % (endpoint, task_id)

    task_info = requests.get(task_request_url)
    task_info.json=ensure_callable(task_info.json)

    if (task_info.status_code >= 200 and task_info.status_code < 300):
        task_status = task_info.json()['task']['state']

    log = requests.get(log_request_url + '?watch')
    log.json=ensure_callable(log.json)

    if (log.status_code >= 200 and log.status_code < 300):
        txid = log.json()['request']
    else:
        print 'error getting transaction'
        sys.exit(1)

    urlinfo = urlparse.urlparse(endpoint)

    fd = socket.socket()
    fd.connect((urlinfo.hostname, urlinfo.port))
    fd.send('GET /tasks/%d/logs/%s HTTP/1.0\n\n' % (task_id, txid))

    linedata = []

    while linedata == []:
        data = fd.recv(4096)
        linedata = data.split('\n')

        while(len(linedata) > 0 and \
                  linedata[0] != '' and \
                  linedata[0] != '\r'):
            linedata.pop(0)

    sys.stdout.write('\n'.join(linedata))

{'fraction_non_alphanumeric': 0.12065331928345627, 'fraction_numerical': 0.016332982086406742, 'mean_word_length': 3.0393617021276595, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7173737', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1165, 'n_words': 351}