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