]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableFile.py
BaseTools: Use absolute import in Table
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableFile.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase table for files\r
3#\r
f7496d71 4# Copyright (c) 2008 - 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
3d872904 17from __future__ import absolute_import\r
30fdf114 18import Common.EdkLogger as EdkLogger\r
3d872904 19from .Table import Table\r
5a57246e 20from Common.StringUtils import ConvertToSqlString\r
1be2ed90 21import Common.LongFilePathOs as os\r
30fdf114
LG
22from CommonDataClass.DataClass import FileClass\r
23\r
24## TableFile\r
25#\r
26# This class defined a table used for file\r
f7496d71 27#\r
30fdf114
LG
28# @param object: Inherited from object class\r
29#\r
30class TableFile(Table):\r
31 def __init__(self, Cursor):\r
32 Table.__init__(self, Cursor)\r
33 self.Table = 'File'\r
f7496d71 34\r
30fdf114
LG
35 ## Create table\r
36 #\r
37 # Create table File\r
38 #\r
39 # @param ID: ID of a File\r
40 # @param Name: Name of a File\r
41 # @param ExtName: ExtName of a File\r
42 # @param Path: Path of a File\r
43 # @param FullPath: FullPath of a File\r
44 # @param Model: Model of a File\r
45 # @param TimeStamp: TimeStamp of a File\r
46 #\r
47 def Create(self):\r
48 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
49 Name VARCHAR NOT NULL,\r
50 ExtName VARCHAR,\r
51 Path VARCHAR,\r
52 FullPath VARCHAR NOT NULL,\r
53 Model INTEGER DEFAULT 0,\r
54 TimeStamp VARCHAR NOT NULL\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 File\r
61 #\r
62 # @param ID: ID of a File\r
63 # @param Name: Name of a File\r
64 # @param ExtName: ExtName of a File\r
65 # @param Path: Path of a File\r
66 # @param FullPath: FullPath of a File\r
67 # @param Model: Model of a File\r
68 # @param TimeStamp: TimeStamp of a File\r
69 #\r
70 def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp):\r
71 self.ID = self.ID + 1\r
72 (Name, ExtName, Path, FullPath) = ConvertToSqlString((Name, ExtName, Path, FullPath))\r
73 SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \\r
74 % (self.Table, self.ID, Name, ExtName, Path, FullPath, Model, TimeStamp)\r
75 Table.Insert(self, SqlCommand)\r
f7496d71 76\r
30fdf114
LG
77 return self.ID\r
78 ## InsertFile\r
79 #\r
80 # Insert one file to table\r
81 #\r
82 # @param FileFullPath: The full path of the file\r
f7496d71
LG
83 # @param Model: The model of the file\r
84 #\r
30fdf114
LG
85 # @retval FileID: The ID after record is inserted\r
86 #\r
87 def InsertFile(self, FileFullPath, Model):\r
88 (Filepath, Name) = os.path.split(FileFullPath)\r
89 (Root, Ext) = os.path.splitext(FileFullPath)\r
90 TimeStamp = os.stat(FileFullPath)[8]\r
91 File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], [])\r
92 return self.Insert(File.Name, File.ExtName, File.Path, File.FullPath, File.Model, TimeStamp)\r
f7496d71 93\r
d0acc87a
LG
94 ## Get ID of a given file\r
95 #\r
96 # @param FilePath Path of file\r
97 #\r
98 # @retval ID ID value of given file in the table\r
99 #\r
100 def GetFileId(self, File):\r
101 QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, str(File))\r
102 RecordList = self.Exec(QueryScript)\r
103 if len(RecordList) == 0:\r
104 return None\r
105 return RecordList[0][0]\r