]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to create/update/query/erase table for ECC reports\r | |
3 | #\r | |
f7496d71 | 4 | # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r |
2e351cbe | 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30fdf114 LG |
6 | #\r |
7 | \r | |
8 | ##\r | |
9 | # Import Modules\r | |
10 | #\r | |
1ccc4d89 | 11 | from __future__ import absolute_import\r |
30fdf114 | 12 | import Common.EdkLogger as EdkLogger\r |
1be2ed90 | 13 | import Common.LongFilePathOs as os, time\r |
855698fb | 14 | from Table.Table import Table\r |
5a57246e | 15 | from Common.StringUtils import ConvertToSqlString2\r |
855698fb | 16 | import Ecc.EccToolError as EccToolError\r |
17 | import Ecc.EccGlobalData as EccGlobalData\r | |
1be2ed90 | 18 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
30fdf114 LG |
19 | \r |
20 | ## TableReport\r | |
21 | #\r | |
22 | # This class defined a table used for data model\r | |
f7496d71 | 23 | #\r |
30fdf114 LG |
24 | # @param object: Inherited from object class\r |
25 | #\r | |
26 | #\r | |
27 | class TableReport(Table):\r | |
28 | def __init__(self, Cursor):\r | |
29 | Table.__init__(self, Cursor)\r | |
30 | self.Table = 'Report'\r | |
f7496d71 | 31 | \r |
30fdf114 LG |
32 | ## Create table\r |
33 | #\r | |
34 | # Create table report\r | |
35 | #\r | |
36 | # @param ID: ID of an Error\r | |
37 | # @param ErrorID: ID of an Error TypeModel of a Report item\r | |
38 | # @param OtherMsg: Other error message besides the standard error message\r | |
39 | # @param BelongsToItem: The error belongs to which item\r | |
40 | # @param Enabled: If this error enabled\r | |
41 | # @param Corrected: if this error corrected\r | |
42 | #\r | |
43 | def Create(self):\r | |
44 | SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r | |
45 | ErrorID INTEGER NOT NULL,\r | |
46 | OtherMsg TEXT,\r | |
47 | BelongsToTable TEXT NOT NULL,\r | |
48 | BelongsToItem SINGLE NOT NULL,\r | |
49 | Enabled INTEGER DEFAULT 0,\r | |
50 | Corrected INTEGER DEFAULT -1\r | |
51 | )""" % self.Table\r | |
52 | Table.Create(self, SqlCommand)\r | |
53 | \r | |
54 | ## Insert table\r | |
55 | #\r | |
56 | # Insert a record into table report\r | |
57 | #\r | |
58 | # @param ID: ID of an Error\r | |
59 | # @param ErrorID: ID of an Error TypeModel of a report item\r | |
60 | # @param OtherMsg: Other error message besides the standard error message\r | |
61 | # @param BelongsToTable: The error item belongs to which table\r | |
62 | # @param BelongsToItem: The error belongs to which item\r | |
63 | # @param Enabled: If this error enabled\r | |
64 | # @param Corrected: if this error corrected\r | |
65 | #\r | |
47fea6af | 66 | def Insert(self, ErrorID, OtherMsg='', BelongsToTable='', BelongsToItem= -1, Enabled=0, Corrected= -1):\r |
30fdf114 LG |
67 | self.ID = self.ID + 1\r |
68 | SqlCommand = """insert into %s values(%s, %s, '%s', '%s', %s, %s, %s)""" \\r | |
69 | % (self.Table, self.ID, ErrorID, ConvertToSqlString2(OtherMsg), BelongsToTable, BelongsToItem, Enabled, Corrected)\r | |
70 | Table.Insert(self, SqlCommand)\r | |
47fea6af | 71 | \r |
30fdf114 | 72 | return self.ID\r |
47fea6af | 73 | \r |
30fdf114 LG |
74 | ## Query table\r |
75 | #\r | |
f7496d71 | 76 | # @retval: A recordSet of all found records\r |
30fdf114 LG |
77 | #\r |
78 | def Query(self):\r | |
79 | SqlCommand = """select ID, ErrorID, OtherMsg, BelongsToTable, BelongsToItem, Corrected from %s\r | |
80 | where Enabled > -1 order by ErrorID, BelongsToItem""" % (self.Table)\r | |
81 | return self.Exec(SqlCommand)\r | |
82 | \r | |
1b2467c5 HC |
83 | ## Update table\r |
84 | #\r | |
85 | def UpdateBelongsToItemByFile(self, ItemID=-1, File=""):\r | |
86 | SqlCommand = """update Report set BelongsToItem=%s where BelongsToTable='File' and BelongsToItem=-2\r | |
87 | and OtherMsg like '%%%s%%'""" % (ItemID, File)\r | |
88 | return self.Exec(SqlCommand)\r | |
89 | \r | |
30fdf114 LG |
90 | ## Convert to CSV\r |
91 | #\r | |
92 | # Get all enabled records from table report and save them to a .csv file\r | |
93 | #\r | |
94 | # @param Filename: To filename to save the report content\r | |
95 | #\r | |
47fea6af | 96 | def ToCSV(self, Filename='Report.csv'):\r |
30fdf114 LG |
97 | try:\r |
98 | File = open(Filename, 'w+')\r | |
99 | File.write("""No, Error Code, Error Message, File, LineNo, Other Error Message\n""")\r | |
100 | RecordSet = self.Query()\r | |
101 | Index = 0\r | |
102 | for Record in RecordSet:\r | |
103 | Index = Index + 1\r | |
104 | ErrorID = Record[1]\r | |
105 | OtherMsg = Record[2]\r | |
106 | BelongsToTable = Record[3]\r | |
107 | BelongsToItem = Record[4]\r | |
108 | IsCorrected = Record[5]\r | |
109 | SqlCommand = ''\r | |
110 | if BelongsToTable == 'File':\r | |
40d841f6 | 111 | SqlCommand = """select 1, FullPath from %s where ID = %s\r |
30fdf114 LG |
112 | """ % (BelongsToTable, BelongsToItem)\r |
113 | else:\r | |
114 | SqlCommand = """select A.StartLine, B.FullPath from %s as A, File as B\r | |
115 | where A.ID = %s and B.ID = A.BelongsToFile\r | |
116 | """ % (BelongsToTable, BelongsToItem)\r | |
117 | NewRecord = self.Exec(SqlCommand)\r | |
118 | if NewRecord != []:\r | |
119 | File.write("""%s,%s,"%s",%s,%s,"%s"\n""" % (Index, ErrorID, EccToolError.gEccErrorMessage[ErrorID], NewRecord[0][1], NewRecord[0][0], OtherMsg))\r | |
52302d4d | 120 | EdkLogger.quiet("%s(%s): [%s]%s %s" % (NewRecord[0][1], NewRecord[0][0], ErrorID, EccToolError.gEccErrorMessage[ErrorID], OtherMsg))\r |
47fea6af | 121 | \r |
30fdf114 LG |
122 | File.close()\r |
123 | except IOError:\r | |
124 | NewFilename = 'Report_' + time.strftime("%Y%m%d_%H%M%S.csv", time.localtime())\r | |
125 | EdkLogger.warn("ECC", "The report file %s is locked by other progress, use %s instead!" % (Filename, NewFilename))\r | |
126 | self.ToCSV(NewFilename)\r | |
127 | \r |