]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableReport.py
BaseTools: Use absolute import in Table
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableReport.py
CommitLineData
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
40d841f6 5# This program and the accompanying materials\r
30fdf114
LG
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
3d872904 17from __future__ import absolute_import\r
30fdf114 18import Common.EdkLogger as EdkLogger\r
1be2ed90 19import Common.LongFilePathOs as os, time\r
3d872904 20from .Table import Table\r
5a57246e 21from Common.StringUtils import ConvertToSqlString2\r
30fdf114
LG
22import EccToolError as EccToolError\r
23import EccGlobalData as EccGlobalData\r
1be2ed90 24from Common.LongFilePathSupport import OpenLongFilePath as open\r
30fdf114
LG
25\r
26## TableReport\r
27#\r
28# This class defined a table used for data model\r
f7496d71 29#\r
30fdf114
LG
30# @param object: Inherited from object class\r
31#\r
32#\r
33class TableReport(Table):\r
34 def __init__(self, Cursor):\r
35 Table.__init__(self, Cursor)\r
36 self.Table = 'Report'\r
f7496d71 37\r
30fdf114
LG
38 ## Create table\r
39 #\r
40 # Create table report\r
41 #\r
42 # @param ID: ID of an Error\r
43 # @param ErrorID: ID of an Error TypeModel of a Report item\r
44 # @param OtherMsg: Other error message besides the standard error message\r
45 # @param BelongsToItem: The error belongs to which item\r
46 # @param Enabled: If this error enabled\r
47 # @param Corrected: if this error corrected\r
48 #\r
49 def Create(self):\r
50 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
51 ErrorID INTEGER NOT NULL,\r
52 OtherMsg TEXT,\r
53 BelongsToTable TEXT NOT NULL,\r
54 BelongsToItem SINGLE NOT NULL,\r
55 Enabled INTEGER DEFAULT 0,\r
56 Corrected INTEGER DEFAULT -1\r
57 )""" % self.Table\r
58 Table.Create(self, SqlCommand)\r
59\r
60 ## Insert table\r
61 #\r
62 # Insert a record into table report\r
63 #\r
64 # @param ID: ID of an Error\r
65 # @param ErrorID: ID of an Error TypeModel of a report item\r
66 # @param OtherMsg: Other error message besides the standard error message\r
67 # @param BelongsToTable: The error item belongs to which table\r
68 # @param BelongsToItem: The error belongs to which item\r
69 # @param Enabled: If this error enabled\r
70 # @param Corrected: if this error corrected\r
71 #\r
47fea6af 72 def Insert(self, ErrorID, OtherMsg='', BelongsToTable='', BelongsToItem= -1, Enabled=0, Corrected= -1):\r
30fdf114
LG
73 self.ID = self.ID + 1\r
74 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', %s, %s, %s)""" \\r
75 % (self.Table, self.ID, ErrorID, ConvertToSqlString2(OtherMsg), BelongsToTable, BelongsToItem, Enabled, Corrected)\r
76 Table.Insert(self, SqlCommand)\r
47fea6af 77\r
30fdf114 78 return self.ID\r
47fea6af 79\r
30fdf114
LG
80 ## Query table\r
81 #\r
f7496d71 82 # @retval: A recordSet of all found records\r
30fdf114
LG
83 #\r
84 def Query(self):\r
85 SqlCommand = """select ID, ErrorID, OtherMsg, BelongsToTable, BelongsToItem, Corrected from %s\r
86 where Enabled > -1 order by ErrorID, BelongsToItem""" % (self.Table)\r
87 return self.Exec(SqlCommand)\r
88\r
1b2467c5
HC
89 ## Update table\r
90 #\r
91 def UpdateBelongsToItemByFile(self, ItemID=-1, File=""):\r
92 SqlCommand = """update Report set BelongsToItem=%s where BelongsToTable='File' and BelongsToItem=-2\r
93 and OtherMsg like '%%%s%%'""" % (ItemID, File)\r
94 return self.Exec(SqlCommand)\r
95\r
30fdf114
LG
96 ## Convert to CSV\r
97 #\r
98 # Get all enabled records from table report and save them to a .csv file\r
99 #\r
100 # @param Filename: To filename to save the report content\r
101 #\r
47fea6af 102 def ToCSV(self, Filename='Report.csv'):\r
30fdf114
LG
103 try:\r
104 File = open(Filename, 'w+')\r
105 File.write("""No, Error Code, Error Message, File, LineNo, Other Error Message\n""")\r
106 RecordSet = self.Query()\r
107 Index = 0\r
108 for Record in RecordSet:\r
109 Index = Index + 1\r
110 ErrorID = Record[1]\r
111 OtherMsg = Record[2]\r
112 BelongsToTable = Record[3]\r
113 BelongsToItem = Record[4]\r
114 IsCorrected = Record[5]\r
115 SqlCommand = ''\r
116 if BelongsToTable == 'File':\r
40d841f6 117 SqlCommand = """select 1, FullPath from %s where ID = %s\r
30fdf114
LG
118 """ % (BelongsToTable, BelongsToItem)\r
119 else:\r
120 SqlCommand = """select A.StartLine, B.FullPath from %s as A, File as B\r
121 where A.ID = %s and B.ID = A.BelongsToFile\r
122 """ % (BelongsToTable, BelongsToItem)\r
123 NewRecord = self.Exec(SqlCommand)\r
124 if NewRecord != []:\r
125 File.write("""%s,%s,"%s",%s,%s,"%s"\n""" % (Index, ErrorID, EccToolError.gEccErrorMessage[ErrorID], NewRecord[0][1], NewRecord[0][0], OtherMsg))\r
52302d4d 126 EdkLogger.quiet("%s(%s): [%s]%s %s" % (NewRecord[0][1], NewRecord[0][0], ErrorID, EccToolError.gEccErrorMessage[ErrorID], OtherMsg))\r
47fea6af 127\r
30fdf114
LG
128 File.close()\r
129 except IOError:\r
130 NewFilename = 'Report_' + time.strftime("%Y%m%d_%H%M%S.csv", time.localtime())\r
131 EdkLogger.warn("ECC", "The report file %s is locked by other progress, use %s instead!" % (Filename, NewFilename))\r
132 self.ToCSV(NewFilename)\r
133\r