]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Core/IpiDb.py
BaseTools/UPT: Support Unicode path
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Core / IpiDb.py
index e45acb7d48ab189001fc0db80189b5094e2d8c45..f147963288adcdfc1746cd1d955eb8d5d29ef04d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is for installed package information database operations\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -27,6 +27,7 @@ import Logger.Log as Logger
 from Logger import StringTable as ST\r
 from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR\r
 from Logger.ToolError import UPT_DB_UPDATE_ERROR\r
+import platform as pf\r
 \r
 ## IpiDb\r
 #\r
@@ -39,11 +40,11 @@ from Logger.ToolError import UPT_DB_UPDATE_ERROR
 #\r
 #\r
 class IpiDatabase(object):\r
-    def __init__(self, DbPath):\r
+    def __init__(self, DbPath, Workspace):\r
         Dir = os.path.dirname(DbPath)\r
         if not os.path.isdir(Dir):\r
             os.mkdir(Dir)\r
-        self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r
+        self.Conn = sqlite3.connect(unicode(DbPath), isolation_level='DEFERRED')\r
         self.Conn.execute("PRAGMA page_size=4096")\r
         self.Conn.execute("PRAGMA synchronous=OFF")\r
         self.Cur = self.Conn.cursor()\r
@@ -54,6 +55,7 @@ class IpiDatabase(object):
         self.ModDepexTable = 'ModDepexInfo'\r
         self.DpFileListTable = 'DpFileListInfo'\r
         self.DummyTable = 'Dummy'\r
+        self.Workspace = os.path.normpath(Workspace)\r
 \r
     ## Initialize build database\r
     #\r
@@ -156,6 +158,12 @@ class IpiDatabase(object):
         \r
         Logger.Verbose(ST.MSG_INIT_IPI_FINISH)\r
 \r
+    def RollBack(self):\r
+        self.Conn.rollback()\r
+\r
+    def Commit(self):\r
+        self.Conn.commit()\r
+\r
     ## Add a distribution install information from DpObj\r
     #\r
     # @param DpObj:\r
@@ -222,7 +230,6 @@ class IpiDatabase(object):
             self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \\r
                         NewDpPkgFileName, DpPkgFileName, RePackage)\r
     \r
-            self.Conn.commit()\r
         except sqlite3.IntegrityError, DetailMsg:\r
             Logger.Error("UPT",\r
                          UPT_DB_UPDATE_ERROR,\r
@@ -266,7 +273,13 @@ class IpiDatabase(object):
     # @param Path: A Md5Sum\r
     #\r
     def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):\r
-        \r
+        Path = os.path.normpath(Path)\r
+        if pf.system() == 'Windows':\r
+            if Path.startswith(self.Workspace):\r
+                Path = Path[len(self.Workspace):]\r
+        else:\r
+            if Path.startswith(self.Workspace + os.sep):\r
+                Path = Path[len(self.Workspace)+1:]\r
         SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \\r
         (self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)\r
 \r
@@ -320,6 +333,11 @@ class IpiDatabase(object):
         \r
         if PkgVersion == None or len(PkgVersion.strip()) == 0:\r
             PkgVersion = 'N/A'\r
+            \r
+        if os.name == 'posix':\r
+            Path = Path.replace('\\', os.sep)\r
+        else:\r
+            Path = Path.replace('/', os.sep)\r
         \r
         #\r
         # Add module from package information to DB.\r
@@ -378,6 +396,11 @@ class IpiDatabase(object):
         \r
         if DepexVersion == None or len(DepexVersion.strip()) == 0:\r
             DepexVersion = 'N/A'\r
+            \r
+        if os.name == 'posix':\r
+            Path = Path.replace('\\', os.sep)\r
+        else:\r
+            Path = Path.replace('/', os.sep)\r
         \r
         #\r
         # Add module depex information to DB.\r
@@ -478,7 +501,7 @@ class IpiDatabase(object):
         (self.DpTable, DpGuid, DpVersion)\r
         self.Cur.execute(SqlCommand)\r
         \r
-        self.Conn.commit()\r
+        #self.Conn.commit()\r
         \r
     ## Get a list of distribution install information.\r
     #\r
@@ -554,7 +577,7 @@ class IpiDatabase(object):
         for Result in self.Cur:\r
             Path = Result[0]\r
             Md5Sum = Result[3]\r
-            PathList.append((Path, Md5Sum))\r
+            PathList.append((os.path.join(self.Workspace, Path), Md5Sum))\r
         \r
         return PathList\r
 \r
@@ -591,8 +614,8 @@ class IpiDatabase(object):
     # @param DistributionFile: Distribution File  \r
     #\r
     def GetDpByName(self, DistributionFile):\r
-        SqlCommand = """select * from %s where NewPkgFileName like '%s'""" % \\r
-        (self.DpTable, '%' + DistributionFile)\r
+        SqlCommand = """select * from %s where NewPkgFileName = '%s'""" % \\r
+        (self.DpTable, DistributionFile)\r
         self.Cur.execute(SqlCommand)\r
 \r
         for Result in self.Cur:\r
@@ -824,7 +847,7 @@ class IpiDatabase(object):
         self.Cur.execute(SqlCommand)\r
         for ModuleInfo in self.Cur:\r
             FilePath = ModuleInfo[0]\r
-            ModList.append(FilePath)\r
+            ModList.append(os.path.join(self.Workspace, FilePath))\r
             \r
         return ModList        \r
 \r
@@ -844,7 +867,7 @@ class IpiDatabase(object):
         ModuleVersion = '%s' and InstallPath ='%s'\r
                             """ % (self.ModDepexTable, Guid, Version, Path)\r
         self.Cur.execute(SqlCommand)\r
-        self.Conn.commit()\r
+\r
         \r
         DepexList = []\r
         for DepInfo in self.Cur:\r
@@ -853,7 +876,25 @@ class IpiDatabase(object):
             DepexList.append((DepexGuid, DepexVersion))\r
         \r
         return DepexList\r
-    \r
\r
+    ## Inventory the distribution installed to current workspace\r
+    #\r
+    # Inventory the distribution installed to current workspace\r
+    #   \r
+    def InventoryDistInstalled(self):\r
+        SqlCommand = """select * from %s """ % (self.DpTable)\r
+        self.Cur.execute(SqlCommand)\r
+        \r
+        DpInfoList = []\r
+        for Result in self.Cur:\r
+            DpGuid = Result[0]\r
+            DpVersion = Result[1]\r
+            DpAliasName = Result[3]\r
+            DpFileName = Result[4]            \r
+            DpInfoList.append((DpGuid, DpVersion, DpFileName, DpAliasName))\r
+        \r
+        return DpInfoList     \r
+\r
     ## Close entire database\r
     #\r
     # Close the connection and cursor\r