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