--- /dev/null
+## @file\r
+# This file is used to create/update/query/erase table for ECC reports\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. 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 Common.EdkLogger as EdkLogger\r
+import os, time\r
+from Table import Table\r
+from Common.String import ConvertToSqlString2\r
+import EccToolError as EccToolError\r
+import EccGlobalData as EccGlobalData\r
+\r
+## TableReport\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object: Inherited from object class\r
+#\r
+#\r
+class TableReport(Table):\r
+ def __init__(self, Cursor):\r
+ Table.__init__(self, Cursor)\r
+ self.Table = 'Report'\r
+ \r
+ ## Create table\r
+ #\r
+ # Create table report\r
+ #\r
+ # @param ID: ID of an Error\r
+ # @param ErrorID: ID of an Error TypeModel of a Report item\r
+ # @param OtherMsg: Other error message besides the standard error message\r
+ # @param BelongsToItem: The error belongs to which item\r
+ # @param Enabled: If this error enabled\r
+ # @param Corrected: if this error corrected\r
+ #\r
+ def Create(self):\r
+ SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+ ErrorID INTEGER NOT NULL,\r
+ OtherMsg TEXT,\r
+ BelongsToTable TEXT NOT NULL,\r
+ BelongsToItem SINGLE NOT NULL,\r
+ Enabled INTEGER DEFAULT 0,\r
+ Corrected INTEGER DEFAULT -1\r
+ )""" % self.Table\r
+ Table.Create(self, SqlCommand)\r
+\r
+ ## Insert table\r
+ #\r
+ # Insert a record into table report\r
+ #\r
+ # @param ID: ID of an Error\r
+ # @param ErrorID: ID of an Error TypeModel of a report item\r
+ # @param OtherMsg: Other error message besides the standard error message\r
+ # @param BelongsToTable: The error item belongs to which table\r
+ # @param BelongsToItem: The error belongs to which item\r
+ # @param Enabled: If this error enabled\r
+ # @param Corrected: if this error corrected\r
+ #\r
+ def Insert(self, ErrorID, OtherMsg = '', BelongsToTable = '', BelongsToItem = -1, Enabled = 0, Corrected = -1):\r
+ self.ID = self.ID + 1\r
+ SqlCommand = """insert into %s values(%s, %s, '%s', '%s', %s, %s, %s)""" \\r
+ % (self.Table, self.ID, ErrorID, ConvertToSqlString2(OtherMsg), BelongsToTable, BelongsToItem, Enabled, Corrected)\r
+ Table.Insert(self, SqlCommand)\r
+ \r
+ return self.ID\r
+ \r
+ ## Query table\r
+ #\r
+ # @retval: A recordSet of all found records \r
+ #\r
+ def Query(self):\r
+ SqlCommand = """select ID, ErrorID, OtherMsg, BelongsToTable, BelongsToItem, Corrected from %s\r
+ where Enabled > -1 order by ErrorID, BelongsToItem""" % (self.Table)\r
+ return self.Exec(SqlCommand)\r
+\r
+ ## Convert to CSV\r
+ #\r
+ # Get all enabled records from table report and save them to a .csv file\r
+ #\r
+ # @param Filename: To filename to save the report content\r
+ #\r
+ def ToCSV(self, Filename = 'Report.csv'):\r
+ try:\r
+ File = open(Filename, 'w+')\r
+ File.write("""No, Error Code, Error Message, File, LineNo, Other Error Message\n""")\r
+ RecordSet = self.Query()\r
+ Index = 0\r
+ for Record in RecordSet:\r
+ Index = Index + 1\r
+ ErrorID = Record[1]\r
+ OtherMsg = Record[2]\r
+ BelongsToTable = Record[3]\r
+ BelongsToItem = Record[4]\r
+ IsCorrected = Record[5]\r
+ SqlCommand = ''\r
+ if BelongsToTable == 'File':\r
+ SqlCommand = """select 0, FullPath from %s where ID = %s\r
+ """ % (BelongsToTable, BelongsToItem)\r
+ else:\r
+ SqlCommand = """select A.StartLine, B.FullPath from %s as A, File as B\r
+ where A.ID = %s and B.ID = A.BelongsToFile\r
+ """ % (BelongsToTable, BelongsToItem)\r
+ NewRecord = self.Exec(SqlCommand)\r
+ if NewRecord != []:\r
+ File.write("""%s,%s,"%s",%s,%s,"%s"\n""" % (Index, ErrorID, EccToolError.gEccErrorMessage[ErrorID], NewRecord[0][1], NewRecord[0][0], OtherMsg))\r
+ \r
+ File.close()\r
+ except IOError:\r
+ NewFilename = 'Report_' + time.strftime("%Y%m%d_%H%M%S.csv", time.localtime())\r
+ EdkLogger.warn("ECC", "The report file %s is locked by other progress, use %s instead!" % (Filename, NewFilename))\r
+ self.ToCSV(NewFilename)\r
+\r