]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileTable.py
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 # 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.
17 from __future__
import absolute_import
20 import Common
.EdkLogger
as EdkLogger
23 from .MetaDataTable
import Table
24 from .MetaDataTable
import ConvertToSqlString
25 from CommonDataClass
.DataClass
import MODEL_FILE_DSC
, MODEL_FILE_DEC
, MODEL_FILE_INF
, \
28 class MetaFileTable(Table
):
30 def __init__(self
, Cursor
, MetaFile
, FileType
, TableName
, Temporary
= False):
31 self
.MetaFile
= MetaFile
32 self
.TblFile
= EccGlobalData
.gDb
.TblFile
33 if (FileType
== MODEL_FILE_INF
):
35 if (FileType
== MODEL_FILE_DSC
):
37 TableName
= "_%s_%s" % ("Dsc", uuid
.uuid4().hex)
40 if (FileType
== MODEL_FILE_DEC
):
43 Table
.__init
__(self
, Cursor
, TableName
, 0, Temporary
)
47 ## Python class representation of table storing module data
48 class ModuleTable(MetaFileTable
):
51 Model INTEGER NOT NULL,
58 BelongsToItem REAL NOT NULL,
59 BelongsToFile SINGLE NOT NULL,
60 StartLine INTEGER NOT NULL,
61 StartColumn INTEGER NOT NULL,
62 EndLine INTEGER NOT NULL,
63 EndColumn INTEGER NOT NULL,
64 Enabled INTEGER DEFAULT 0
66 # used as table end flag, in case the changes to database is not committed to db file
67 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
70 def __init__(self
, Cursor
):
71 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_INF
, "Inf", False)
73 ## Insert a record into table Inf
75 # @param Model: Model of a Inf item
76 # @param Value1: Value1 of a Inf item
77 # @param Value2: Value2 of a Inf item
78 # @param Value3: Value3 of a Inf item
79 # @param Scope1: Arch of a Inf item
80 # @param Scope2 Platform os a Inf item
81 # @param BelongsToItem: The item belongs to which another item
82 # @param StartLine: StartLine of a Inf item
83 # @param StartColumn: StartColumn of a Inf item
84 # @param EndLine: EndLine of a Inf item
85 # @param EndColumn: EndColumn of a Inf item
86 # @param Enabled: If this item enabled
88 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
89 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0, Usage
=''):
90 (Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Usage
, Scope1
, Scope2
))
111 # @param Model: The Model of Record
112 # @param Arch: The Arch attribute of Record
113 # @param Platform The Platform attribute of Record
115 # @retval: A recordSet of all found records
117 def Query(self
, Model
, Arch
=None, Platform
=None):
118 ConditionString
= "Model=%s AND Enabled>=0" % Model
119 ValueString
= "Value1,Value2,Value3,Usage,Scope1,Scope2,ID,StartLine"
121 if Arch
is not None and Arch
!= 'COMMON':
122 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
123 if Platform
is not None and Platform
!= 'COMMON':
124 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform
126 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
127 return self
.Exec(SqlCommand
)
129 ## Python class representation of table storing package data
130 class PackageTable(MetaFileTable
):
133 Model INTEGER NOT NULL,
134 Value1 TEXT NOT NULL,
139 BelongsToItem REAL NOT NULL,
140 BelongsToFile SINGLE NOT NULL,
141 StartLine INTEGER NOT NULL,
142 StartColumn INTEGER NOT NULL,
143 EndLine INTEGER NOT NULL,
144 EndColumn INTEGER NOT NULL,
145 Enabled INTEGER DEFAULT 0
147 # used as table end flag, in case the changes to database is not committed to db file
148 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
151 def __init__(self
, Cursor
):
152 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_DEC
, "Dec", False)
156 # Insert a record into table Dec
158 # @param Model: Model of a Dec item
159 # @param Value1: Value1 of a Dec item
160 # @param Value2: Value2 of a Dec item
161 # @param Value3: Value3 of a Dec item
162 # @param Scope1: Arch of a Dec item
163 # @param Scope2: Module type of a Dec item
164 # @param BelongsToItem: The item belongs to which another item
165 # @param StartLine: StartLine of a Dec item
166 # @param StartColumn: StartColumn of a Dec item
167 # @param EndLine: EndLine of a Dec item
168 # @param EndColumn: EndColumn of a Dec item
169 # @param Enabled: If this item enabled
171 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON',
172 BelongsToItem
=-1, BelongsToFile
= -1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=0):
173 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
193 # @param Model: The Model of Record
194 # @param Arch: The Arch attribute of Record
196 # @retval: A recordSet of all found records
198 def Query(self
, Model
, Arch
=None):
199 ConditionString
= "Model=%s AND Enabled>=0" % Model
200 ValueString
= "Value1,Value2,Value3,Scope1,ID,StartLine"
202 if Arch
is not None and Arch
!= 'COMMON':
203 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
205 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
206 return self
.Exec(SqlCommand
)
208 ## Python class representation of table storing platform data
209 class PlatformTable(MetaFileTable
):
212 Model INTEGER NOT NULL,
213 Value1 TEXT NOT NULL,
218 BelongsToItem REAL NOT NULL,
219 BelongsToFile SINGLE NOT NULL,
220 FromItem REAL NOT NULL,
221 StartLine INTEGER NOT NULL,
222 StartColumn INTEGER NOT NULL,
223 EndLine INTEGER NOT NULL,
224 EndColumn INTEGER NOT NULL,
225 Enabled INTEGER DEFAULT 0
227 # used as table end flag, in case the changes to database is not committed to db file
228 _DUMMY_
= "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"
231 def __init__(self
, Cursor
, MetaFile
= '', FileType
= MODEL_FILE_DSC
, Temporary
= False):
232 MetaFileTable
.__init
__(self
, Cursor
, MetaFile
, FileType
, "Dsc", Temporary
)
236 # Insert a record into table Dsc
238 # @param Model: Model of a Dsc item
239 # @param Value1: Value1 of a Dsc item
240 # @param Value2: Value2 of a Dsc item
241 # @param Value3: Value3 of a Dsc item
242 # @param Scope1: Arch of a Dsc item
243 # @param Scope2: Module type of a Dsc item
244 # @param BelongsToItem: The item belongs to which another item
245 # @param FromItem: The item belongs to which dsc file
246 # @param StartLine: StartLine of a Dsc item
247 # @param StartColumn: StartColumn of a Dsc item
248 # @param EndLine: EndLine of a Dsc item
249 # @param EndColumn: EndColumn of a Dsc item
250 # @param Enabled: If this item enabled
252 def Insert(self
, Model
, Value1
, Value2
, Value3
, Scope1
='COMMON', Scope2
='COMMON', BelongsToItem
=-1, BelongsToFile
= -1,
253 FromItem
=-1, StartLine
=-1, StartColumn
=-1, EndLine
=-1, EndColumn
=-1, Enabled
=1):
254 (Value1
, Value2
, Value3
, Scope1
, Scope2
) = ConvertToSqlString((Value1
, Value2
, Value3
, Scope1
, Scope2
))
275 # @param Model: The Model of Record
276 # @param Scope1: Arch of a Dsc item
277 # @param Scope2: Module type of a Dsc item
278 # @param BelongsToItem: The item belongs to which another item
279 # @param FromItem: The item belongs to which dsc file
281 # @retval: A recordSet of all found records
283 def Query(self
, Model
, Scope1
=None, Scope2
=None, BelongsToItem
=None, FromItem
=None):
284 ConditionString
= "Model=%s AND Enabled>0" % Model
285 ValueString
= "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
287 if Scope1
is not None and Scope1
!= 'COMMON':
288 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1
289 if Scope2
is not None and Scope2
!= 'COMMON':
290 ConditionString
+= " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2
292 if BelongsToItem
is not None:
293 ConditionString
+= " AND BelongsToItem=%s" % BelongsToItem
295 ConditionString
+= " AND BelongsToItem<0"
297 if FromItem
is not None:
298 ConditionString
+= " AND FromItem=%s" % FromItem
300 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
301 return self
.Exec(SqlCommand
)
303 ## Factory class to produce different storage for different type of meta-file
304 class MetaFileStorage(object):
306 MODEL_FILE_INF
: ModuleTable
,
307 MODEL_FILE_DEC
: PackageTable
,
308 MODEL_FILE_DSC
: PlatformTable
,
309 MODEL_FILE_OTHERS
: MetaFileTable
,
313 ".inf" : MODEL_FILE_INF
,
314 ".dec" : MODEL_FILE_DEC
,
315 ".dsc" : MODEL_FILE_DSC
,
319 def __new__(Class
, Cursor
, MetaFile
, FileType
=None, Temporary
=False):
320 # no type given, try to find one
322 if MetaFile
.Type
in self
._FILE
_TYPE
_:
323 FileType
= Class
._FILE
_TYPE
_[MetaFile
.Type
]
325 FileType
= MODEL_FILE_OTHERS
327 # don't pass the type around if it's well known
328 if FileType
== MODEL_FILE_OTHERS
:
329 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
331 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
333 # create the storage object and return it to caller
334 return Class
._FILE
_TABLE
_[FileType
](*Args
)