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