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