## @file
# This file is used to create report for Eot tool
#
# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import os
import EotGlobalData
## Report() class
#
#  This class defined Report
#
#  @param object: Inherited from object class
#
class Report(object):
    ## The constructor
    #
    #  @param  self: The object pointer
    #  @param  ReportName: name of the report
    #  @param  FvObj: FV object after parsing FV images
    #
    def __init__(self, ReportName = 'Report.html', FvObj = None, DispatchName=None):
        self.ReportName = ReportName
        self.Op = open(ReportName, 'w+')
        self.DispatchList = None
        if DispatchName:
            self.DispatchList = open(DispatchName, 'w+')
        self.FvObj = FvObj
        self.FfsIndex = 0
        self.PpiIndex = 0
        self.ProtocolIndex = 0
        if EotGlobalData.gMACRO['EFI_SOURCE'] == '':
            EotGlobalData.gMACRO['EFI_SOURCE'] = EotGlobalData.gMACRO['EDK_SOURCE']
    ## WriteLn() method
    #
    #  Write a line in the report
    #
    #  @param  self: The object pointer
    #  @param Line:  The lint to be written into
    #
    def WriteLn(self, Line):
        self.Op.write('%s\n' % Line)
    ## GenerateReport() method
    #
    #  A caller to generate report
    #
    #  @param  self: The object pointer
    #
    def GenerateReport(self):
        self.GenerateHeader()
        self.GenerateFv()
        self.GenerateTail()
        self.Op.close()
        self.GenerateUnDispatchedList()
    ## GenerateUnDispatchedList() method
    #
    #  Create a list for not dispatched items
    #
    #  @param  self: The object pointer
    #
    def GenerateUnDispatchedList(self):
        FvObj = self.FvObj
        EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.Name)
        for Item in FvObj.UnDispatchedFfsDict:
            EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.UnDispatchedFfsDict[Item])
    ## GenerateFv() method
    #
    #  Generate FV information
    #
    #  @param  self: The object pointer
    #
    def GenerateFv(self):
        FvObj = self.FvObj
        Content = """