Remove duplicates for md5 and keep only utils.md5
[osm/osmclient.git] / osmclient / common / package_tool.py
index cf09bac..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
@@ -81,7 +81,7 @@ class PackageTool(object):
         self._logger.debug("")
         # print("location: {}".format(osmclient.__path__))
         file_loader = PackageLoader("osmclient")
-        env = Environment(loader=file_loader)
+        env = Environment(loader=file_loader, autoscape=True)
         if package_type == "ns":
             template = env.get_template("nsd.yaml.j2" if not old else "nsd_old.yaml.j2")
             content = {
@@ -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):
         """
@@ -944,7 +938,7 @@ class PackageTool(object):
 
     def _charms_search_on_osm_im_dict(self, osm_im_dict, desc_type):
         self._logger.debug("")
-        charms_set = []
+        charms_set = set()
         for k1, v1 in osm_im_dict.items():
             for k2, v2 in v1.items():
                 for entry in v2: