]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Core/PackageFile.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Core / PackageFile.py
index 04c5d4e8d0a8cd5d4822d58a17ae8116cc3dd3e6..ec6f5503eaad39756894c329f87432e763d17475 100644 (file)
@@ -2,7 +2,7 @@
 #\r
 # PackageFile class represents the zip file of a distribution package.\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2014, 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
@@ -36,7 +36,8 @@ import Logger.Log as Logger
 from Logger import StringTable as ST\r
 from Library.Misc import CreateDirectory\r
 from Library.Misc import RemoveDirectory\r
-\r
+from Core.FileHook import __FileHookOpen__\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 \r
 class PackageFile:\r
@@ -55,7 +56,7 @@ class PackageFile:
                             ExtraData="%s (%s)" % (FileName, str(Xstr)))\r
 \r
         BadFile = self._ZipFile.testzip()\r
-        if BadFile != None:\r
+        if BadFile is not None:\r
             Logger.Error("PackagingTool", FILE_CHECKSUM_FAILURE, \r
                             ExtraData="[%s] in %s" % (BadFile, FileName))\r
     \r
@@ -96,7 +97,7 @@ class PackageFile:
     ## Extract the file\r
     # \r
     # @param Which:  the source path \r
-    # @param To:  the destination path \r
+    # @param ToDest:  the destination path \r
     #\r
     def Extract(self, Which, ToDest):\r
         Which = os.path.normpath(Which)\r
@@ -116,7 +117,8 @@ class PackageFile:
                 Logger.Warn("PackagingTool", \\r
                             ST.WRN_FILE_NOT_OVERWRITTEN % ToDest)\r
                 return\r
-            ToFile = open(ToDest, "wb")\r
+            else:\r
+                ToFile = __FileHookOpen__(ToDest, 'wb')\r
         except BaseException, Xstr:\r
             Logger.Error("PackagingTool", FILE_OPEN_FAILURE, \r
                             ExtraData="%s (%s)" % (ToDest, str(Xstr)))\r
@@ -202,8 +204,11 @@ class PackageFile:
     # @param Files:  the files to pack \r
     #\r
     def PackFiles(self, Files):\r
-        for File1 in Files:\r
-            self.PackFile(File1)\r
+        for File in Files:\r
+            Cwd = os.getcwd()\r
+            os.chdir(mws.getWs(mws.WORKSPACE, File))\r
+            self.PackFile(File)\r
+            os.chdir(Cwd)\r
 \r
     ## Pack the file\r
     # \r
@@ -234,6 +239,8 @@ class PackageFile:
     #\r
     def PackData(self, Data, ArcName):\r
         try:\r
+            if os.path.splitext(ArcName)[1].lower() == '.pkg':\r
+                Data = Data.encode('utf_8')\r
             self._ZipFile.writestr(ArcName, Data)\r
         except BaseException, Xstr:\r
             Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,\r