]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file is used to create a database used by ECC tool\r | |
3 | #\r | |
4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
5 | # 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 sqlite3\r | |
18 | import Common.LongFilePathOs as os\r | |
19 | \r | |
20 | import EdkLogger as EdkLogger\r | |
21 | from CommonDataClass.DataClass import *\r | |
22 | from String import *\r | |
23 | from DataType import *\r | |
24 | \r | |
25 | from Table.TableDataModel import TableDataModel\r | |
26 | from Table.TableFile import TableFile\r | |
27 | from Table.TableInf import TableInf\r | |
28 | from Table.TableDec import TableDec\r | |
29 | from Table.TableDsc import TableDsc\r | |
30 | \r | |
31 | ## Database\r | |
32 | #\r | |
33 | # This class defined the build databse\r | |
34 | # During the phase of initialization, the database will create all tables and\r | |
35 | # insert all records of table DataModel\r | |
36 | # \r | |
37 | # @param object: Inherited from object class\r | |
38 | # @param DbPath: A string for the path of the ECC database\r | |
39 | #\r | |
40 | # @var Conn: Connection of the ECC database\r | |
41 | # @var Cur: Cursor of the connection\r | |
42 | # @var TblDataModel: Local instance for TableDataModel\r | |
43 | #\r | |
44 | class Database(object):\r | |
45 | def __init__(self, DbPath):\r | |
46 | if os.path.exists(DbPath):\r | |
47 | os.remove(DbPath)\r | |
48 | self.Conn = sqlite3.connect(DbPath, isolation_level = 'DEFERRED')\r | |
49 | self.Conn.execute("PRAGMA page_size=8192")\r | |
50 | self.Conn.execute("PRAGMA synchronous=OFF")\r | |
51 | self.Cur = self.Conn.cursor()\r | |
52 | self.TblDataModel = TableDataModel(self.Cur)\r | |
53 | self.TblFile = TableFile(self.Cur)\r | |
54 | self.TblInf = TableInf(self.Cur)\r | |
55 | self.TblDec = TableDec(self.Cur)\r | |
56 | self.TblDsc = TableDsc(self.Cur)\r | |
57 | \r | |
58 | ## Initialize build database\r | |
59 | #\r | |
60 | # 1. Delete all old existing tables\r | |
61 | # 2. Create new tables\r | |
62 | # 3. Initialize table DataModel\r | |
63 | #\r | |
64 | def InitDatabase(self):\r | |
65 | EdkLogger.verbose("\nInitialize ECC database started ...")\r | |
66 | #\r | |
67 | # Drop all old existing tables\r | |
68 | #\r | |
69 | # self.TblDataModel.Drop()\r | |
70 | # self.TblDsc.Drop()\r | |
71 | # self.TblFile.Drop()\r | |
72 | \r | |
73 | #\r | |
74 | # Create new tables\r | |
75 | #\r | |
76 | self.TblDataModel.Create()\r | |
77 | self.TblFile.Create()\r | |
78 | self.TblInf.Create()\r | |
79 | self.TblDec.Create()\r | |
80 | self.TblDsc.Create()\r | |
81 | \r | |
82 | #\r | |
83 | # Initialize table DataModel\r | |
84 | #\r | |
85 | self.TblDataModel.InitTable()\r | |
86 | EdkLogger.verbose("Initialize ECC database ... DONE!")\r | |
87 | \r | |
88 | ## Query a table\r | |
89 | #\r | |
90 | # @param Table: The instance of the table to be queried\r | |
91 | #\r | |
92 | def QueryTable(self, Table):\r | |
93 | Table.Query()\r | |
94 | \r | |
95 | ## Close entire database\r | |
96 | #\r | |
97 | # Commit all first \r | |
98 | # Close the connection and cursor\r | |
99 | #\r | |
100 | def Close(self):\r | |
101 | self.Conn.commit()\r | |
102 | self.Cur.close()\r | |
103 | self.Conn.close()\r | |
104 | \r | |
105 | ##\r | |
106 | #\r | |
107 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
108 | # script.\r | |
109 | #\r | |
110 | if __name__ == '__main__':\r | |
111 | EdkLogger.Initialize()\r | |
112 | EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r | |
113 | \r | |
114 | Db = Database(DATABASE_PATH)\r | |
115 | Db.InitDatabase()\r | |
116 | Db.QueryTable(Db.TblDataModel) \r | |
117 | Db.QueryTable(Db.TblFile)\r | |
118 | Db.QueryTable(Db.TblDsc)\r | |
119 | Db.Close()\r | |
120 |