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