#! /usr/bin/env python
# -*- python -*-

####################################################################################################
#
# PyDvi - A Python Library to Process DVI Stream.
# Copyright (C) 2009 Salvaire Fabrice
#
####################################################################################################

####################################################################################################
#
# Audit
#
#  - 16/01/2010 fabrice
#
####################################################################################################

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

import os
import re
import sys

from optparse import OptionParser

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

from Logging import *
from CopyrightConfig import *

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

def log_and_exit(message, exit_value):

    print message
    sys.exit(exit_value)

####################################################################################################
#
# Options
#

usage = 'usage: %prog [options]'

parser = OptionParser(usage)

opt, args = parser.parse_args()

if len(args) != 1:
    log_and_exit(message='Specify a file',
                 exit_value=1)

filename = args[0]

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

if not os.path.exists(filename):
    log_and_exit(message="File don't exists",
                 exit_value=1)

copyrighted = False # not used
audit_line = None
with open(filename, 'r') as f:
    for line in f:
        match = re.match('.* (\d+)/(\d+)/(\d+) ', line)
        if match is not None:
            d, m, y = [int(x) for x in match.groups()]
            date = '%4u/%02u/%02u' % (y, m, d)
            audit_line = ' '.join((date, filename))

if audit_line:
    print audit_line

sys.exit(0)

####################################################################################################
#
# End
#
####################################################################################################
