<commit_before>import datetime
import functools
import glob
import itertools
import operator
import optparse
import os
import re
import shutil
import stat
import subprocess
import sys
import tempfile
import time
import uuid

import tkt.files
import tkt.models
import tkt.config
import tkt.getplugins
import yaml


CLOSED = tkt.models.Issue.CLOSED
DEFAULT = "todo"

loader_class = yaml.__with_libyaml__ and yaml.CLoader or yaml.Loader
dumper_class = yaml.__with_libyaml__ and yaml.CDumper or yaml.Dumper

_load = yaml.load
def load_yaml(*args, **kwargs):
    kwargs.pop('Loader', 0)
    return _load(*args, Loader=loader_class, **kwargs)
yaml.load = load_yaml

_dump = yaml.dump
def dump_yaml(*args, **kwargs):
    kwargs.pop('Dumper', 0)
    return _dump(*args, Dumper=dumper_class, **kwargs)
yaml.dump = dump_yaml

def main():
    tkt.getplugins.getplugins()
    if len(sys.argv) > 1 and sys.argv[1] and not sys.argv[1].startswith('-'):
        arg = sys.argv[1]
    else:
        arg = DEFAULT

    cmd = Command.cmds.get(arg)
    if cmd is None:
        sys.stderr.write("unknown tkt command: %s\n" % arg)
        sys.exit(1)
    cmd = cmd()

    cmd.prepare_options()

    cmd.main()

def track_opens():
    builtinopen = __builtins__.open
    globals()['openedfiles'] = opened = []
    def opener(name, mode='rb'):
        opened.append((name, mode))
        return builtinopen(name, mode)
    __builtins__.open = opener

def aliases(*names):
    def decorator(cls):
        for name in names:
            Command.cmds[name.replace("_", "-").lower()] = cls
        return cls
    return decorator

def hextimestamp(dt):
    return "%x" % int(time.mktime(dt.timetuple()))<commit_msg>catch Ctrl-C while executing commands<commit_after>import datetime
import functools
import glob
import itertools
import operator
import optparse
import os
import re
import shutil
import stat
import subprocess
import sys
import tempfile
import time
import uuid

import tkt.files
import tkt.models
import tkt.config
import tkt.getplugins
import yaml


CLOSED = tkt.models.Issue.CLOSED
DEFAULT = "todo"

loader_class = yaml.__with_libyaml__ and yaml.CLoader or yaml.Loader
dumper_class = yaml.__with_libyaml__ and yaml.CDumper or yaml.Dumper

_load = yaml.load
def load_yaml(*args, **kwargs):
    kwargs.pop('Loader', 0)
    return _load(*args, Loader=loader_class, **kwargs)
yaml.load = load_yaml

_dump = yaml.dump
def dump_yaml(*args, **kwargs):
    kwargs.pop('Dumper', 0)
    return _dump(*args, Dumper=dumper_class, **kwargs)
yaml.dump = dump_yaml

def main():
    tkt.getplugins.getplugins()
    if len(sys.argv) > 1 and sys.argv[1] and not sys.argv[1].startswith('-'):
        arg = sys.argv[1]
    else:
        arg = DEFAULT

    cmd = Command.cmds.get(arg)
    if cmd is None:
        sys.stderr.write("unknown tkt command: %s\n" % arg)
        sys.exit(1)
    cmd = cmd()

    cmd.prepare_options()

    try:
        cmd.main()
    except KeyboardInterrupt:
        cmd.fail("Cancelled")

def track_opens():
    builtinopen = __builtins__.open
    globals()['openedfiles'] = opened = []
    def opener(name, mode='rb'):
        opened.append((name, mode))
        return builtinopen(name, mode)
    __builtins__.open = opener

def aliases(*names):
    def decorator(cls):
        for name in names:
            Command.cmds[name.replace("_", "-").lower()] = cls
        return cls
    return decorator

def hextimestamp(dt):
    return "%x" % int(time.mktime(dt.timetuple()))
{'fraction_non_alphanumeric': 0.11869778161912993, 'fraction_numerical': 0.004033419763756842, 'mean_word_length': 3.400506970849176, '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': '457389', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1154, 'n_words': 307}