1## @file
2# This file is used to define each component of FDF file
3#
4# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
5# This program and the accompanying materials
6# are licensed and made available under the terms and conditions of the BSD License
7# which accompanies this distribution.  The full text of the license may be found at
8# http://opensource.org/licenses/bsd-license.php
9#
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12#
13
14##
15# Import Modules
16#
17from FdfParserLite import FdfParser
18from Table.TableFdf import TableFdf
19from CommonDataClass.DataClass import MODEL_FILE_FDF, MODEL_PCD, MODEL_META_DATA_COMPONENT
20from String import NormPath
21
22## FdfObject
23#
24# This class defined basic Fdf object which is used by inheriting
25#
26# @param object:       Inherited from object class
27#
28class FdfObject(object):
29    def __init__(self):
30        object.__init__()
31
32## Fdf
33#
34# This class defined the structure used in Fdf object
35#
36# @param FdfObject:     Inherited from FdfObject class
37# @param Filename:      Input value for Ffilename of Fdf file, default is None
38# @param WorkspaceDir:  Input value for current workspace directory, default is None
39#
40class Fdf(FdfObject):
41    def __init__(self, Filename = None, IsToDatabase = False, WorkspaceDir = None, Database = None):
42        self.WorkspaceDir = WorkspaceDir
43        self.IsToDatabase = IsToDatabase
44
45        self.Cur = Database.Cur
46        self.TblFile = Database.TblFile
47        self.TblFdf = Database.TblFdf
48        self.FileID = -1
49        self.FileList = {}
50
51        #
52        # Load Fdf file if filename is not None
53        #
54        if Filename != None:
55            self.LoadFdfFile(Filename)
56
57    #
58    # Insert a FDF file record into database
59    #
60    def InsertFile(self, Filename):
61        FileID = -1
62        Filename = NormPath(Filename)
63        if Filename not in self.FileList:
64            FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_FDF)
65            self.FileList[Filename] = FileID
66
67        return self.FileList[Filename]
68
69
70    ## Load Fdf file
71    #
72    # Load the file if it exists
73    #
74    # @param Filename:  Input value for filename of Fdf file
75    #
76    def LoadFdfFile(self, Filename):
77        FileList = []
78        #
79        # Parse Fdf file
80        #
81        Filename = NormPath(Filename)
82        Fdf = FdfParser(Filename)
83        Fdf.ParseFile()
84
85        #
86        # Insert inf file and pcd information
87        #
88        if self.IsToDatabase:
89            (Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled) = \
90            (0, '', '', '', 'COMMON', -1, -1, -1, -1, -1, -1, 0)
91            for Index in range(0, len(Fdf.Profile.PcdDict)):
92                pass
93            for Key in Fdf.Profile.PcdDict.keys():
94                Model = MODEL_PCD
95                Value1 = ''
96                Value2 = ".".join((Key[1], Key[0]))
97                FileName = Fdf.Profile.PcdFileLineDict[Key][0]
98                StartLine = Fdf.Profile.PcdFileLineDict[Key][1]
99                BelongsToFile = self.InsertFile(FileName)
100                self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
101            for Index in range(0, len(Fdf.Profile.InfList)):
102                Model = MODEL_META_DATA_COMPONENT
103                Value1 = Fdf.Profile.InfList[Index]
104                Value2 = ''
105                FileName = Fdf.Profile.InfFileLineList[Index][0]
106                StartLine = Fdf.Profile.InfFileLineList[Index][1]
107                BelongsToFile = self.InsertFile(FileName)
108                self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
109
110##
111#
112# This acts like the main() function for the script, unless it is 'import'ed into another
113# script.
114#
115if __name__ == '__main__':
116    pass
117