Use from hashlib import md5 instead of import md5
due to md5 deprecated in python3

Cc: Liming Gao <liming....@intel.com>
Cc: Yonghong Zhu <yonghong....@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.f...@intel.com>
---
 BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py |  4 ++--
 BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py |  4 ++--
 BaseTools/Source/Python/UPT/InstallPkg.py             | 12 ++++++------
 BaseTools/Source/Python/UPT/MkPkg.py                  |  4 ++--
 BaseTools/Source/Python/UPT/RmPkg.py                  |  4 ++--
 BaseTools/Source/Python/Workspace/MetaFileParser.py   |  6 +++---
 6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py 
b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
index 0ba07ccebc..e2dd6a02dc 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
@@ -17,11 +17,11 @@
 GenDEC
 '''
 import os
 import stat
 import codecs
-import md5
+from hashlib import md5
 from Core.FileHook import __FileHookOpen__
 from Library.Parsing import GenSection
 from Library.CommentGenerating import GenHeaderCommentSection
 from Library.CommentGenerating import GenGenericCommentF
 from Library.CommentGenerating import GenDecTailComment
@@ -644,11 +644,11 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader 
= '', Encoding=TAB_ENCO
                     Content += PcdErrString
 
     File = codecs.open(ContainerFile, 'w', Encoding)
     File.write(u'\uFEFF' + Content)
     File.stream.close()
-    Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
+    Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
     Md5Sum = Md5Sigature.hexdigest()
     if (ContainerFile, Md5Sum) not in PackageObject.FileList:
         PackageObject.FileList.append((ContainerFile, Md5Sum))
 
     return ContainerFile
diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py 
b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
index b62c705137..c2a240a884 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
@@ -16,11 +16,11 @@
 GenInf
 '''
 import os
 import stat
 import codecs
-import md5
+from hashlib import md5
 from Core.FileHook import __FileHookOpen__
 from Library.StringUtils import GetSplitValueList
 from Library.Parsing import GenSection
 from Library.Parsing import GetWorkspacePackage
 from Library.Parsing import ConvertArchForInstall
@@ -253,11 +253,11 @@ def GenModuleUNIEncodeFile(ModuleObject, 
UniFileHeader='', Encoding=DT.TAB_ENCOD
 
     if not os.path.exists(ContainerFile):
         File = codecs.open(ContainerFile, 'wb', Encoding)
         File.write(u'\uFEFF' + Content)
         File.stream.close()
-    Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
+    Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
     Md5Sum = Md5Sigature.hexdigest()
     if (ContainerFile, Md5Sum) not in ModuleObject.FileList:
         ModuleObject.FileList.append((ContainerFile, Md5Sum))
 
     return ContainerFile
diff --git a/BaseTools/Source/Python/UPT/InstallPkg.py 
b/BaseTools/Source/Python/UPT/InstallPkg.py
index 3573886d5a..c553d707fd 100644
--- a/BaseTools/Source/Python/UPT/InstallPkg.py
+++ b/BaseTools/Source/Python/UPT/InstallPkg.py
@@ -21,11 +21,11 @@ from Core.FileHook import __FileHookOpen__
 import os.path
 from os import chmod
 from os import SEEK_SET
 from os import SEEK_END
 import stat
-import md5
+from hashlib import md5
 import copy
 from sys import stdin
 from sys import platform
 from shutil import rmtree
 from shutil import copyfile
@@ -174,11 +174,11 @@ def UnZipDp(WorkspaceDir, DpPkgFileName, Index=1):
 
     #
     # verify MD5 signature when existed
     #
     if DistPkg.Header.Signature != '':
-        Md5Sigature = md5.new(__FileHookOpen__(ContentFile, 'rb').read())
+        Md5Sigature = md5(__FileHookOpen__(ContentFile, 'rb').read())
         if DistPkg.Header.Signature != Md5Sigature.hexdigest():
             ContentZipFile.Close()
             Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE,
                 ExtraData=ContentFile)
 
@@ -213,11 +213,11 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, 
ContentZipFile, ModuleLi
     # all packages installed, else hard to resolve modules' package
     # dependency (Hard to get the location of the newly installed package)
     #
     for Package in PackageList:
         FilePath = PackageToDec(Package, DistPkg.Header)
-        Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())
+        Md5Sigature = md5(__FileHookOpen__(str(FilePath), 'rb').read())
         Md5Sum = Md5Sigature.hexdigest()
         if (FilePath, Md5Sum) not in Package.FileList:
             Package.FileList.append((FilePath, Md5Sum))
 
     return NewDict
@@ -273,11 +273,11 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, 
ContentZipFile, ModuleList):
     # generate all inf for modules
     #
     for (Module, Package) in ModuleList:
         CheckCNameInModuleRedefined(Module, DistPkg)
         FilePath = ModuleToInf(Module, Package, DistPkg.Header)
-        Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())
+        Md5Sigature = md5(__FileHookOpen__(str(FilePath), 'rb').read())
         Md5Sum = Md5Sigature.hexdigest()
         if Package:
             if (FilePath, Md5Sum) not in Package.FileList:
                 Package.FileList.append((FilePath, Md5Sum))
         else:
