#!/usr/bin/env python

##
## parseInfo.py
##      - command line parser of various formats - prints info about a
##      benchmark file on the command line 
##

# $Id: ParseInfo.py,v 1.7 2007/01/05 23:39:46 jarda Exp $


# import of required modules {{{
import sys

from optparse import OptionParser

from Constants import Constants
from BenchmarkFileParser import BenchmarkFileParser
# }}}


def parseFile(fileName, format):
    # DOC {{{
    """Parses a benchmark file.

    Parameters

        fileName -- the name of the parsed file

        format -- the format of the file or None
    """
    # }}}

    # CODE {{{
    print '\nParsing file %s\n' % (fileName,) 
    
    if (format):
        parser = BenchmarkFileParser.getParserForFormatName(format)
    else:
        parser = BenchmarkFileParser.getParserForFileName(fileName)
    
    parser.parseBenchmarkFileContents(open(fileName).read())

    print parser.getParsedFileInfo()
    # }}}


def main(self):
    # DOC {{{
    """Parses the command line options, then processes all input lines.
    """
    # }}}

    # CODE {{{
    print >> sys.stderr, '** Benchmark file info parser **'
    
    parser = OptionParser()

    parser.add_option("-t", "--format", dest = "format",
                      help = "format of the file")

    options, args = parser.parse_args()

    if (not len(args)):
        print >> sys.stderr, 'Name of a parsed file missing'
        print >> sys.stderr, 'Syntax: %s fileName(s)' % (sys.argv[0])
        return

    #import profile
    #profile.runctx('parseFile(args[0])', globals(), locals())
    for fileName in args:
        parseFile(fileName, options.format)
    # }}}


if (__name__ == '__main__'):
    main(sys.argv)
