Remove duplicates for md5 and keep only utils.md5
[osm/osmclient.git] / osmclient / common / package_tool.py
index 985a447..abdcd3c 100644 (file)
@@ -16,7 +16,6 @@
 #    under the License.
 
 import glob
-import hashlib
 import logging
 import os
 import shutil
@@ -29,6 +28,7 @@ from osm_im.validation import ValidationException
 from osm_im import im_translation
 from osmclient.common import package_handling as package_handling
 from osmclient.common.exceptions import ClientException
+from osmclient.common import utils
 from .sol004_package import SOL004Package
 from .sol007_package import SOL007Package
 import yaml
@@ -396,13 +396,7 @@ class PackageTool(object):
             for file_item in files:
                 if "checksums.txt" in file_item:
                     continue
-                # from https://www.quickprogrammingtips.com/python/how-to-calculate-md5-hash-of-a-file-in-python.html
-                md5_hash = hashlib.md5()
-                with open(file_item, "rb") as f:
-                    # Read and update hash in chunks of 4K
-                    for byte_block in iter(lambda: f.read(4096), b""):
-                        md5_hash.update(byte_block)
-                    checksum.write("{}\t{}\n".format(md5_hash.hexdigest(), file_item))
+                checksum.write("{}\t{}\n".format(utils.md5(file_item), file_item))
 
     def create_folders(self, folders, package_type):
         """