Change-Id: I527d099421cd61de7291ade3779d8b81500a7b23
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
# under the License.
import glob
# under the License.
import glob
import logging
import os
import shutil
import logging
import os
import shutil
from osm_im import im_translation
from osmclient.common import package_handling as package_handling
from osmclient.common.exceptions import ClientException
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
from .sol004_package import SOL004Package
from .sol007_package import SOL007Package
import yaml
for file_item in files:
if "checksums.txt" in file_item:
continue
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):
"""
def create_folders(self, folders, package_type):
"""
+ """
+ Checksum generator
+ :param fname: file path
+ :return: checksum string
+ """
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
OSM Repo API handling
"""
import glob
OSM Repo API handling
"""
import glob
import logging
from os import listdir, mkdir, getcwd, remove
from os.path import isfile, isdir, join, abspath
import logging
from os import listdir, mkdir, getcwd, remove
from os.path import isfile, isdir, join, abspath
from osmclient.common.exceptions import ClientException
from osmclient.common.package_tool import PackageTool
from osmclient.sol005.repo import Repo
from osmclient.common.exceptions import ClientException
from osmclient.common.package_tool import PackageTool
from osmclient.sol005.repo import Repo
+from osmclient.common import utils
from packaging import version as versioning
import requests
import yaml
from packaging import version as versioning
import requests
import yaml
+ str(len(glob.glob(destination + "/nst/*/*/metadata.yaml")))
)
+ str(len(glob.glob(destination + "/nst/*/*/metadata.yaml")))
)
- def md5(self, fname):
- """
- Checksum generator
- :param fname: file path
- :return: checksum string
- """
- self._logger.debug("")
- hash_md5 = hashlib.md5()
- with open(fname, "rb") as f:
- for chunk in iter(lambda: f.read(4096), b""):
- hash_md5.update(chunk)
- return hash_md5.hexdigest()
-
def fields_building(self, descriptor_dict, file, package_type):
"""
From an artifact descriptor, obtain the fields required for indexing
def fields_building(self, descriptor_dict, file, package_type):
"""
From an artifact descriptor, obtain the fields required for indexing
path = pt.build(path)
self._logger.debug(f"Directory path {path}")
compressed = True
path = pt.build(path)
self._logger.debug(f"Directory path {path}")
compressed = True
- fields["checksum"] = self.md5(path)
+ fields["checksum"] = utils.md5(path)
self.indexation(destination, path, package_type, fields)
except Exception as e:
self.indexation(destination, path, package_type, fields)
except Exception as e: