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