]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Core/PackageFile.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Core / PackageFile.py
index 5fafd85bffbf5107a721b5c9b1913b9d0242a45e..5eeed2aea7d000ca73f7a140037cfe6239d8e155 100644 (file)
@@ -2,11 +2,11 @@
 #\r
 # PackageFile class represents the zip file of a distribution package.\r
 #\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2018, 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
-# distribution. The full text of the license may be found at \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
+# 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
@@ -51,26 +51,26 @@ class PackageFile:
             self._Files = {}\r
             for Filename in self._ZipFile.namelist():\r
                 self._Files[os.path.normpath(Filename)] = Filename\r
-        except BaseException, Xstr:\r
-            Logger.Error("PackagingTool", FILE_OPEN_FAILURE, \r
+        except BaseException as Xstr:\r
+            Logger.Error("PackagingTool", FILE_OPEN_FAILURE,\r
                             ExtraData="%s (%s)" % (FileName, str(Xstr)))\r
 \r
         BadFile = self._ZipFile.testzip()\r
-        if BadFile != None:\r
-            Logger.Error("PackagingTool", FILE_CHECKSUM_FAILURE, \r
+        if BadFile is not None:\r
+            Logger.Error("PackagingTool", FILE_CHECKSUM_FAILURE,\r
                             ExtraData="[%s] in %s" % (BadFile, FileName))\r
-    \r
+\r
     def GetZipFile(self):\r
         return self._ZipFile\r
-    \r
-    ## Get file name \r
+\r
+    ## Get file name\r
     #\r
     def __str__(self):\r
         return self._FileName\r
-    \r
+\r
     ## Extract the file\r
-    # \r
-    # @param To:  the destination file \r
+    #\r
+    # @param To:  the destination file\r
     #\r
     def Unpack(self, ToDest):\r
         for FileN in self._ZipFile.namelist():\r
@@ -78,11 +78,11 @@ class PackageFile:
             Msg = "%s -> %s" % (FileN, ToFile)\r
             Logger.Info(Msg)\r
             self.Extract(FileN, ToFile)\r
-    \r
+\r
     ## Extract the file\r
-    # \r
-    # @param File:  the extracted file \r
-    # @param ToFile:  the destination file \r
+    #\r
+    # @param File:  the extracted file\r
+    # @param ToFile:  the destination file\r
     #\r
     def UnpackFile(self, File, ToFile):\r
         File = File.replace('\\', '/')\r
@@ -91,13 +91,13 @@ class PackageFile:
             Logger.Info(Msg)\r
             self.Extract(File, ToFile)\r
             return ToFile\r
-        \r
+\r
         return ''\r
-    \r
+\r
     ## Extract the file\r
-    # \r
-    # @param Which:  the source path \r
-    # @param ToDest:  the destination path \r
+    #\r
+    # @param Which:  the source path\r
+    # @param ToDest:  the destination path\r
     #\r
     def Extract(self, Which, ToDest):\r
         Which = os.path.normpath(Which)\r
@@ -106,8 +106,8 @@ class PackageFile:
                             ExtraData="[%s] in %s" % (Which, self._FileName))\r
         try:\r
             FileContent = self._ZipFile.read(self._Files[Which])\r
-        except BaseException, Xstr:\r
-            Logger.Error("PackagingTool", FILE_DECOMPRESS_FAILURE, \r
+        except BaseException as Xstr:\r
+            Logger.Error("PackagingTool", FILE_DECOMPRESS_FAILURE,\r
                             ExtraData="[%s] in %s (%s)" % (Which, \\r
                                                            self._FileName, \\r
                                                            str(Xstr)))\r
@@ -119,20 +119,20 @@ class PackageFile:
                 return\r
             else:\r
                 ToFile = __FileHookOpen__(ToDest, 'wb')\r
-        except BaseException, Xstr:\r
-            Logger.Error("PackagingTool", FILE_OPEN_FAILURE, \r
+        except BaseException as Xstr:\r
+            Logger.Error("PackagingTool", FILE_OPEN_FAILURE,\r
                             ExtraData="%s (%s)" % (ToDest, str(Xstr)))\r
 \r
         try:\r
             ToFile.write(FileContent)\r
             ToFile.close()\r
-        except BaseException, Xstr:\r
-            Logger.Error("PackagingTool", FILE_WRITE_FAILURE, \r
+        except BaseException as Xstr:\r
+            Logger.Error("PackagingTool", FILE_WRITE_FAILURE,\r
                             ExtraData="%s (%s)" % (ToDest, str(Xstr)))\r
 \r
     ## Remove the file\r
-    # \r
-    # @param Files:  the removed files \r
+    #\r
+    # @param Files:  the removed files\r
     #\r
     def Remove(self, Files):\r
         TmpDir = os.path.join(tempfile.gettempdir(), ".packaging")\r
@@ -144,7 +144,7 @@ class PackageFile:
         for SinF in Files:\r
             SinF = os.path.normpath(SinF)\r
             if SinF not in self._Files:\r
-                Logger.Error("PackagingTool", FILE_NOT_FOUND, \r
+                Logger.Error("PackagingTool", FILE_NOT_FOUND,\r
                                 ExtraData="%s is not in %s!" % \\r
                                 (SinF, self._FileName))\r
             self._Files.pop(SinF)\r
@@ -159,12 +159,12 @@ class PackageFile:
         RemoveDirectory(TmpDir, True)\r
 \r
     ## Pack the files under Top directory, the directory shown in the zipFile start from BaseDir,\r
-    # BaseDir should be the parent directory of the Top directory, for example, \r
-    # Pack(Workspace\Dir1, Workspace) will pack files under Dir1, and the path in the zipfile will \r
+    # BaseDir should be the parent directory of the Top directory, for example,\r
+    # Pack(Workspace\Dir1, Workspace) will pack files under Dir1, and the path in the zipfile will\r
     # start from Workspace\r
-    # \r
-    # @param Top:  the top directory \r
-    # @param BaseDir:  the base directory \r
+    #\r
+    # @param Top:  the top directory\r
+    # @param BaseDir:  the base directory\r
     #\r
     def Pack(self, Top, BaseDir):\r
         if not os.path.isdir(Top):\r
@@ -175,14 +175,14 @@ class PackageFile:
         Cwd = os.getcwd()\r
         os.chdir(BaseDir)\r
         RelaDir = Top[Top.upper().find(BaseDir.upper()).\\r
-                      join(len(BaseDir).join(1)):] \r
+                      join(len(BaseDir).join(1)):]\r
 \r
         for Root, Dirs, Files in os.walk(RelaDir):\r
             if 'CVS' in Dirs:\r
                 Dirs.remove('CVS')\r
             if '.svn' in Dirs:\r
                 Dirs.remove('.svn')\r
-            \r
+\r
             for Dir in Dirs:\r
                 if Dir.startswith('.'):\r
                     Dirs.remove(Dir)\r
@@ -200,8 +200,8 @@ class PackageFile:
         os.chdir(Cwd)\r
 \r
     ## Pack the file\r
-    # \r
-    # @param Files:  the files to pack \r
+    #\r
+    # @param Files:  the files to pack\r
     #\r
     def PackFiles(self, Files):\r
         for File in Files:\r
@@ -211,9 +211,9 @@ class PackageFile:
             os.chdir(Cwd)\r
 \r
     ## Pack the file\r
-    # \r
-    # @param File:  the files to pack \r
-    # @param ArcName:  the Arc Name \r
+    #\r
+    # @param File:  the files to pack\r
+    # @param ArcName:  the Arc Name\r
     #\r
     def PackFile(self, File, ArcName=None):\r
         try:\r
@@ -221,33 +221,33 @@ class PackageFile:
             # avoid packing same file multiple times\r
             #\r
             if platform.system() != 'Windows':\r
-                File = File.replace('\\', '/')            \r
+                File = File.replace('\\', '/')\r
             ZipedFilesNameList = self._ZipFile.namelist()\r
             for ZipedFile in ZipedFilesNameList:\r
                 if File == os.path.normpath(ZipedFile):\r
                     return\r
             Logger.Info("packing ..." + File)\r
             self._ZipFile.write(File, ArcName)\r
-        except BaseException, Xstr:\r
+        except BaseException as Xstr:\r
             Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,\r
                             ExtraData="%s (%s)" % (File, str(Xstr)))\r
 \r
     ## Write data to the packed file\r
-    # \r
-    # @param Data:  data to write \r
-    # @param ArcName:  the Arc Name \r
+    #\r
+    # @param Data:  data to write\r
+    # @param ArcName:  the Arc Name\r
     #\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
+        except BaseException as Xstr:\r
             Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,\r
                             ExtraData="%s (%s)" % (ArcName, str(Xstr)))\r
 \r
     ## Close file\r
-    # \r
+    #\r
     #\r
     def Close(self):\r
         self._ZipFile.close()\r