Check In tool source code based on Build tool project revision r1655.
[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
4# Copyright (c) 2008, Intel Corporation\r
5# All rights reserved. This program and the accompanying materials\r
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
22## FdfObject\r
23#\r
24# This class defined basic Fdf object which is used by inheriting\r
25# \r
26# @param object: Inherited from object class\r
27#\r
28class FdfObject(object):\r
29 def __init__(self):\r
30 object.__init__()\r
31\r
32## Fdf\r
33#\r
34# This class defined the structure used in Fdf object\r
35# \r
36# @param FdfObject: Inherited from FdfObject class\r
37# @param Filename: Input value for Ffilename of Fdf file, default is None\r
38# @param WorkspaceDir: Input value for current workspace directory, default is None\r
39#\r
40class Fdf(FdfObject):\r
41 def __init__(self, Filename = None, IsToDatabase = False, WorkspaceDir = None, Database = None):\r
42 self.WorkspaceDir = WorkspaceDir\r
43 self.IsToDatabase = IsToDatabase\r
44 \r
45 self.Cur = Database.Cur\r
46 self.TblFile = Database.TblFile\r
47 self.TblFdf = Database.TblFdf\r
48 self.FileID = -1\r
49 self.FileList = {}\r
50\r
51 #\r
52 # Load Fdf file if filename is not None\r
53 #\r
54 if Filename != None:\r
55 self.LoadFdfFile(Filename)\r
56\r
57 #\r
58 # Insert a FDF file record into database\r
59 #\r
60 def InsertFile(self, Filename):\r
61 FileID = -1\r
62 Filename = NormPath(Filename)\r
63 if Filename not in self.FileList:\r
64 FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_FDF)\r
65 self.FileList[Filename] = FileID\r
66\r
67 return self.FileList[Filename]\r
68 \r
69 \r
70 ## Load Fdf file\r
71 #\r
72 # Load the file if it exists\r
73 #\r
74 # @param Filename: Input value for filename of Fdf file\r
75 #\r
76 def LoadFdfFile(self, Filename): \r
77 FileList = []\r
78 #\r
79 # Parse Fdf file\r
80 #\r
81 Filename = NormPath(Filename)\r
82 Fdf = FdfParser(Filename)\r
83 Fdf.ParseFile()\r
84\r
85 #\r
86 # Insert inf file and pcd information\r
87 #\r
88 if self.IsToDatabase:\r
89 (Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled) = \\r
90 (0, '', '', '', 'COMMON', -1, -1, -1, -1, -1, -1, 0)\r
91 for Index in range(0, len(Fdf.Profile.PcdDict)):\r
92 pass\r
93 for Key in Fdf.Profile.PcdDict.keys():\r
94 Model = MODEL_PCD\r
95 Value1 = ''\r
96 Value2 = ".".join((Key[1], Key[0]))\r
97 FileName = Fdf.Profile.PcdFileLineDict[Key][0]\r
98 StartLine = Fdf.Profile.PcdFileLineDict[Key][1]\r
99 BelongsToFile = self.InsertFile(FileName)\r
100 self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
101 for Index in range(0, len(Fdf.Profile.InfList)):\r
102 Model = MODEL_META_DATA_COMPONENT\r
103 Value1 = Fdf.Profile.InfList[Index]\r
104 Value2 = ''\r
105 FileName = Fdf.Profile.InfFileLineList[Index][0]\r
106 StartLine = Fdf.Profile.InfFileLineList[Index][1]\r
107 BelongsToFile = self.InsertFile(FileName)\r
108 self.TblFdf.Insert(Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
109\r
110##\r
111#\r
112# This acts like the main() function for the script, unless it is 'import'ed into another\r
113# script.\r
114#\r
115if __name__ == '__main__':\r
116 pass\r