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