<commit_before>'''

Wraps shell commands and sends the result to Datadog as events. Ex:

python -m dogapi.wrap -n test-job -k $API_KEY --submit_mode all "ls -lah"

Note that you need to enclose your command in quotes to prevent python
from thinking the command line arguments belong to the python command
instead of the wrapped command.

You can also have the script only send events if they fail:

python -m dogapi.wrap -n test-job -k $API_KEY --submit_mode errors "ls -lah"

And you can give the command a timeout too:

python -m dogapi.wrap -n test-job -k $API_KEY --timeout=1 "sleep 3"

'''
import sys
import subprocess
import time
from StringIO import StringIO
from optparse import OptionParser

from dogapi import dog_http_api as dog
from dogapi.common import get_ec2_instance_id

class Timeout(Exception): pass

def poll_proc(proc, sleep_interval, timeout):
    start_time = time.time()
    returncode = None
    while returncode is None:
        returncode = proc.poll()
        if time.time() - start_time > timeout:
            raise Timeout()
        else:
            time.sleep(sleep_interval)<commit_msg>update dogwrap script name in docstring<commit_after>'''

Wraps shell commands and sends the result to Datadog as events. Ex:

dogwrap -n test-job -k $API_KEY --submit_mode all "ls -lah"

Note that you need to enclose your command in quotes to prevent python
from thinking the command line arguments belong to the python command
instead of the wrapped command.

You can also have the script only send events if they fail:

dogwrap -n test-job -k $API_KEY --submit_mode errors "ls -lah"

And you can give the command a timeout too:

dogwrap -n test-job -k $API_KEY --timeout=1 "sleep 3"

'''
import sys
import subprocess
import time
from StringIO import StringIO
from optparse import OptionParser

from dogapi import dog_http_api as dog
from dogapi.common import get_ec2_instance_id

class Timeout(Exception): pass

def poll_proc(proc, sleep_interval, timeout):
    start_time = time.time()
    returncode = None
    while returncode is None:
        returncode = proc.poll()
        if time.time() - start_time > timeout:
            raise Timeout()
        else:
            time.sleep(sleep_interval)
{'fraction_non_alphanumeric': 0.06756756756756757, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 3.4778225806451615, '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': '5408180', 'n_tokens_mistral': 649, 'n_tokens_neox': 645, 'n_words': 286}