]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Table/TableReport.py
2 # This file is used to create/update/query/erase table for ECC reports
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
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
22 # This class defined a table used for data model
24 # @param object: Inherited from object class
27 class TableReport(Table
):
28 def __init__(self
, Cursor
):
29 Table
.__init
__(self
, Cursor
)
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
44 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
45 ErrorID INTEGER NOT NULL,
47 BelongsToTable TEXT NOT NULL,
48 BelongsToItem SINGLE NOT NULL,
49 Enabled INTEGER DEFAULT 0,
50 Corrected INTEGER DEFAULT -1
52 Table
.Create(self
, SqlCommand
)
56 # Insert a record into table report
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
66 def Insert(self
, ErrorID
, OtherMsg
='', BelongsToTable
='', BelongsToItem
= -1, Enabled
=0, Corrected
= -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
)
76 # @retval: A recordSet of all found records
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
)
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
)
92 # Get all enabled records from table report and save them to a .csv file
94 # @param Filename: To filename to save the report content
96 def ToCSV(self
, Filename
='Report.csv'):
98 File
= open(Filename
, 'w+')
99 File
.write("""No, Error Code, Error Message, File, LineNo, Other Error Message\n""")
100 RecordSet
= self
.Query()
102 for Record
in RecordSet
:
106 BelongsToTable
= Record
[3]
107 BelongsToItem
= Record
[4]
108 IsCorrected
= Record
[5]
110 if BelongsToTable
== 'File':
111 SqlCommand
= """select 1, FullPath from %s where ID = %s
112 """ % (BelongsToTable
, BelongsToItem
)
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
)
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
))
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
)