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