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