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