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