]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileTable.py
0914aec460f5cf2503833d7c020cf5adfc7daa27
2 # This file is used to create/update/query/erase a meta file table
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 from __future__
import absolute_import
14 import Common
.EdkLogger
as EdkLogger
15 import Ecc
.EccGlobalData
as EccGlobalData
17 from Ecc
.MetaFileWorkspace
.MetaDataTable
import Table
18 from Ecc
.MetaFileWorkspace
.MetaDataTable
import ConvertToSqlString
19 from CommonDataClass
.DataClass
import MODEL_FILE_DSC
, MODEL_FILE_DEC
, MODEL_FILE_INF
, \
22 class MetaFileTable(Table
):
24 def __init__(self
, Cursor
, MetaFile
, FileType
, TableName
, Temporary
= False):
25 self
.MetaFile
= MetaFile
26 self
.TblFile
= EccGlobalData
.gDb
.TblFile
27 if (FileType
== MODEL_FILE_INF
):
29 if (FileType
== MODEL_FILE_DSC
):
31 TableName
= "_%s_%s" % ("Dsc", uuid
.uuid4().hex)
34 if (FileType
== MODEL_FILE_DEC
):
37 Table
.__init
__(self
, Cursor
, TableName
, 0, Temporary
)
41 ## Python class representation of table storing module data
42 class ModuleTable(MetaFileTable
):
45 Model INTEGER NOT NULL,
52 BelongsToItem REAL NOT NULL,
53 BelongsToFile SINGLE NOT NULL,
54 StartLine INTEGER NOT NULL,
55 StartColumn INTEGER NOT NULL,
56 EndLine INTEGER NOT NULL,
57 EndColumn INTEGER NOT NULL,
58 Enabled INTEGER DEFAULT 0
60 # used as table end flag, in case the changes to database is not committed to db file
61 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
64 def __init__(self
, Cursor
):
65 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_INF
, "Inf", False)
67 ## Insert a record into table Inf
69 # @param Model: Model of a Inf item
70 # @param Value1: Value1 of a Inf item
71 # @param Value2: Value2 of a Inf item
72 # @param Value3: Value3 of a Inf item
73 # @param Scope1: Arch of a Inf item
74 # @param Scope2 Platform os a Inf item
75 # @param BelongsToItem: The item belongs to which another item
76 # @param StartLine: StartLine of a Inf item
77 # @param StartColumn: StartColumn of a Inf item
78 # @param EndLine: EndLine of a Inf item
79 # @param EndColumn: EndColumn of a Inf item
80 # @param Enabled: If this item enabled
82 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
83 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0, Usage
=''):
84 (Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
))
105 # @param Model: The Model of Record
106 # @param Arch: The Arch attribute of Record
107 # @param Platform The Platform attribute of Record
109 # @retval: A recordSet of all found records
111 def Query(self
, Model
, Arch
=None, Platform
=None):
112 ConditionString
= "Model=%s AND Enabled>=0" % Model
113 ValueString
= "Value1,Value2,Value3,Usage,Scope1,Scope2,ID,StartLine"
115 if Arch
is not None and Arch
!= 'COMMON':
116 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
117 if Platform
is not None and Platform
!= 'COMMON':
118 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform
120 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
121 return self
.Exec(SqlCommand
)
123 ## Python class representation of table storing package data
124 class PackageTable(MetaFileTable
):
127 Model INTEGER NOT NULL,
128 Value1 TEXT NOT NULL,
133 BelongsToItem REAL NOT NULL,
134 BelongsToFile SINGLE NOT NULL,
135 StartLine INTEGER NOT NULL,
136 StartColumn INTEGER NOT NULL,
137 EndLine INTEGER NOT NULL,
138 EndColumn INTEGER NOT NULL,
139 Enabled INTEGER DEFAULT 0
141 # used as table end flag, in case the changes to database is not committed to db file
142 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
145 def __init__(self
, Cursor
):
146 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_DEC
, "Dec", False)
150 # Insert a record into table Dec
152 # @param Model: Model of a Dec item
153 # @param Value1: Value1 of a Dec item
154 # @param Value2: Value2 of a Dec item
155 # @param Value3: Value3 of a Dec item
156 # @param Scope1: Arch of a Dec item
157 # @param Scope2: Module type of a Dec item
158 # @param BelongsToItem: The item belongs to which another item
159 # @param StartLine: StartLine of a Dec item
160 # @param StartColumn: StartColumn of a Dec item
161 # @param EndLine: EndLine of a Dec item
162 # @param EndColumn: EndColumn of a Dec item
163 # @param Enabled: If this item enabled
165 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
166 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0):
167 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
187 # @param Model: The Model of Record
188 # @param Arch: The Arch attribute of Record
190 # @retval: A recordSet of all found records
192 def Query(self
, Model
, Arch
=None):
193 ConditionString
= "Model=%s AND Enabled>=0" % Model
194 ValueString
= "Value1,Value2,Value3,Scope1,ID,StartLine"
196 if Arch
is not None and Arch
!= 'COMMON':
197 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
199 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
200 return self
.Exec(SqlCommand
)
202 ## Python class representation of table storing platform data
203 class PlatformTable(MetaFileTable
):
206 Model INTEGER NOT NULL,
207 Value1 TEXT NOT NULL,
212 BelongsToItem REAL NOT NULL,
213 BelongsToFile SINGLE NOT NULL,
214 FromItem REAL NOT NULL,
215 StartLine INTEGER NOT NULL,
216 StartColumn INTEGER NOT NULL,
217 EndLine INTEGER NOT NULL,
218 EndColumn INTEGER NOT NULL,
219 Enabled INTEGER DEFAULT 0
221 # used as table end flag, in case the changes to database is not committed to db file
222 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"
225 def __init__(self
, Cursor
, MetaFile
= '', FileType
= MODEL_FILE_DSC
, Temporary
= False):
226 MetaFileTable
.__init
__(self
, Cursor
, MetaFile
, FileType
, "Dsc", Temporary
)
230 # Insert a record into table Dsc
232 # @param Model: Model of a Dsc item
233 # @param Value1: Value1 of a Dsc item
234 # @param Value2: Value2 of a Dsc item
235 # @param Value3: Value3 of a Dsc item
236 # @param Scope1: Arch of a Dsc item
237 # @param Scope2: Module type of a Dsc item
238 # @param BelongsToItem: The item belongs to which another item
239 # @param FromItem: The item belongs to which dsc file
240 # @param StartLine: StartLine of a Dsc item
241 # @param StartColumn: StartColumn of a Dsc item
242 # @param EndLine: EndLine of a Dsc item
243 # @param EndColumn: EndColumn of a Dsc item
244 # @param Enabled: If this item enabled
246 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON', BelongsToItem
=-1, BelongsToFile
= -1,
247 FromItem
=-1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=1):
248 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
269 # @param Model: The Model of Record
270 # @param Scope1: Arch of a Dsc item
271 # @param Scope2: Module type of a Dsc item
272 # @param BelongsToItem: The item belongs to which another item
273 # @param FromItem: The item belongs to which dsc file
275 # @retval: A recordSet of all found records
277 def Query(self
, Model
, Scope1
=None, Scope2
=None, BelongsToItem
=None, FromItem
=None):
278 ConditionString
= "Model=%s AND Enabled>0" % Model
279 ValueString
= "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
281 if Scope1
is not None and Scope1
!= 'COMMON':
282 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1
283 if Scope2
is not None and Scope2
!= 'COMMON':
284 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2
286 if BelongsToItem
is not None:
287 ConditionString
+= " AND BelongsToItem=%s" % BelongsToItem
289 ConditionString
+= " AND BelongsToItem<0"
291 if FromItem
is not None:
292 ConditionString
+= " AND FromItem=%s" % FromItem
294 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
295 return self
.Exec(SqlCommand
)
297 ## Factory class to produce different storage for different type of meta-file
298 class MetaFileStorage(object):
300 MODEL_FILE_INF
: ModuleTable
,
301 MODEL_FILE_DEC
: PackageTable
,
302 MODEL_FILE_DSC
: PlatformTable
,
303 MODEL_FILE_OTHERS
: MetaFileTable
,
307 ".inf" : MODEL_FILE_INF
,
308 ".dec" : MODEL_FILE_DEC
,
309 ".dsc" : MODEL_FILE_DSC
,
313 def __new__(Class
, Cursor
, MetaFile
, FileType
=None, Temporary
=False):
314 # no type given, try to find one
316 if MetaFile
.Type
in self
._FILE
_TYPE
_:
317 FileType
= Class
._FILE
_TYPE
_[MetaFile
.Type
]
319 FileType
= MODEL_FILE_OTHERS
321 # don't pass the type around if it's well known
322 if FileType
== MODEL_FILE_OTHERS
:
323 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
325 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
327 # create the storage object and return it to caller
328 return Class
._FILE
_TABLE
_[FileType
](*Args
)