]>
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, 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,
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
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"
68 def __init__(self
, Cursor
):
69 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_INF
, "Inf", False)
71 ## Insert a record into table Inf
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
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
))
108 # @param Model: The Model of Record
109 # @param Arch: The Arch attribute of Record
110 # @param Platform The Platform attribute of Record
112 # @retval: A recordSet of all found records
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"
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
123 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
124 return self
.Exec(SqlCommand
)
126 ## Python class representation of table storing package data
127 class PackageTable(MetaFileTable
):
130 Model INTEGER NOT NULL,
131 Value1 TEXT NOT NULL,
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
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"
148 def __init__(self
, Cursor
):
149 MetaFileTable
.__init
__(self
, Cursor
, '', MODEL_FILE_DEC
, "Dec", False)
153 # Insert a record into table Dec
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
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
))
190 # @param Model: The Model of Record
191 # @param Arch: The Arch attribute of Record
193 # @retval: A recordSet of all found records
195 def Query(self
, Model
, Arch
=None):
196 ConditionString
= "Model=%s AND Enabled>=0" % Model
197 ValueString
= "Value1,Value2,Value3,Scope1,ID,StartLine"
199 if Arch
!= None and Arch
!= 'COMMON':
200 ConditionString
+= " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
202 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
203 return self
.Exec(SqlCommand
)
205 ## Python class representation of table storing platform data
206 class PlatformTable(MetaFileTable
):
209 Model INTEGER NOT NULL,
210 Value1 TEXT NOT NULL,
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
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"
228 def __init__(self
, Cursor
, MetaFile
= '', FileType
= MODEL_FILE_DSC
, Temporary
= False):
229 MetaFileTable
.__init
__(self
, Cursor
, MetaFile
, FileType
, "Dsc", Temporary
)
233 # Insert a record into table Dsc
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
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
))
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
278 # @retval: A recordSet of all found records
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"
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
289 if BelongsToItem
!= None:
290 ConditionString
+= " AND BelongsToItem=%s" % BelongsToItem
292 ConditionString
+= " AND BelongsToItem<0"
295 ConditionString
+= " AND FromItem=%s" % FromItem
297 SqlCommand
= "SELECT %s FROM %s WHERE %s" % (ValueString
, self
.Table
, ConditionString
)
298 return self
.Exec(SqlCommand
)
300 ## Factory class to produce different storage for different type of meta-file
301 class MetaFileStorage(object):
303 MODEL_FILE_INF
: ModuleTable
,
304 MODEL_FILE_DEC
: PackageTable
,
305 MODEL_FILE_DSC
: PlatformTable
,
306 MODEL_FILE_OTHERS
: MetaFileTable
,
310 ".inf" : MODEL_FILE_INF
,
311 ".dec" : MODEL_FILE_DEC
,
312 ".dsc" : MODEL_FILE_DSC
,
316 def __new__(Class
, Cursor
, MetaFile
, FileType
=None, Temporary
=False):
317 # no type given, try to find one
319 if MetaFile
.Type
in self
._FILE
_TYPE
_:
320 FileType
= Class
._FILE
_TYPE
_[MetaFile
.Type
]
322 FileType
= MODEL_FILE_OTHERS
324 # don't pass the type around if it's well known
325 if FileType
== MODEL_FILE_OTHERS
:
326 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
328 Args
= (Cursor
, MetaFile
, FileType
, Temporary
)
330 # create the storage object and return it to caller
331 return Class
._FILE
_TABLE
_[FileType
](*Args
)