<commit_before>#!/bin/env python
# -*- encoding: utf-8 -*-
################################################################################
## TexPack - Free and open-source TexturePacker alternative
## Copyright (c) 2015 criptych
##
## Released under the MIT License.  See LICENSE file for terms.
##
## Disclaimer:  This tool was not developed from TexturePacker source or by
## reverse engineering of any kind; but through inspection of the TexturePacker
## documentation and independent research and implementation of the features
## advertised therein.
##
################################################################################

import logging
log = logging.getLogger('TexPack')

import math
import os

from PIL import Image
from PIL import ImageChops
from PIL import ImageColor
from PIL import ImageDraw
from PIL import ImageOps

from layouts import get_layout
from spritesheet import Sprite, Sheet

################################################################################

import datetime

class Timer(object):
    def __init__(self, name='Timer', callback=None):
        self.name = name
        if callback is not None:
            self.callback = callback

    def callback(self, dt):
        print("%s: %s" % (self.name, dt))

    def __enter__(self):
        self.start = datetime.datetime.now()
        return self

    def __exit__(self, *exc_info):
        self.finish = datetime.datetime.now()
        if self.callback is not None:
            self.callback(self.finish - self.start)

################################################################################
<commit_msg>Make Timer log start and stop times<commit_after>#!/bin/env python
# -*- encoding: utf-8 -*-
################################################################################
## TexPack - Free and open-source TexturePacker alternative
## Copyright (c) 2015 criptych
##
## Released under the MIT License.  See LICENSE file for terms.
##
## Disclaimer:  This tool was not developed from TexturePacker source or by
## reverse engineering of any kind; but through inspection of the TexturePacker
## documentation and independent research and implementation of the features
## advertised therein.
##
################################################################################

import logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('texpack')

import math
import os

from PIL import Image
from PIL import ImageChops
from PIL import ImageColor
from PIL import ImageDraw
from PIL import ImageOps

from layouts import get_layout
from spritesheet import Sprite, Sheet

################################################################################

import datetime

def strfdelta(dt, fmt=None):
    dy = dt.days
    ts = dt.seconds

    hr = (ts // 3600)
    mn = (ts //   60) % 60
    sc = (ts        ) % 60

    us = dt.microseconds
    ms = us // 1000

    if fmt is None:
        if dy:
            return '%dd%02d:%02d:%02d.%06d' % (dy, hr, mn, sc, us)
        elif hr:
            return '%d:%02d:%02d.%06d' % (hr, mn, sc, us)
        elif mn:
            return '%d:%02d.%06d' % (mn, sc, us)
        else:
            return '%d.%06ds' % (sc, us)

    return (fmt
        .replace('%d', '%d' % dy)
        .replace('%S', '%d' % ts)
        .replace('%h', '%02d' % hr)
        .replace('%m', '%02d' % mn)
        .replace('%s', '%02d' % sc)
        .replace('%f', '%06d' % us)
    )

class Timer(object):
    def __init__(self, name='Timer', callback=None):
        self.name = name
        self.callback = callback

    def __enter__(self):
        self.start = datetime.datetime.now()
        log.debug("%s: start: %s", self.name, self.start.strftime('%H:%M:%S'))
        return self

    def __exit__(self, *exc_info):
        self.finish = datetime.datetime.now()
        dt = self.finish - self.start
        log.debug("%s: end: %s (%s)", self.name, self.finish.strftime('%H:%M:%S'),
            strfdelta(dt))
        if self.callback is not None:
            self.callback(dt)

################################################################################

{'fraction_non_alphanumeric': 0.2588349987813795, 'fraction_numerical': 0.012673653424323665, 'mean_word_length': 3.4415584415584415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1004038', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1081, 'n_words': 356}