]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/FdfClassObject.py
9a7d6494d331e61d8a8d8740306ea7834f4f7cb4
[mirror_edk2.git] / BaseTools / Source / Python / Common / FdfClassObject.py
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 #
17 from FdfParserLite import FdfParser
18 from Table.TableFdf import TableFdf
19 from CommonDataClass.DataClass import MODEL_FILE_FDF, MODEL_PCD, MODEL_META_DATA_COMPONENT
20 from String import NormPath
21
22
23 ## Fdf
24 #
25 # This class defined the structure used in Fdf object
26 #
27 # @param Filename: Input value for Ffilename of Fdf file, default is None
28 # @param WorkspaceDir: Input value for current workspace directory, default is None
29 #
30 class Fdf(object):
31 def __init__(self, Filename = None, IsToDatabase = False, WorkspaceDir = None, Database = None):
32 self.WorkspaceDir = WorkspaceDir
33 self.IsToDatabase = IsToDatabase
34
35 self.Cur = Database.Cur
36 self.TblFile = Database.TblFile
37 self.TblFdf = Database.TblFdf
38 self.FileID = -1
39 self.FileList = {}
40
41 #
42 # Load Fdf file if filename is not None
43 #
44 if Filename is not None:
45 self.LoadFdfFile(Filename)
46
47 #
48 # Insert a FDF file record into database
49 #
50 def InsertFile(self, Filename):
51 FileID = -1
52 Filename = NormPath(Filename)
53 if Filename not in self.FileList:
54 FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_FDF)
55 self.FileList[Filename] = FileID
56
57 return self.FileList[Filename]
58
59
60 ## Load Fdf file
61 #
62 # Load the file if it exists
63 #
64 # @param Filename: Input value for filename of Fdf file
65 #
66 def LoadFdfFile(self, Filename):
67 FileList = []
68 #
69 # Parse Fdf file
70 #
71 Filename = NormPath(Filename)
72 Fdf = FdfParser(Filename)
73 Fdf.ParseFile()
74
75 #
76 # Insert inf file and pcd information
77 #
78 if self.IsToDatabase:
79 (Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled) = \
80 (0, '', '', '', 'COMMON', -1, -1, -1, -1, -1, -1, 0)
81 for Index in range(0, len(Fdf.Profile.PcdDict)):
82 pass
83 for Key in Fdf.Profile.PcdDict.keys():
84 Model = MODEL_PCD
85 Value1 = ''
86 Value2 = ".".join((Key[1], Key[0]))
87 FileName = Fdf.Profile.PcdFileLineDict[Key][0]
88 StartLine = Fdf.Profile.PcdFileLineDict[Key][1]
89 BelongsToFile = self.InsertFile(FileName)
90 self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
91 for Index in range(0, len(Fdf.Profile.InfList)):
92 Model = MODEL_META_DATA_COMPONENT
93 Value1 = Fdf.Profile.InfList[Index]
94 Value2 = ''
95 FileName = Fdf.Profile.InfFileLineList[Index][0]
96 StartLine = Fdf.Profile.InfFileLineList[Index][1]
97 BelongsToFile = self.InsertFile(FileName)
98 self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
99
100 ##
101 #
102 # This acts like the main() function for the script, unless it is 'import'ed into another
103 # script.
104 #
105 if __name__ == '__main__':
106 pass