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