]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Table/TableFile.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableFile.py
diff --git a/BaseTools/Source/Python/Table/TableFile.py b/BaseTools/Source/Python/Table/TableFile.py
new file mode 100644 (file)
index 0000000..9be6494
--- /dev/null
@@ -0,0 +1,91 @@
+## @file\r
+# This file is used to create/update/query/erase table for files\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import Common.EdkLogger as EdkLogger\r
+from Table import Table\r
+from Common.String import ConvertToSqlString\r
+import os\r
+from CommonDataClass.DataClass import FileClass\r
+\r
+## TableFile\r
+#\r
+# This class defined a table used for file\r
+# \r
+# @param object:       Inherited from object class\r
+#\r
+class TableFile(Table):\r
+    def __init__(self, Cursor):\r
+        Table.__init__(self, Cursor)\r
+        self.Table = 'File'\r
+    \r
+    ## Create table\r
+    #\r
+    # Create table File\r
+    #\r
+    # @param ID:        ID of a File\r
+    # @param Name:      Name of a File\r
+    # @param ExtName:   ExtName of a File\r
+    # @param Path:      Path of a File\r
+    # @param FullPath:  FullPath of a File\r
+    # @param Model:     Model of a File\r
+    # @param TimeStamp: TimeStamp of a File\r
+    #\r
+    def Create(self):\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+                                                       Name VARCHAR NOT NULL,\r
+                                                       ExtName VARCHAR,\r
+                                                       Path VARCHAR,\r
+                                                       FullPath VARCHAR NOT NULL,\r
+                                                       Model INTEGER DEFAULT 0,\r
+                                                       TimeStamp VARCHAR NOT NULL\r
+                                                      )""" % self.Table\r
+        Table.Create(self, SqlCommand)\r
+\r
+    ## Insert table\r
+    #\r
+    # Insert a record into table File\r
+    #\r
+    # @param ID:        ID of a File\r
+    # @param Name:      Name of a File\r
+    # @param ExtName:   ExtName of a File\r
+    # @param Path:      Path of a File\r
+    # @param FullPath:  FullPath of a File\r
+    # @param Model:     Model of a File\r
+    # @param TimeStamp: TimeStamp of a File\r
+    #\r
+    def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp):\r
+        self.ID = self.ID + 1\r
+        (Name, ExtName, Path, FullPath) = ConvertToSqlString((Name, ExtName, Path, FullPath))\r
+        SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \\r
+                                           % (self.Table, self.ID, Name, ExtName, Path, FullPath, Model, TimeStamp)\r
+        Table.Insert(self, SqlCommand)\r
+        \r
+        return self.ID\r
+    ## InsertFile\r
+    #\r
+    # Insert one file to table\r
+    #\r
+    # @param FileFullPath:  The full path of the file\r
+    # @param Model:         The model of the file \r
+    # \r
+    # @retval FileID:       The ID after record is inserted\r
+    #\r
+    def InsertFile(self, FileFullPath, Model):\r
+        (Filepath, Name) = os.path.split(FileFullPath)\r
+        (Root, Ext) = os.path.splitext(FileFullPath)\r
+        TimeStamp = os.stat(FileFullPath)[8]\r
+        File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], [])\r
+        return self.Insert(File.Name, File.ExtName, File.Path, File.FullPath, File.Model, TimeStamp)\r