]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileTable.py
54a3016948b1fbe762296b11901c99e3cdf6dd47
2 # This file is used to create/update/query/erase a meta file table
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
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.
19 import Common
.EdkLogger
as EdkLogger
22 from MetaDataTable
import Table
23 from MetaDataTable
import ConvertToSqlString
24 from CommonDataClass
.DataClass
import MODEL_FILE_DSC
, MODEL_FILE_DEC
, MODEL_FILE_INF
, \
27 class MetaFileTable(Table
):
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
):
34 if (FileType
== MODEL_FILE_DSC
):
36 TableName
= "_%s_%s" % ("Dsc", uuid
.uuid4().hex)
39 if (FileType
== MODEL_FILE_DEC
):
42 Table
.__init
__(self
, Cursor
, TableName
, 0, Temporary
)
46 ## Python class representation of table storing module data
47 class ModuleTable(MetaFileTable
):
50 Model INTEGER NOT NULL,
57 BelongsToItem REAL NOT NULL,
58 BelongsToFile SINGLE NOT NULL,
59 StartLine INTEGER NOT NULL,
60 StartColumn INTEGER NOT NULL,
61 EndLine INTEGER NOT NULL,
62 EndColumn INTEGER NOT NULL,
63 Enabled INTEGER DEFAULT 0
65 # used as table end flag, in case the changes to database is not committed to db file
66 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
69 def __init__(self
, Cursor
):
70 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_INF
, "Inf", False)
72 ## Insert a record into table Inf
74 # @param Model: Model of a Inf item
75 # @param Value1: Value1 of a Inf item
76 # @param Value2: Value2 of a Inf item
77 # @param Value3: Value3 of a Inf item
78 # @param Scope1: Arch of a Inf item
79 # @param Scope2 Platform os a Inf item
80 # @param BelongsToItem: The item belongs to which another item
81 # @param StartLine: StartLine of a Inf item
82 # @param StartColumn: StartColumn of a Inf item
83 # @param EndLine: EndLine of a Inf item
84 # @param EndColumn: EndColumn of a Inf item
85 # @param Enabled: If this item enabled
87 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
88 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0, Usage
=''):
89 (Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
))
110 # @param Model: The Model of Record
111 # @param Arch: The Arch attribute of Record
112 # @param Platform The Platform attribute of Record
114 # @retval: A recordSet of all found records
116 def Query(self
, Model
, Arch
=None, Platform
=None):
117 ConditionString
= "Model=%s AND Enabled>=0" % Model
118 ValueString
= "Value1,Value2,Value3,Usage,Scope1,Scope2,ID,StartLine"
120 if Arch
!= None and Arch
!= 'COMMON':
121 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
122 if Platform
!= None and Platform
!= 'COMMON':
123 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform
125 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
126 return self
.Exec(SqlCommand
)
128 ## Python class representation of table storing package data
129 class PackageTable(MetaFileTable
):
132 Model INTEGER NOT NULL,
133 Value1 TEXT NOT NULL,
138 BelongsToItem REAL NOT NULL,
139 BelongsToFile SINGLE NOT NULL,
140 StartLine INTEGER NOT NULL,
141 StartColumn INTEGER NOT NULL,
142 EndLine INTEGER NOT NULL,
143 EndColumn INTEGER NOT NULL,
144 Enabled INTEGER DEFAULT 0
146 # used as table end flag, in case the changes to database is not committed to db file
147 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
150 def __init__(self
, Cursor
):
151 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_DEC
, "Dec", False)
155 # Insert a record into table Dec
157 # @param Model: Model of a Dec item
158 # @param Value1: Value1 of a Dec item
159 # @param Value2: Value2 of a Dec item
160 # @param Value3: Value3 of a Dec item
161 # @param Scope1: Arch of a Dec item
162 # @param Scope2: Module type of a Dec item
163 # @param BelongsToItem: The item belongs to which another item
164 # @param StartLine: StartLine of a Dec item
165 # @param StartColumn: StartColumn of a Dec item
166 # @param EndLine: EndLine of a Dec item
167 # @param EndColumn: EndColumn of a Dec item
168 # @param Enabled: If this item enabled
170 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
171 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0):
172 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
192 # @param Model: The Model of Record
193 # @param Arch: The Arch attribute of Record
195 # @retval: A recordSet of all found records
197 def Query(self
, Model
, Arch
=None):
198 ConditionString
= "Model=%s AND Enabled>=0" % Model
199 ValueString
= "Value1,Value2,Value3,Scope1,ID,StartLine"
201 if Arch
!= None and Arch
!= 'COMMON':
202 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
204 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
205 return self
.Exec(SqlCommand
)
207 ## Python class representation of table storing platform data
208 class PlatformTable(MetaFileTable
):
211 Model INTEGER NOT NULL,
212 Value1 TEXT NOT NULL,
217 BelongsToItem REAL NOT NULL,
218 BelongsToFile SINGLE NOT NULL,
219 FromItem REAL NOT NULL,
220 StartLine INTEGER NOT NULL,
221 StartColumn INTEGER NOT NULL,
222 EndLine INTEGER NOT NULL,
223 EndColumn INTEGER NOT NULL,
224 Enabled INTEGER DEFAULT 0
226 # used as table end flag, in case the changes to database is not committed to db file
227 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"
230 def __init__(self
, Cursor
, MetaFile
= '', FileType
= MODEL_FILE_DSC
, Temporary
= False):
231 MetaFileTable
.__init
__(self
, Cursor
, MetaFile
, FileType
, "Dsc", Temporary
)
235 # Insert a record into table Dsc
237 # @param Model: Model of a Dsc item
238 # @param Value1: Value1 of a Dsc item
239 # @param Value2: Value2 of a Dsc item
240 # @param Value3: Value3 of a Dsc item
241 # @param Scope1: Arch of a Dsc item
242 # @param Scope2: Module type of a Dsc item
243 # @param BelongsToItem: The item belongs to which another item
244 # @param FromItem: The item belongs to which dsc file
245 # @param StartLine: StartLine of a Dsc item
246 # @param StartColumn: StartColumn of a Dsc item
247 # @param EndLine: EndLine of a Dsc item
248 # @param EndColumn: EndColumn of a Dsc item
249 # @param Enabled: If this item enabled
251 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON', BelongsToItem
=-1, BelongsToFile
= -1,
252 FromItem
=-1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=1):
253 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
274 # @param Model: The Model of Record
275 # @param Scope1: Arch of a Dsc item
276 # @param Scope2: Module type of a Dsc item
277 # @param BelongsToItem: The item belongs to which another item
278 # @param FromItem: The item belongs to which dsc file
280 # @retval: A recordSet of all found records
282 def Query(self
, Model
, Scope1
=None, Scope2
=None, BelongsToItem
=None, FromItem
=None):
283 ConditionString
= "Model=%s AND Enabled>0" % Model
284 ValueString
= "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
286 if Scope1
!= None and Scope1
!= 'COMMON':
287 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1
288 if Scope2
!= None and Scope2
!= 'COMMON':
289 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2
291 if BelongsToItem
!= None:
292 ConditionString
+= " AND BelongsToItem=%s" % BelongsToItem
294 ConditionString
+= " AND BelongsToItem<0"
297 ConditionString
+= " AND FromItem=%s" % FromItem
299 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
300 return self
.Exec(SqlCommand
)
302 ## Factory class to produce different storage for different type of meta-file
303 class MetaFileStorage(object):
305 MODEL_FILE_INF
: ModuleTable
,
306 MODEL_FILE_DEC
: PackageTable
,
307 MODEL_FILE_DSC
: PlatformTable
,
308 MODEL_FILE_OTHERS
: MetaFileTable
,
312 ".inf" : MODEL_FILE_INF
,
313 ".dec" : MODEL_FILE_DEC
,
314 ".dsc" : MODEL_FILE_DSC
,
318 def __new__(Class
, Cursor
, MetaFile
, FileType
=None, Temporary
=False):
319 # no type given, try to find one
321 if MetaFile
.Type
in self
._FILE
_TYPE
_:
322 FileType
= Class
._FILE
_TYPE
_[MetaFile
.Type
]
324 FileType
= MODEL_FILE_OTHERS
326 # don't pass the type around if it's well known
327 if FileType
== MODEL_FILE_OTHERS
:
328 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
330 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
332 # create the storage object and return it to caller
333 return Class
._FILE
_TABLE
_[FileType
](*Args
)