#!/usr/bin/env python
"""Format Gentoo's emerge log.

Converts lines like:
    1124079478:  >>> AUTOCLEAN: x11-misc/icewm-tools
to:
    2005-08-14 21:17:58:  >>> AUTOCLEAN: x11-misc/icewm-tools
Leaves other lines alone.
"""
import datetime, re


SRC = "/var/log/emerge.log"

rx = re.compile( R'^(\d+): ')

f = open(SRC, 'r')
for lin in f:
    m = rx.match(lin)
    if m:
        ticks = int(m.group(1))
        timestamp = datetime.datetime.fromtimestamp(ticks).isoformat(' ')
        print timestamp + lin[m.end(1):]
    else:
        print lin

