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