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