--- /dev/null
+## @file\r
+# This file is used to create/update/query/erase a meta file table\r
+#\r
+# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import uuid\r
+\r
+import Common.EdkLogger as EdkLogger\r
+import EccGlobalData\r
+\r
+from MetaDataTable import Table\r
+from MetaDataTable import ConvertToSqlString\r
+from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \\r
+ MODEL_FILE_OTHERS\r
+\r
+class MetaFileTable(Table):\r
+ ## Constructor \r
+ def __init__(self, Cursor, MetaFile, FileType, TableName, Temporary = False):\r
+ self.MetaFile = MetaFile\r
+ self.TblFile = EccGlobalData.gDb.TblFile\r
+ if (FileType == MODEL_FILE_INF):\r
+ TableName = "Inf"\r
+ if (FileType == MODEL_FILE_DSC):\r
+ if Temporary:\r
+ TableName = "_%s_%s" % ("Dsc", uuid.uuid4().hex)\r
+ else:\r
+ TableName = "Dsc"\r
+ if (FileType == MODEL_FILE_DEC):\r
+ TableName = "Dec"\r
+\r
+ Table.__init__(self, Cursor, TableName, 0, Temporary)\r
+ self.Create(False)\r
+\r
+\r
+## Python class representation of table storing module data\r
+class ModuleTable(MetaFileTable):\r
+ _COLUMN_ = '''\r
+ ID REAL PRIMARY KEY,\r
+ Model INTEGER NOT NULL,\r
+ Value1 TEXT NOT NULL,\r
+ Value2 TEXT,\r
+ Value3 TEXT,\r
+ Scope1 TEXT,\r
+ Scope2 TEXT,\r
+ BelongsToItem REAL NOT NULL,\r
+ BelongsToFile SINGLE NOT NULL,\r
+ StartLine INTEGER NOT NULL,\r
+ StartColumn INTEGER NOT NULL,\r
+ EndLine INTEGER NOT NULL,\r
+ EndColumn INTEGER NOT NULL,\r
+ Enabled INTEGER DEFAULT 0\r
+ '''\r
+ # used as table end flag, in case the changes to database is not committed to db file\r
+ _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
+\r
+ ## Constructor\r
+ def __init__(self, Cursor):\r
+ MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_INF, "Inf", False)\r
+\r
+ ## Insert a record into table Inf\r
+ #\r
+ # @param Model: Model of a Inf item\r
+ # @param Value1: Value1 of a Inf item\r
+ # @param Value2: Value2 of a Inf item\r
+ # @param Value3: Value3 of a Inf item\r
+ # @param Scope1: Arch of a Inf item\r
+ # @param Scope2 Platform os a Inf item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param StartLine: StartLine of a Inf item\r
+ # @param StartColumn: StartColumn of a Inf item\r
+ # @param EndLine: EndLine of a Inf item\r
+ # @param EndColumn: EndColumn of a Inf item\r
+ # @param Enabled: If this item enabled\r
+ #\r
+ def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
+ BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
+ (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
+ return Table.Insert(\r
+ self, \r
+ Model, \r
+ Value1, \r
+ Value2, \r
+ Value3, \r
+ Scope1, \r
+ Scope2,\r
+ BelongsToItem,\r
+ BelongsToFile, \r
+ StartLine, \r
+ StartColumn, \r
+ EndLine, \r
+ EndColumn, \r
+ Enabled\r
+ )\r
+\r
+ ## Query table\r
+ #\r
+ # @param Model: The Model of Record \r
+ # @param Arch: The Arch attribute of Record \r
+ # @param Platform The Platform attribute of Record \r
+ #\r
+ # @retval: A recordSet of all found records \r
+ #\r
+ def Query(self, Model, Arch=None, Platform=None):\r
+ ConditionString = "Model=%s AND Enabled>=0" % Model\r
+ ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
+\r
+ if Arch != None and Arch != 'COMMON':\r
+ ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
+ if Platform != None and Platform != 'COMMON':\r
+ ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform\r
+\r
+ SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
+ return self.Exec(SqlCommand)\r
+\r
+## Python class representation of table storing package data\r
+class PackageTable(MetaFileTable):\r
+ _COLUMN_ = '''\r
+ ID REAL PRIMARY KEY,\r
+ Model INTEGER NOT NULL,\r
+ Value1 TEXT NOT NULL,\r
+ Value2 TEXT,\r
+ Value3 TEXT,\r
+ Scope1 TEXT,\r
+ Scope2 TEXT,\r
+ BelongsToItem REAL NOT NULL,\r
+ BelongsToFile SINGLE NOT NULL,\r
+ StartLine INTEGER NOT NULL,\r
+ StartColumn INTEGER NOT NULL,\r
+ EndLine INTEGER NOT NULL,\r
+ EndColumn INTEGER NOT NULL,\r
+ Enabled INTEGER DEFAULT 0\r
+ '''\r
+ # used as table end flag, in case the changes to database is not committed to db file\r
+ _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
+\r
+ ## Constructor\r
+ def __init__(self, Cursor):\r
+ MetaFileTable.__init__(self, Cursor, '', MODEL_FILE_DEC, "Dec", False)\r
+\r
+ ## Insert table\r
+ #\r
+ # Insert a record into table Dec\r
+ #\r
+ # @param Model: Model of a Dec item\r
+ # @param Value1: Value1 of a Dec item\r
+ # @param Value2: Value2 of a Dec item\r
+ # @param Value3: Value3 of a Dec item\r
+ # @param Scope1: Arch of a Dec item\r
+ # @param Scope2: Module type of a Dec item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param StartLine: StartLine of a Dec item\r
+ # @param StartColumn: StartColumn of a Dec item\r
+ # @param EndLine: EndLine of a Dec item\r
+ # @param EndColumn: EndColumn of a Dec item\r
+ # @param Enabled: If this item enabled\r
+ #\r
+ def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
+ BelongsToItem=-1, BelongsToFile = -1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
+ (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
+ return Table.Insert(\r
+ self, \r
+ Model, \r
+ Value1, \r
+ Value2, \r
+ Value3, \r
+ Scope1, \r
+ Scope2,\r
+ BelongsToItem,\r
+ BelongsToFile, \r
+ StartLine, \r
+ StartColumn, \r
+ EndLine, \r
+ EndColumn, \r
+ Enabled\r
+ )\r
+\r
+ ## Query table\r
+ #\r
+ # @param Model: The Model of Record \r
+ # @param Arch: The Arch attribute of Record \r
+ #\r
+ # @retval: A recordSet of all found records \r
+ #\r
+ def Query(self, Model, Arch=None):\r
+ ConditionString = "Model=%s AND Enabled>=0" % Model\r
+ ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"\r
+\r
+ if Arch != None and Arch != 'COMMON':\r
+ ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
+\r
+ SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
+ return self.Exec(SqlCommand)\r
+\r
+## Python class representation of table storing platform data\r
+class PlatformTable(MetaFileTable):\r
+ _COLUMN_ = '''\r
+ ID REAL PRIMARY KEY,\r
+ Model INTEGER NOT NULL,\r
+ Value1 TEXT NOT NULL,\r
+ Value2 TEXT,\r
+ Value3 TEXT,\r
+ Scope1 TEXT,\r
+ Scope2 TEXT,\r
+ BelongsToItem REAL NOT NULL,\r
+ BelongsToFile SINGLE NOT NULL,\r
+ FromItem REAL NOT NULL,\r
+ StartLine INTEGER NOT NULL,\r
+ StartColumn INTEGER NOT NULL,\r
+ EndLine INTEGER NOT NULL,\r
+ EndColumn INTEGER NOT NULL,\r
+ Enabled INTEGER DEFAULT 0\r
+ '''\r
+ # used as table end flag, in case the changes to database is not committed to db file\r
+ _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1, -1"\r
+\r
+ ## Constructor\r
+ def __init__(self, Cursor, MetaFile = '', FileType = MODEL_FILE_DSC, Temporary = False):\r
+ MetaFileTable.__init__(self, Cursor, MetaFile, FileType, "Dsc", Temporary)\r
+\r
+ ## Insert table\r
+ #\r
+ # Insert a record into table Dsc\r
+ #\r
+ # @param Model: Model of a Dsc item\r
+ # @param Value1: Value1 of a Dsc item\r
+ # @param Value2: Value2 of a Dsc item\r
+ # @param Value3: Value3 of a Dsc item\r
+ # @param Scope1: Arch of a Dsc item\r
+ # @param Scope2: Module type of a Dsc item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param FromItem: The item belongs to which dsc file\r
+ # @param StartLine: StartLine of a Dsc item\r
+ # @param StartColumn: StartColumn of a Dsc item\r
+ # @param EndLine: EndLine of a Dsc item\r
+ # @param EndColumn: EndColumn of a Dsc item\r
+ # @param Enabled: If this item enabled\r
+ #\r
+ def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, BelongsToFile = -1,\r
+ FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):\r
+ (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
+ return Table.Insert(\r
+ self, \r
+ Model, \r
+ Value1, \r
+ Value2, \r
+ Value3, \r
+ Scope1, \r
+ Scope2,\r
+ BelongsToItem, \r
+ BelongsToFile,\r
+ FromItem,\r
+ StartLine, \r
+ StartColumn, \r
+ EndLine, \r
+ EndColumn, \r
+ Enabled\r
+ )\r
+\r
+ ## Query table\r
+ #\r
+ # @param Model: The Model of Record \r
+ # @param Scope1: Arch of a Dsc item\r
+ # @param Scope2: Module type of a Dsc item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param FromItem: The item belongs to which dsc file\r
+ #\r
+ # @retval: A recordSet of all found records \r
+ #\r
+ def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):\r
+ ConditionString = "Model=%s AND Enabled>0" % Model\r
+ ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
+\r
+ if Scope1 != None and Scope1 != 'COMMON':\r
+ ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1\r
+ if Scope2 != None and Scope2 != 'COMMON':\r
+ ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2\r
+\r
+ if BelongsToItem != None:\r
+ ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r
+ else:\r
+ ConditionString += " AND BelongsToItem<0"\r
+\r
+ if FromItem != None:\r
+ ConditionString += " AND FromItem=%s" % FromItem\r
+\r
+ SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
+ return self.Exec(SqlCommand)\r
+\r
+## Factory class to produce different storage for different type of meta-file\r
+class MetaFileStorage(object):\r
+ _FILE_TABLE_ = {\r
+ MODEL_FILE_INF : ModuleTable,\r
+ MODEL_FILE_DEC : PackageTable,\r
+ MODEL_FILE_DSC : PlatformTable,\r
+ MODEL_FILE_OTHERS : MetaFileTable,\r
+ }\r
+\r
+ _FILE_TYPE_ = {\r
+ ".inf" : MODEL_FILE_INF,\r
+ ".dec" : MODEL_FILE_DEC,\r
+ ".dsc" : MODEL_FILE_DSC,\r
+ }\r
+\r
+ ## Constructor\r
+ def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):\r
+ # no type given, try to find one\r
+ if not FileType:\r
+ if MetaFile.Type in self._FILE_TYPE_:\r
+ FileType = Class._FILE_TYPE_[MetaFile.Type]\r
+ else:\r
+ FileType = MODEL_FILE_OTHERS\r
+\r
+ # don't pass the type around if it's well known\r
+ if FileType == MODEL_FILE_OTHERS:\r
+ Args = (Cursor, MetaFile, FileType, Temporary)\r
+ else:\r
+ Args = (Cursor, MetaFile, FileType, Temporary)\r
+\r
+ # create the storage object and return it to caller\r
+ return Class._FILE_TABLE_[FileType](*Args)\r
+\r