@@ -801,11 +801,11 @@ def InstallFile(ContentZipFile, FromFile, ToFile, 
ReadOnly, Executable=False):
             chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | 
stat.S_IWUSR | stat.S_IWGRP |
                   stat.S_IWOTH | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
         else:
             chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | 
stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
 
-    Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())
+    Md5Sigature = md5(__FileHookOpen__(str(ToFile), 'rb').read())
     Md5Sum = Md5Sigature.hexdigest()
 
     return Md5Sum
 
 ## InstallPackageContent method
@@ -874,11 +874,11 @@ def InstallPackageContent(FromPath, ToPath, Package, 
ContentZipFile, Dep,
             continue
         if ReadOnly:
             chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
         else:
             chmod(ToFile, 
stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)
-        Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())
+        Md5Sigature = md5(__FileHookOpen__(str(ToFile), 'rb').read())
         Md5Sum = Md5Sigature.hexdigest()
         if (ToFile, Md5Sum) not in Package.FileList:
             Package.FileList.append((ToFile, Md5Sum))
     Package.SetIncludeArchList(PackageIncludeArchList)
 
diff --git a/BaseTools/Source/Python/UPT/MkPkg.py 
b/BaseTools/Source/Python/UPT/MkPkg.py
index 37942b8ed9..053d115547 100644
--- a/BaseTools/Source/Python/UPT/MkPkg.py
+++ b/BaseTools/Source/Python/UPT/MkPkg.py
@@ -25,11 +25,11 @@ from os import chdir
 import os.path
 from sys import stdin
 from sys import platform
 from traceback import format_exc
 from platform import python_version
-import md5
+from hashlib import md5
 from time import strftime
 from time import localtime
 from uuid import uuid4
 
 from Logger import StringTable as ST
@@ -194,11 +194,11 @@ def Main(Options = None):
         ContentFileClosed = True
 
         #
         # Add Md5Sigature
         #
-        DistPkg.Header.Signature = md5.new(open(str(ContentFile), 
'rb').read()).hexdigest()
+        DistPkg.Header.Signature = md5(open(str(ContentFile), 
'rb').read()).hexdigest()
         #
         # Add current Date
         #
         DistPkg.Header.Date = str(strftime("%Y-%m-%dT%H:%M:%S", localtime()))
 
diff --git a/BaseTools/Source/Python/UPT/RmPkg.py 
b/BaseTools/Source/Python/UPT/RmPkg.py
index 78469dc758..f1d141c736 100644
--- a/BaseTools/Source/Python/UPT/RmPkg.py
+++ b/BaseTools/Source/Python/UPT/RmPkg.py
@@ -21,11 +21,11 @@ RmPkg
 #
 import os.path
 from stat import S_IWUSR
 from traceback import format_exc
 from platform import python_version
-import md5
+from hashlib import md5
 from sys import stdin
 from sys import platform
 
 from Core.DependencyRules import DependencyRules
 from Library import GlobalData
@@ -240,11 +240,11 @@ def RemoveDist(Guid, Version, StoredDistFile, DataBase, 
WorkspaceDir, ForceRemov
                 NewFileList.remove(Path)
             if not ForceRemove:
                 #
                 # check whether modified by users
                 #
-                Md5Sigature = md5.new(open(str(Path), 'rb').read())
+                Md5Sigature = md5(open(str(Path), 'rb').read())
                 if Md5Sum != Md5Sigature.hexdigest():
                     Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path)
                     Input = stdin.readline()
                     Input = Input.replace('\r', '').replace('\n', '')
                     if Input.upper() != 'Y':
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py 
b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 2b1ab40439..7bfe0933a1 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -19,11 +19,11 @@ from __future__ import print_function
 from __future__ import absolute_import
 import Common.LongFilePathOs as os
 import re
 import time
 import copy
-import md5
+from hashlib import md5
 
 import Common.EdkLogger as EdkLogger
 import Common.GlobalData as GlobalData
 
 from CommonDataClass.DataClass import *
@@ -1927,14 +1927,14 @@ class DecParser(MetaFileParser):
                     self._ValueList = None
                     self._include_flag = False
                     return
 
                 if self._include_flag:
-                    self._ValueList[1] = "<HeaderFiles>_" + 
md5.new(self._CurrentLine).hexdigest()
+                    self._ValueList[1] = "<HeaderFiles>_" + 
md5(self._CurrentLine).hexdigest()
                     self._ValueList[2] = self._CurrentLine
                 if self._package_flag and "}" != self._CurrentLine:
-                    self._ValueList[1] = "<Packages>_" + 
md5.new(self._CurrentLine).hexdigest()
+                    self._ValueList[1] = "<Packages>_" + 
md5(self._CurrentLine).hexdigest()
                     self._ValueList[2] = self._CurrentLine
                 if self._CurrentLine == "}":
                     self._package_flag = False
                     self._include_flag = False
                     self._ValueList = None
-- 
2.12.2.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to