]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileTable.py
Sync BaseTool trunk (version r2460) into EDKII BaseTools. The change mainly includes:
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / MetaFileWorkspace / MetaFileTable.py
CommitLineData
d0acc87a
LG
1## @file\r
2# This file is used to create/update/query/erase a meta file table\r
3#\r
4# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
5# 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
17import uuid\r
18\r
19import Common.EdkLogger as EdkLogger\r
20import EccGlobalData\r
21\r
22from MetaDataTable import Table\r
23from MetaDataTable import ConvertToSqlString\r
24from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \\r
25 MODEL_FILE_OTHERS\r
26\r
27class MetaFileTable(Table):\r
28 ## Constructor \r
29 def __init__(self, Cursor, MetaFile, FileType, TableName, Temporary = False):\r
30 self.MetaFile = MetaFile\r
31 self.TblFile = EccGlobalData.gDb.TblFile\r
32 if (FileType == MODEL_FILE_INF):\r
33 TableName = "Inf"\r
34 if (FileType == MODEL_FILE_DSC):\r
35 if Temporary:\r
36 TableName = "_%s_%s" % ("Dsc", uuid.uuid4().hex)\r
37 else:\r
38 TableName = "Dsc"\r
39 if (FileType == MODEL_FILE_DEC):\r
40 TableName = "Dec"\r
41\r
42 Table.__init__(self, Cursor, TableName, 0, Temporary)\r
43 self.Create(False)\r
44\r
45\r
46## Python class representation of table storing module data\r
47class ModuleTable(MetaFileTable):\r
48 _COLUMN_ = '''\r
49 ID REAL PRIMARY KEY,\r
50 Model INTEGER NOT NULL,\r
51 Value1 TEXT NOT NULL,\r
52 Value2 TEXT,\r
53 Value3 TEXT,\r
54 Scope1 TEXT,\r
55 Scope2 TEXT,\r
56 BelongsToItem REAL NOT NULL,\r
57 BelongsToFile SINGLE NOT NULL,\r
58 StartLine INTEGER NOT NULL,\r
59 StartColumn INTEGER NOT NULL,\r
60 EndLine INTEGER NOT NULL,\r
61 EndColumn INTEGER NOT NULL,\r
62 Enabled INTEGER DEFAULT 0\r
63 '''\r
64 # used as table end flag, in case the changes to database is not committed to db file\r
65 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
66\r
67 ## Constructor\r
68 def __init__(self, Cursor):\r
69 MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_INF, "Inf", False)\r
70\r
71 ## Insert a record into table Inf\r
72 #\r
73 # @param Model: Model of a Inf item\r
74 # @param Value1: Value1 of a Inf item\r
75 # @param Value2: Value2 of a Inf item\r
76 # @param Value3: Value3 of a Inf item\r
77 # @param Scope1: Arch of a Inf item\r
78 # @param Scope2 Platform os a Inf item\r
79 # @param BelongsToItem: The item belongs to which another item\r
80 # @param StartLine: StartLine of a Inf item\r
81 # @param StartColumn: StartColumn of a Inf item\r
82 # @param EndLine: EndLine of a Inf item\r
83 # @param EndColumn: EndColumn of a Inf item\r
84 # @param Enabled: If this item enabled\r
85 #\r
86 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
87 BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
88 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
89 return Table.Insert(\r
90 self, \r
91 Model, \r
92 Value1, \r
93 Value2, \r
94 Value3, \r
95 Scope1, \r
96 Scope2,\r
97 BelongsToItem,\r
98 BelongsToFile, \r
99 StartLine, \r
100 StartColumn, \r
101 EndLine, \r
102 EndColumn, \r
103 Enabled\r
104 )\r
105\r
106 ## Query table\r
107 #\r
108 # @param Model: The Model of Record \r
109 # @param Arch: The Arch attribute of Record \r
110 # @param Platform The Platform attribute of Record \r
111 #\r
112 # @retval: A recordSet of all found records \r
113 #\r
114 def Query(self, Model, Arch=None, Platform=None):\r
115 ConditionString = "Model=%s AND Enabled>=0" % Model\r
116 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
117\r
118 if Arch != None and Arch != 'COMMON':\r
119 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
120 if Platform != None and Platform != 'COMMON':\r
121 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform\r
122\r
123 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
124 return self.Exec(SqlCommand)\r
125\r
126## Python class representation of table storing package data\r
127class PackageTable(MetaFileTable):\r
128 _COLUMN_ = '''\r
129 ID REAL PRIMARY KEY,\r
130 Model INTEGER NOT NULL,\r
131 Value1 TEXT NOT NULL,\r
132 Value2 TEXT,\r
133 Value3 TEXT,\r
134 Scope1 TEXT,\r
135 Scope2 TEXT,\r
136 BelongsToItem REAL NOT NULL,\r
137 BelongsToFile SINGLE NOT NULL,\r
138 StartLine INTEGER NOT NULL,\r
139 StartColumn INTEGER NOT NULL,\r
140 EndLine INTEGER NOT NULL,\r
141 EndColumn INTEGER NOT NULL,\r
142 Enabled INTEGER DEFAULT 0\r
143 '''\r
144 # used as table end flag, in case the changes to database is not committed to db file\r
145 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
146\r
147 ## Constructor\r
148 def __init__(self, Cursor):\r
149 MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_DEC, "Dec", False)\r
150\r
151 ## Insert table\r
152 #\r
153 # Insert a record into table Dec\r
154 #\r
155 # @param Model: Model of a Dec item\r
156 # @param Value1: Value1 of a Dec item\r
157 # @param Value2: Value2 of a Dec item\r
158 # @param Value3: Value3 of a Dec item\r
159 # @param Scope1: Arch of a Dec item\r
160 # @param Scope2: Module type of a Dec item\r
161 # @param BelongsToItem: The item belongs to which another item\r
162 # @param StartLine: StartLine of a Dec item\r
163 # @param StartColumn: StartColumn of a Dec item\r
164 # @param EndLine: EndLine of a Dec item\r
165 # @param EndColumn: EndColumn of a Dec item\r
166 # @param Enabled: If this item enabled\r
167 #\r
168 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
169 BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
170 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
171 return Table.Insert(\r
172 self, \r
173 Model, \r
174 Value1, \r
175 Value2, \r
176 Value3, \r
177 Scope1, \r
178 Scope2,\r
179 BelongsToItem,\r
180 BelongsToFile, \r
181 StartLine, \r
182 StartColumn, \r
183 EndLine, \r
184 EndColumn, \r
185 Enabled\r
186 )\r
187\r
188 ## Query table\r
189 #\r
190 # @param Model: The Model of Record \r
191 # @param Arch: The Arch attribute of Record \r
192 #\r
193 # @retval: A recordSet of all found records \r
194 #\r
195 def Query(self, Model, Arch=None):\r
196 ConditionString = "Model=%s AND Enabled>=0" % Model\r
197 ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"\r
198\r
199 if Arch != None and Arch != 'COMMON':\r
200 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
201\r
202 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
203 return self.Exec(SqlCommand)\r
204\r
205## Python class representation of table storing platform data\r
206class PlatformTable(MetaFileTable):\r
207 _COLUMN_ = '''\r
208 ID REAL PRIMARY KEY,\r
209 Model INTEGER NOT NULL,\r
210 Value1 TEXT NOT NULL,\r
211 Value2 TEXT,\r
212 Value3 TEXT,\r
213 Scope1 TEXT,\r
214 Scope2 TEXT,\r
215 BelongsToItem REAL NOT NULL,\r
216 BelongsToFile SINGLE NOT NULL,\r
217 FromItem REAL NOT NULL,\r
218 StartLine INTEGER NOT NULL,\r
219 StartColumn INTEGER NOT NULL,\r
220 EndLine INTEGER NOT NULL,\r
221 EndColumn INTEGER NOT NULL,\r
222 Enabled INTEGER DEFAULT 0\r
223 '''\r
224 # used as table end flag, in case the changes to database is not committed to db file\r
225 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"\r
226\r
227 ## Constructor\r
228 def __init__(self, Cursor, MetaFile = '', FileType = MODEL_FILE_DSC, Temporary = False):\r
229 MetaFileTable.__init__(self, Cursor, MetaFile, FileType, "Dsc", Temporary)\r
230\r
231 ## Insert table\r
232 #\r
233 # Insert a record into table Dsc\r
234 #\r
235 # @param Model: Model of a Dsc item\r
236 # @param Value1: Value1 of a Dsc item\r
237 # @param Value2: Value2 of a Dsc item\r
238 # @param Value3: Value3 of a Dsc item\r
239 # @param Scope1: Arch of a Dsc item\r
240 # @param Scope2: Module type of a Dsc item\r
241 # @param BelongsToItem: The item belongs to which another item\r
242 # @param FromItem: The item belongs to which dsc file\r
243 # @param StartLine: StartLine of a Dsc item\r
244 # @param StartColumn: StartColumn of a Dsc item\r
245 # @param EndLine: EndLine of a Dsc item\r
246 # @param EndColumn: EndColumn of a Dsc item\r
247 # @param Enabled: If this item enabled\r
248 #\r
249 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, BelongsToFile = -1,\r
250 FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):\r
251 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
252 return Table.Insert(\r
253 self, \r
254 Model, \r
255 Value1, \r
256 Value2, \r
257 Value3, \r
258 Scope1, \r
259 Scope2,\r
260 BelongsToItem, \r
261 BelongsToFile,\r
262 FromItem,\r
263 StartLine, \r
264 StartColumn, \r
265 EndLine, \r
266 EndColumn, \r
267 Enabled\r
268 )\r
269\r
270 ## Query table\r
271 #\r
272 # @param Model: The Model of Record \r
273 # @param Scope1: Arch of a Dsc item\r
274 # @param Scope2: Module type of a Dsc item\r
275 # @param BelongsToItem: The item belongs to which another item\r
276 # @param FromItem: The item belongs to which dsc file\r
277 #\r
278 # @retval: A recordSet of all found records \r
279 #\r
280 def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):\r
281 ConditionString = "Model=%s AND Enabled>0" % Model\r
282 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
283\r
284 if Scope1 != None and Scope1 != 'COMMON':\r
285 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1\r
286 if Scope2 != None and Scope2 != 'COMMON':\r
287 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2\r
288\r
289 if BelongsToItem != None:\r
290 ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r
291 else:\r
292 ConditionString += " AND BelongsToItem<0"\r
293\r
294 if FromItem != None:\r
295 ConditionString += " AND FromItem=%s" % FromItem\r
296\r
297 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
298 return self.Exec(SqlCommand)\r
299\r
300## Factory class to produce different storage for different type of meta-file\r
301class MetaFileStorage(object):\r
302 _FILE_TABLE_ = {\r
303 MODEL_FILE_INF : ModuleTable,\r
304 MODEL_FILE_DEC : PackageTable,\r
305 MODEL_FILE_DSC : PlatformTable,\r
306 MODEL_FILE_OTHERS : MetaFileTable,\r
307 }\r
308\r
309 _FILE_TYPE_ = {\r
310 ".inf" : MODEL_FILE_INF,\r
311 ".dec" : MODEL_FILE_DEC,\r
312 ".dsc" : MODEL_FILE_DSC,\r
313 }\r
314\r
315 ## Constructor\r
316 def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):\r
317 # no type given, try to find one\r
318 if not FileType:\r
319 if MetaFile.Type in self._FILE_TYPE_:\r
320 FileType = Class._FILE_TYPE_[MetaFile.Type]\r
321 else:\r
322 FileType = MODEL_FILE_OTHERS\r
323\r
324 # don't pass the type around if it's well known\r
325 if FileType == MODEL_FILE_OTHERS:\r
326 Args = (Cursor, MetaFile, FileType, Temporary)\r
327 else:\r
328 Args = (Cursor, MetaFile, FileType, Temporary)\r
329\r
330 # create the storage object and return it to caller\r
331 return Class._FILE_TABLE_[FileType](*Args)\r
332\r