]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/InstallPkg.py
BaseTools:Update mailing list address in BaseTools error messages
[mirror_edk2.git] / BaseTools / Source / Python / UPT / InstallPkg.py
index 0e99d2f01f2651ccc1da9ddd37835782eee9d00f..e4c7565441ba1726066fc6c23ca13a01987d945a 100644 (file)
@@ -1,15 +1,9 @@
 ## @file\r
 # Install distribution package.\r
 #\r
-# Copyright (c) 2011 - 2015, 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
-# 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
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 """\r
 Install a distribution package\r
@@ -23,7 +17,7 @@ from os import chmod
 from os import SEEK_SET\r
 from os import SEEK_END\r
 import stat\r
-import md5\r
+from hashlib import md5\r
 import copy\r
 from sys import stdin\r
 from sys import platform\r
@@ -91,7 +85,7 @@ def InstallNewPackage(WorkspaceDir, Path, CustomPath = False):
 # @param PathList:       The already installed standalone module Path list\r
 #\r
 def InstallNewModule(WorkspaceDir, Path, PathList = None):\r
-    if PathList == None:\r
+    if PathList is None:\r
         PathList = []\r
     Path = ConvertPath(Path)\r
     Path = os.path.normpath(Path)\r
@@ -102,7 +96,7 @@ def InstallNewModule(WorkspaceDir, Path, PathList = None):
         Logger.Info(ST.MSG_RELATIVE_PATH_ONLY%FullPath)\r
     else:\r
         return Path\r
-    \r
+\r
     Input = stdin.readline()\r
     Input = Input.replace('\r', '').replace('\n', '')\r
     if Input == '':\r
@@ -110,7 +104,7 @@ def InstallNewModule(WorkspaceDir, Path, PathList = None):
     Input = Input.replace('\r', '').replace('\n', '')\r
     return InstallNewModule(WorkspaceDir, Input, PathList)\r
 \r
-    \r
+\r
 ## InstallNewFile\r
 #\r
 # @param WorkspaceDir:   Workspace Direction\r
@@ -133,19 +127,19 @@ def InstallNewFile(WorkspaceDir, File):
 #\r
 # UnZipDp\r
 #\r
-def UnZipDp(WorkspaceDir, DpPkgFileName):\r
+def UnZipDp(WorkspaceDir, DpPkgFileName, Index=1):\r
     ContentZipFile = None\r
     Logger.Quiet(ST.MSG_UZIP_PARSE_XML)\r
     DistFile = PackageFile(DpPkgFileName)\r
-    \r
+\r
     DpDescFileName, ContentFileName = GetDPFile(DistFile.GetZipFile())\r
-    \r
-    GlobalData.gUNPACK_DIR = os.path.normpath(os.path.join(WorkspaceDir, ".tmp"))\r
-    DistPkgFile = DistFile.UnpackFile(DpDescFileName,\r
-        os.path.normpath(os.path.join(GlobalData.gUNPACK_DIR, DpDescFileName)))\r
+\r
+    TempDir = os.path.normpath(os.path.join(WorkspaceDir, "Conf/.tmp%s" % str(Index)))\r
+    GlobalData.gUNPACK_DIR.append(TempDir)\r
+    DistPkgFile = DistFile.UnpackFile(DpDescFileName, os.path.normpath(os.path.join(TempDir, DpDescFileName)))\r
     if not DistPkgFile:\r
         Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_FILE_BROKEN %DpDescFileName)\r
-    \r
+\r
     #\r
     # Generate distpkg\r
     #\r
@@ -159,33 +153,25 @@ def UnZipDp(WorkspaceDir, DpPkgFileName):
     #\r
     # unzip contents.zip file\r
     #\r
-    ContentFile = DistFile.UnpackFile(ContentFileName,\r
-        os.path.normpath(os.path.join(GlobalData.gUNPACK_DIR, ContentFileName)))\r
+    ContentFile = DistFile.UnpackFile(ContentFileName, os.path.normpath(os.path.join(TempDir, ContentFileName)))\r
     if not ContentFile:\r
         Logger.Error("InstallPkg", FILE_NOT_FOUND,\r
             ST.ERR_FILE_BROKEN % ContentFileName)\r
 \r
-    FilePointer = __FileHookOpen__(ContentFile, "rb")\r
-    #\r
-    # Assume no archive comment.\r
-    #\r
-    FilePointer.seek(0, SEEK_SET)\r
-    FilePointer.seek(0, SEEK_END)\r
     #\r
     # Get file size\r
-    #                \r
-    FileSize = FilePointer.tell()\r
-    FilePointer.close()\r
-               \r
-    if FileSize != 0:        \r
+    #\r
+    FileSize = os.path.getsize(ContentFile)\r
+\r
+    if FileSize != 0:\r
         ContentZipFile = PackageFile(ContentFile)\r
 \r
     #\r
     # verify MD5 signature when existed\r
     #\r
     if DistPkg.Header.Signature != '':\r
-        Md5Sigature = md5.new(__FileHookOpen__(ContentFile, 'rb').read())\r
-        if DistPkg.Header.Signature != Md5Sigature.hexdigest():\r
+        Md5Signature = md5(__FileHookOpen__(ContentFile, 'rb').read())\r
+        if DistPkg.Header.Signature != Md5Signature.hexdigest():\r
             ContentZipFile.Close()\r
             Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE,\r
                 ExtraData=ContentFile)\r
@@ -202,19 +188,19 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleLi
         PackagePath = Path\r
         Package = DistPkg.PackageSurfaceArea[Guid, Version, Path]\r
         Logger.Info(ST.MSG_INSTALL_PACKAGE % Package.GetName())\r
-        if Dep.CheckPackageExists(Guid, Version):\r
-            Logger.Info(ST.WRN_PACKAGE_EXISTED %(Guid, Version))\r
+        if Dep.CheckPackageExists(Guid, Version):\r
+            Logger.Info(ST.WRN_PACKAGE_EXISTED %(Guid, Version))\r
         if Options.UseGuidedPkgPath:\r
             GuidedPkgPath = "%s_%s_%s" % (Package.GetName(), Guid, Version)\r
             NewPackagePath = InstallNewPackage(WorkspaceDir, GuidedPkgPath, Options.CustomPath)\r
         else:\r
             NewPackagePath = InstallNewPackage(WorkspaceDir, PackagePath, Options.CustomPath)\r
-        InstallPackageContent(PackagePath, NewPackagePath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList, \r
+        InstallPackageContent(PackagePath, NewPackagePath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList,\r
                               DistPkg.Header.ReadOnly)\r
         PackageList.append(Package)\r
-        \r
+\r
         NewDict[Guid, Version, Package.GetPackagePath()] = Package\r
-    \r
+\r
     #\r
     # Now generate meta-data files, first generate all dec for package\r
     # dec should be generated before inf, and inf should be generated after\r
@@ -223,11 +209,11 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleLi
     #\r
     for Package in PackageList:\r
         FilePath = PackageToDec(Package, DistPkg.Header)\r
-        Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())\r
-        Md5Sum = Md5Sigature.hexdigest()\r
+        Md5Signature = md5(__FileHookOpen__(str(FilePath), 'rb').read())\r
+        Md5Sum = Md5Signature.hexdigest()\r
         if (FilePath, Md5Sum) not in Package.FileList:\r
             Package.FileList.append((FilePath, Md5Sum))\r
-    \r
+\r
     return NewDict\r
 \r
 ## GetModuleList\r
@@ -237,18 +223,18 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleLi
 def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList):\r
     #\r
     # ModulePathList will keep track of the standalone module path that\r
-    # we just installed. If a new module's path in that list \r
-    # (only multiple INF in one directory will be so), we will \r
-    # install them directly. If not, we will try to create a new directory \r
+    # we just installed. If a new module's path in that list\r
+    # (only multiple INF in one directory will be so), we will\r
+    # install them directly. If not, we will try to create a new directory\r
     # for it.\r
     #\r
     ModulePathList = []\r
-    \r
+\r
     #\r
     # Check module exist and install\r
     #\r
     Module = None\r
-    NewDict = Sdict()        \r
+    NewDict = Sdict()\r
     for Guid, Version, Name, Path in DistPkg.ModuleSurfaceArea:\r
         ModulePath = Path\r
         Module = DistPkg.ModuleSurfaceArea[Guid, Version, Name, Path]\r
@@ -267,14 +253,14 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList):
             ModulePathList.append(NewModuleFullPath)\r
         else:\r
             NewModulePath = ModulePath\r
-        \r
-        InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None, \r
+\r
+        InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None,\r
                              DistPkg.Header.ReadOnly)\r
         #\r
         # Update module\r
         #\r
         Module.SetModulePath(Module.GetModulePath().replace(Path, NewModulePath, 1))\r
-        \r
+\r
         NewDict[Guid, Version, Name, Module.GetModulePath()] = Module\r
 \r
     #\r
@@ -283,8 +269,8 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList):
     for (Module, Package) in ModuleList:\r
         CheckCNameInModuleRedefined(Module, DistPkg)\r
         FilePath = ModuleToInf(Module, Package, DistPkg.Header)\r
-        Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())\r
-        Md5Sum = Md5Sigature.hexdigest()\r
+        Md5Signature = md5(__FileHookOpen__(str(FilePath), 'rb').read())\r
+        Md5Sum = Md5Signature.hexdigest()\r
         if Package:\r
             if (FilePath, Md5Sum) not in Package.FileList:\r
                 Package.FileList.append((FilePath, Md5Sum))\r
@@ -297,7 +283,7 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList):
         for (FilePath, Md5Sum) in Module.FileList:\r
             if str(FilePath).endswith('.uni') and Package and (FilePath, Md5Sum) not in Package.FileList:\r
                 Package.FileList.append((FilePath, Md5Sum))\r
-    \r
+\r
     return NewDict\r
 \r
 ##\r
@@ -311,7 +297,7 @@ def GetDepProtocolPpiGuidPcdNames(DePackageObjList):
     DependentPpiCNames = []\r
     DependentGuidCNames = []\r
     DependentPcdNames = []\r
-    \r
+\r
     for PackageObj in DePackageObjList:\r
         #\r
         # Get protocol CName list from all dependent DEC file\r
@@ -320,29 +306,29 @@ def GetDepProtocolPpiGuidPcdNames(DePackageObjList):
         for Protocol in PackageObj.GetProtocolList():\r
             if Protocol.GetCName() not in ProtocolCNames:\r
                 ProtocolCNames.append(Protocol.GetCName())\r
-  \r
+\r
         DependentProtocolCNames.append(ProtocolCNames)\r
-            \r
+\r
         #\r
         # Get Ppi CName list from all dependent DEC file\r
-        #            \r
+        #\r
         PpiCNames = []\r
         for Ppi in PackageObj.GetPpiList():\r
             if Ppi.GetCName() not in PpiCNames:\r
                 PpiCNames.append(Ppi.GetCName())\r
 \r
         DependentPpiCNames.append(PpiCNames)\r
-            \r
+\r
         #\r
         # Get Guid CName list from all dependent DEC file\r
-        #      \r
+        #\r
         GuidCNames = []\r
         for Guid in PackageObj.GetGuidList():\r
             if Guid.GetCName() not in GuidCNames:\r
                 GuidCNames.append(Guid.GetCName())\r
-        \r
+\r
         DependentGuidCNames.append(GuidCNames)\r
-        \r
+\r
         #\r
         # Get PcdName list from all dependent DEC file\r
         #\r
@@ -351,10 +337,10 @@ def GetDepProtocolPpiGuidPcdNames(DePackageObjList):
             PcdName = '.'.join([Pcd.GetTokenSpaceGuidCName(), Pcd.GetCName()])\r
             if PcdName not in PcdNames:\r
                 PcdNames.append(PcdName)\r
-        \r
+\r
         DependentPcdNames.append(PcdNames)\r
-                \r
-            \r
+\r
+\r
     return DependentProtocolCNames, DependentPpiCNames, DependentGuidCNames, DependentPcdNames\r
 \r
 ##\r
@@ -366,8 +352,8 @@ def CheckProtoclCNameRedefined(Module, DependentProtocolCNames):
         for PackageProtocolCNames in DependentProtocolCNames:\r
             if ProtocolInModule.GetCName() in PackageProtocolCNames:\r
                 if IsCNameDefined:\r
-                    Logger.Error("\nUPT", FORMAT_INVALID, \r
-                                 File = Module.GetFullPath(), \r
+                    Logger.Error("\nUPT", FORMAT_INVALID,\r
+                                 File = Module.GetFullPath(),\r
                                  ExtraData = \\r
                                  ST.ERR_INF_PARSER_ITEM_DUPLICATE_IN_DEC % ProtocolInModule.GetCName())\r
                 else:\r
@@ -382,11 +368,11 @@ def CheckPpiCNameRedefined(Module, DependentPpiCNames):
         for PackagePpiCNames in DependentPpiCNames:\r
             if PpiInModule.GetCName() in PackagePpiCNames:\r
                 if IsCNameDefined:\r
-                    Logger.Error("\nUPT", FORMAT_INVALID, \r
-                                 File = Module.GetFullPath(), \r
+                    Logger.Error("\nUPT", FORMAT_INVALID,\r
+                                 File = Module.GetFullPath(),\r
                                  ExtraData = ST.ERR_INF_PARSER_ITEM_DUPLICATE_IN_DEC % PpiInModule.GetCName())\r
                 else:\r
-                    IsCNameDefined = True    \r
+                    IsCNameDefined = True\r
 \r
 ##\r
 # Check if Guid CName is redefined\r
@@ -397,8 +383,8 @@ def CheckGuidCNameRedefined(Module, DependentGuidCNames):
         for PackageGuidCNames in DependentGuidCNames:\r
             if GuidInModule.GetCName() in PackageGuidCNames:\r
                 if IsCNameDefined:\r
-                    Logger.Error("\nUPT", FORMAT_INVALID, \r
-                                 File = Module.GetFullPath(), \r
+                    Logger.Error("\nUPT", FORMAT_INVALID,\r
+                                 File = Module.GetFullPath(),\r
                                  ExtraData = \\r
                                  ST.ERR_INF_PARSER_ITEM_DUPLICATE_IN_DEC % GuidInModule.GetCName())\r
                 else:\r
@@ -422,8 +408,8 @@ def CheckPcdNameRedefined(Module, DependentPcdNames):
         for PcdNames in DependentPcdNames:\r
             if PcdName in PcdNames:\r
                 if IsPcdNameDefined:\r
-                    Logger.Error("\nUPT", FORMAT_INVALID, \r
-                                 File = Module.GetFullPath(), \r
+                    Logger.Error("\nUPT", FORMAT_INVALID,\r
+                                 File = Module.GetFullPath(),\r
                                  ExtraData = ST.ERR_INF_PARSER_ITEM_DUPLICATE_IN_DEC % PcdName)\r
                 else:\r
                     IsPcdNameDefined = True\r
@@ -435,7 +421,7 @@ def CheckCNameInModuleRedefined(Module, DistPkg):
     DePackageObjList = []\r
     #\r
     # Get all dependent package objects\r
-    # \r
+    #\r
     for Obj in Module.GetPackageDependencyList():\r
         Guid = Obj.GetGuid()\r
         Version = Obj.GetVersion()\r
@@ -443,7 +429,7 @@ def CheckCNameInModuleRedefined(Module, DistPkg):
             if Key[0] == Guid and Key[1] == Version:\r
                 if DistPkg.PackageSurfaceArea[Key] not in DePackageObjList:\r
                     DePackageObjList.append(DistPkg.PackageSurfaceArea[Key])\r
-    \r
+\r
     DependentProtocolCNames, DependentPpiCNames, DependentGuidCNames, DependentPcdNames = \\r
     GetDepProtocolPpiGuidPcdNames(DePackageObjList)\r
 \r
@@ -465,7 +451,7 @@ def GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile):
     ToolFileNum = 0\r
     FileNum = 0\r
     RootDir = WorkspaceDir\r
-    \r
+\r
     #\r
     # FileList stores both tools files and misc files\r
     # Misc file list must be appended to FileList *AFTER* Tools file list\r
@@ -509,70 +495,81 @@ def GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile):
 # @param  Options: command Options\r
 #\r
 def Main(Options = None):\r
-    ContentZipFile, DistFile = None, None\r
-\r
     try:\r
         DataBase = GlobalData.gDB\r
         WorkspaceDir = GlobalData.gWORKSPACE\r
         if not Options.PackageFile:\r
             Logger.Error("InstallPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE)\r
-        \r
-        #\r
-        # unzip dist.pkg file\r
-        #\r
-        DistPkg, ContentZipFile, DpPkgFileName, DistFile = UnZipDp(WorkspaceDir, Options.PackageFile)\r
 \r
-        #\r
-        # check dependency\r
-        #\r
-        Dep = DependencyRules(DataBase)\r
-        CheckInstallDpx(Dep, DistPkg)\r
+        # Get all Dist Info\r
+        DistInfoList = []\r
+        DistPkgList = []\r
+        Index = 1\r
+        for ToBeInstalledDist in Options.PackageFile:\r
+            #\r
+            # unzip dist.pkg file\r
+            #\r
+            DistInfoList.append(UnZipDp(WorkspaceDir, ToBeInstalledDist, Index))\r
+            DistPkgList.append(DistInfoList[-1][0])\r
+            Index += 1\r
 \r
-        #\r
-        # Install distribution\r
-        #\r
-        InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase)\r
+            #\r
+            # Add dist\r
+            #\r
+            GlobalData.gTO_BE_INSTALLED_DIST_LIST.append(DistInfoList[-1][0])\r
+\r
+        # Check for dependency\r
+        Dep = DependencyRules(DataBase, DistPkgList)\r
+\r
+        for ToBeInstalledDist in DistInfoList:\r
+            CheckInstallDpx(Dep, ToBeInstalledDist[0], ToBeInstalledDist[2])\r
+\r
+            #\r
+            # Install distribution\r
+            #\r
+            InstallDp(ToBeInstalledDist[0], ToBeInstalledDist[2], ToBeInstalledDist[1],\r
+                      Options, Dep, WorkspaceDir, DataBase)\r
         ReturnCode = 0\r
-        \r
-    except FatalError, XExcept:\r
+\r
+    except FatalError as XExcept:\r
         ReturnCode = XExcept.args[0]\r
         if Logger.GetLevel() <= Logger.DEBUG_9:\r
             Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
-            \r
+\r
     except KeyboardInterrupt:\r
         ReturnCode = ABORT_ERROR\r
         if Logger.GetLevel() <= Logger.DEBUG_9:\r
             Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
-            \r
+\r
     except:\r
         ReturnCode = CODE_ERROR\r
         Logger.Error(\r
                     "\nInstallPkg",\r
                     CODE_ERROR,\r
                     ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.PackageFile,\r
-                    ExtraData=ST.MSG_SEARCH_FOR_HELP,\r
+                    ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR,\r
                     RaiseError=False\r
                     )\r
         Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(),\r
             platform) + format_exc())\r
     finally:\r
-        if ReturnCode != UPT_ALREADY_INSTALLED_ERROR:\r
-            Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)\r
-            if DistFile:\r
-                DistFile.Close()\r
-            if ContentZipFile:\r
-                ContentZipFile.Close()\r
-            if GlobalData.gUNPACK_DIR:\r
-                rmtree(GlobalData.gUNPACK_DIR)\r
-                GlobalData.gUNPACK_DIR = None\r
-            Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)\r
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)\r
+        for ToBeInstalledDist in DistInfoList:\r
+            if ToBeInstalledDist[3]:\r
+                ToBeInstalledDist[3].Close()\r
+            if ToBeInstalledDist[1]:\r
+                ToBeInstalledDist[1].Close()\r
+        for TempDir in GlobalData.gUNPACK_DIR:\r
+            rmtree(TempDir)\r
+        GlobalData.gUNPACK_DIR = []\r
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)\r
     if ReturnCode == 0:\r
         Logger.Quiet(ST.MSG_FINISH)\r
     return ReturnCode\r
 \r
 # BackupDist method\r
-#  \r
-# This method will backup the Distribution file into the $(WORKSPACE)/conf/upt, and rename it \r
+#\r
+# This method will backup the Distribution file into the $(WORKSPACE)/conf/upt, and rename it\r
 # if there is already a same-named distribution existed.\r
 #\r
 # @param DpPkgFileName: The distribution path\r
@@ -609,14 +606,15 @@ def BackupDist(DpPkgFileName, Guid, Version, WorkspaceDir):
 #   @param  Dep: the DependencyRules instance that used to check dependency\r
 #   @param  DistPkg: the distribution object\r
 #\r
-def CheckInstallDpx(Dep, DistPkg):\r
+def CheckInstallDpx(Dep, DistPkg, DistPkgFileName):\r
     #\r
     # Check distribution package installed or not\r
     #\r
     if Dep.CheckDpExists(DistPkg.Header.GetGuid(),\r
         DistPkg.Header.GetVersion()):\r
-        Logger.Error("InstallPkg", UPT_ALREADY_INSTALLED_ERROR,\r
-            ST.WRN_DIST_PKG_INSTALLED)\r
+        Logger.Error("InstallPkg",\r
+                     UPT_ALREADY_INSTALLED_ERROR,\r
+                     ST.WRN_DIST_PKG_INSTALLED % os.path.basename(DistPkgFileName))\r
     #\r
     # Check distribution dependency (all module dependency should be\r
     # satisfied)\r
@@ -641,19 +639,19 @@ def CheckInstallDpx(Dep, DistPkg):
 #\r
 def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile,\r
     WorkspaceDir, ModuleList, Package = None, ReadOnly = False):\r
-    \r
+\r
     if NewPath.startswith("\\") or NewPath.startswith("/"):\r
         NewPath = NewPath[1:]\r
-    \r
+\r
     if not IsValidInstallPath(NewPath):\r
-        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%NewPath) \r
-           \r
+        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%NewPath)\r
+\r
     NewModuleFullPath = os.path.normpath(os.path.join(WorkspaceDir, NewPath,\r
         ConvertPath(ModulePath)))\r
     Module.SetFullPath(os.path.normpath(os.path.join(NewModuleFullPath,\r
         ConvertPath(Module.GetName()) + '.inf')))\r
     Module.FileList = []\r
-    \r
+\r
     for MiscFile in Module.GetMiscFileList():\r
         if not MiscFile:\r
             continue\r
@@ -661,12 +659,12 @@ def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile,
             File = Item.GetURI()\r
             if File.startswith("\\") or File.startswith("/"):\r
                 File = File[1:]\r
-            \r
+\r
             if not IsValidInstallPath(File):\r
                 Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File)\r
 \r
             FromFile = os.path.join(FromPath, ModulePath, File)\r
-            Executable = Item.GetExecutable()            \r
+            Executable = Item.GetExecutable()\r
             ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File)))\r
             Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable)\r
             if Package and ((ToFile, Md5Sum) not in Package.FileList):\r
@@ -679,10 +677,10 @@ def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile,
         File = Item.GetSourceFile()\r
         if File.startswith("\\") or File.startswith("/"):\r
             File = File[1:]\r
-            \r
+\r
         if not IsValidInstallPath(File):\r
-            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File) \r
-                               \r
+            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File)\r
+\r
         FromFile = os.path.join(FromPath, ModulePath, File)\r
         ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File)))\r
         Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly)\r
@@ -694,24 +692,24 @@ def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile,
             Module.FileList.append((ToFile, Md5Sum))\r
     for Item in Module.GetBinaryFileList():\r
         FileNameList = Item.GetFileNameList()\r
-        for FileName in FileNameList:              \r
-            File = FileName.GetFilename()          \r
+        for FileName in FileNameList:\r
+            File = FileName.GetFilename()\r
             if File.startswith("\\") or File.startswith("/"):\r
                 File = File[1:]\r
-                \r
+\r
             if not IsValidInstallPath(File):\r
                 Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%File)\r
 \r
             FromFile = os.path.join(FromPath, ModulePath, File)\r
             ToFile = os.path.normpath(os.path.join(NewModuleFullPath, ConvertPath(File)))\r
-            Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly)       \r
+            Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly)\r
             if Package and ((ToFile, Md5Sum) not in Package.FileList):\r
                 Package.FileList.append((ToFile, Md5Sum))\r
             elif Package:\r
                 continue\r
             elif (ToFile, Md5Sum) not in Module.FileList:\r
                 Module.FileList.append((ToFile, Md5Sum))\r
-    \r
+\r
     InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly,\r
                                 ModuleList)\r
 \r
@@ -722,7 +720,7 @@ def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile,
 def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly,\r
                                 ModuleList):\r
     #\r
-    # Extract other files under current module path in content Zip file but not listed in the description \r
+    # Extract other files under current module path in content Zip file but not listed in the description\r
     #\r
     if ContentZipFile:\r
         for FileName in ContentZipFile.GetZipFile().namelist():\r
@@ -731,12 +729,12 @@ def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceD
             if FileUnderPath(FileName, CheckPath):\r
                 if FileName.startswith("\\") or FileName.startswith("/"):\r
                     FileName = FileName[1:]\r
-                    \r
+\r
                 if not IsValidInstallPath(FileName):\r
                     Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName)\r
-                                                   \r
+\r
                 FromFile = FileName\r
-                ToFile = os.path.normpath(os.path.join(WorkspaceDir, \r
+                ToFile = os.path.normpath(os.path.join(WorkspaceDir,\r
                         ConvertPath(FileName.replace(FromPath, NewPath, 1))))\r
                 CheckList = copy.copy(Module.FileList)\r
                 if Package:\r
@@ -751,16 +749,16 @@ def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceD
                     elif Package:\r
                         continue\r
                     elif (ToFile, Md5Sum) not in Module.FileList:\r
-                        Module.FileList.append((ToFile, Md5Sum))            \r
-    \r
+                        Module.FileList.append((ToFile, Md5Sum))\r
+\r
     ModuleList.append((Module, Package))\r
 \r
 ## FileUnderPath\r
-#  Check whether FileName started with directory specified by CheckPath \r
+#  Check whether FileName started with directory specified by CheckPath\r
 #\r
 # @param FileName: the FileName need to be checked\r
 # @param CheckPath: the path need to be checked against\r
-# @return:  True or False  \r
+# @return:  True or False\r
 #\r
 def FileUnderPath(FileName, CheckPath):\r
     FileName = FileName.replace('\\', '/')\r
@@ -773,13 +771,13 @@ def FileUnderPath(FileName, CheckPath):
             RemainingPath = RemainingPath[1:]\r
         if FileName == os.path.normpath(os.path.join(CheckPath, RemainingPath)):\r
             return True\r
-    \r
+\r
     return False\r
 \r
 ## InstallFile\r
 #  Extract File from Zipfile, set file attribute, and return the Md5Sum\r
 #\r
-# @return:  True or False  \r
+# @return:  True or False\r
 #\r
 def InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable=False):\r
     if os.path.exists(os.path.normpath(ToFile)):\r
@@ -798,9 +796,9 @@ def InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable=False):
                   stat.S_IWOTH | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)\r
         else:\r
             chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)\r
-                \r
-    Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())\r
-    Md5Sum = Md5Sigature.hexdigest()\r
+\r
+    Md5Signature = md5(__FileHookOpen__(str(ToFile), 'rb').read())\r
+    Md5Sum = Md5Signature.hexdigest()\r
 \r
     return Md5Sum\r
 \r
@@ -819,44 +817,44 @@ def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep,
     if Dep:\r
         pass\r
     Package.FileList = []\r
-    \r
+\r
     if ToPath.startswith("\\") or ToPath.startswith("/"):\r
         ToPath = ToPath[1:]\r
-    \r
+\r
     if not IsValidInstallPath(ToPath):\r
-        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%ToPath)     \r
+        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%ToPath)\r
 \r
     if FromPath.startswith("\\") or FromPath.startswith("/"):\r
         FromPath = FromPath[1:]\r
-    \r
+\r
     if not IsValidInstallPath(FromPath):\r
-        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FromPath)   \r
-    \r
+        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FromPath)\r
+\r
     PackageFullPath = os.path.normpath(os.path.join(WorkspaceDir, ToPath))\r
     for MiscFile in Package.GetMiscFileList():\r
         for Item in MiscFile.GetFileList():\r
             FileName = Item.GetURI()\r
             if FileName.startswith("\\") or FileName.startswith("/"):\r
                 FileName = FileName[1:]\r
-                \r
+\r
             if not IsValidInstallPath(FileName):\r
                 Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName)\r
-                            \r
+\r
             FromFile = os.path.join(FromPath, FileName)\r
             Executable = Item.GetExecutable()\r
             ToFile =  (os.path.join(PackageFullPath, ConvertPath(FileName)))\r
             Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable)\r
             if (ToFile, Md5Sum) not in Package.FileList:\r
                 Package.FileList.append((ToFile, Md5Sum))\r
-    PackageIncludeArchList = [] \r
+    PackageIncludeArchList = []\r
     for Item in Package.GetPackageIncludeFileList():\r
         FileName = Item.GetFilePath()\r
         if FileName.startswith("\\") or FileName.startswith("/"):\r
             FileName = FileName[1:]\r
-            \r
+\r
         if not IsValidInstallPath(FileName):\r
-            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) \r
-                   \r
+            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName)\r
+\r
         FromFile = os.path.join(FromPath, FileName)\r
         ToFile = os.path.normpath(os.path.join(PackageFullPath, ConvertPath(FileName)))\r
         RetFile = ContentZipFile.UnpackFile(FromFile, ToFile)\r
@@ -871,21 +869,21 @@ def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep,
         if ReadOnly:\r
             chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r
         else:\r
-            chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)            \r
-        Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())\r
-        Md5Sum = Md5Sigature.hexdigest()\r
+            chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)\r
+        Md5Signature = md5(__FileHookOpen__(str(ToFile), 'rb').read())\r
+        Md5Sum = Md5Signature.hexdigest()\r
         if (ToFile, Md5Sum) not in Package.FileList:\r
             Package.FileList.append((ToFile, Md5Sum))\r
     Package.SetIncludeArchList(PackageIncludeArchList)\r
-    \r
+\r
     for Item in Package.GetStandardIncludeFileList():\r
         FileName = Item.GetFilePath()\r
         if FileName.startswith("\\") or FileName.startswith("/"):\r
             FileName = FileName[1:]\r
-            \r
+\r
         if not IsValidInstallPath(FileName):\r
-            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) \r
-                    \r
+            Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName)\r
+\r
         FromFile = os.path.join(FromPath, FileName)\r
         ToFile = os.path.normpath(os.path.join(PackageFullPath, ConvertPath(FileName)))\r
         Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly)\r
@@ -928,7 +926,7 @@ def GetDPFile(ZipFile):
                 continue\r
         else:\r
             continue\r
-        \r
+\r
         Logger.Error("PackagingTool", FILE_TYPE_MISMATCH,\r
             ExtraData=ST.ERR_DIST_FILE_TOOMANY)\r
     if not DescFile or not ContentFile:\r
@@ -947,13 +945,13 @@ def InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir
     #\r
     PackageList = []\r
     ModuleList = []\r
-    DistPkg.PackageSurfaceArea = GetPackageList(DistPkg, Dep, WorkspaceDir, Options, \r
+    DistPkg.PackageSurfaceArea = GetPackageList(DistPkg, Dep, WorkspaceDir, Options,\r
                                                 ContentZipFile, ModuleList, PackageList)\r
 \r
     DistPkg.ModuleSurfaceArea = GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList)\r
-    \r
+\r
     GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile)\r
-    \r
+\r
     #\r
     # copy "Distribution File" to directory $(WORKSPACE)/conf/upt\r
     #\r
@@ -964,6 +962,6 @@ def InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir
     # update database\r
     #\r
     Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE)\r
-    DataBase.AddDPObject(DistPkg, NewDpPkgFileName, DistFileName, \r
+    DataBase.AddDPObject(DistPkg, NewDpPkgFileName, DistFileName,\r
                    DistPkg.Header.RePackage)\r
 \r