]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableReport.py
There is a limitation on WINDOWS OS for the length of entire file path can’t be large...
[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
1be2ed90 4# Copyright (c) 2008 - 2014, 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
71 def Insert(self, ErrorID, OtherMsg = '', BelongsToTable = '', BelongsToItem = -1, Enabled = 0, Corrected = -1):\r
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
76 \r
77 return self.ID\r
78 \r
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
88 ## Convert to CSV\r
89 #\r
90 # Get all enabled records from table report and save them to a .csv file\r
91 #\r
92 # @param Filename: To filename to save the report content\r
93 #\r
94 def ToCSV(self, Filename = 'Report.csv'):\r
95 try:\r
96 File = open(Filename, 'w+')\r
97 File.write("""No, Error Code, Error Message, File, LineNo, Other Error Message\n""")\r
98 RecordSet = self.Query()\r
99 Index = 0\r
100 for Record in RecordSet:\r
101 Index = Index + 1\r
102 ErrorID = Record[1]\r
103 OtherMsg = Record[2]\r
104 BelongsToTable = Record[3]\r
105 BelongsToItem = Record[4]\r
106 IsCorrected = Record[5]\r
107 SqlCommand = ''\r
108 if BelongsToTable == 'File':\r
40d841f6 109 SqlCommand = """select 1, FullPath from %s where ID = %s\r
30fdf114
LG
110 """ % (BelongsToTable, BelongsToItem)\r
111 else:\r
112 SqlCommand = """select A.StartLine, B.FullPath from %s as A, File as B\r
113 where A.ID = %s and B.ID = A.BelongsToFile\r
114 """ % (BelongsToTable, BelongsToItem)\r
115 NewRecord = self.Exec(SqlCommand)\r
116 if NewRecord != []:\r
117 File.write("""%s,%s,"%s",%s,%s,"%s"\n""" % (Index, ErrorID, EccToolError.gEccErrorMessage[ErrorID], NewRecord[0][1], NewRecord[0][0], OtherMsg))\r
52302d4d
LG
118 EdkLogger.quiet("%s(%s): [%s]%s %s" % (NewRecord[0][1], NewRecord[0][0], ErrorID, EccToolError.gEccErrorMessage[ErrorID], OtherMsg))\r
119 \r
30fdf114
LG
120 File.close()\r
121 except IOError:\r
122 NewFilename = 'Report_' + time.strftime("%Y%m%d_%H%M%S.csv", time.localtime())\r
123 EdkLogger.warn("ECC", "The report file %s is locked by other progress, use %s instead!" % (Filename, NewFilename))\r
124 self.ToCSV(NewFilename)\r
125\r