summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2022-03-01 17:36:06 +0000
committerKshitij Sisodia <kshitij.sisodia@arm.com>2022-03-02 15:16:34 +0000
commit6a2ac465896ce6f980f0f3d374d6d401b8acb900 (patch)
tree0ff70002d8cd5c0c36515b06e5c58198695e5877 /scripts
parent6b9adad2bde07764bc0b28ff0a43c72306d5e139 (diff)
downloadml-embedded-evaluation-kit-6a2ac465896ce6f980f0f3d374d6d401b8acb900.tar.gz
MLECO-2881: Using MD5 sum for downloaded resources check.
Removing git as a requirement for the checks performed for downloaded resources. Another minor change is renaming of RTE_components.h to RTE_Components.h as per the convention. Change-Id: If93f80f2f5dfa6a3f143259904c33b3b6d3a6e7c Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/py/check_update_resources_downloaded.py60
1 files changed, 37 insertions, 23 deletions
diff --git a/scripts/py/check_update_resources_downloaded.py b/scripts/py/check_update_resources_downloaded.py
index c016665..44e9bd9 100644
--- a/scripts/py/check_update_resources_downloaded.py
+++ b/scripts/py/check_update_resources_downloaded.py
@@ -15,11 +15,30 @@
# limitations under the License.
import json
import os
-import subprocess
import sys
+import hashlib
from argparse import ArgumentParser
+def get_md5sum_for_file(filepath: str) -> str:
+ """
+ Function to calculate md5sum for contents of a given file.
+
+ Parameters:
+ ----------
+ filepath (string): Path to the required file.
+
+ Returns:
+ -------
+ Hex digest represented as string.
+ """
+ md5_sum = hashlib.md5()
+ with open(filepath, mode='rb') as f:
+ buf = f.read()
+ md5_sum.update(buf)
+ return md5_sum.hexdigest()
+
+
def check_update_resources_downloaded(
resource_downloaded_dir: str, set_up_script_path: str
):
@@ -40,20 +59,25 @@ def check_update_resources_downloaded(
with open(metadata_file_path) as metadata_json:
metadata_dict = json.load(metadata_json)
- set_up_script_hash = metadata_dict["set_up_script_hash"]
- command = f"git log -1 --pretty=tformat:%H {set_up_script_path}"
+ md5_key = 'set_up_script_md5sum'
+ set_up_script_md5sum_metadata = ''
+
+ if md5_key in metadata_dict.keys():
+ set_up_script_md5sum_metadata = metadata_dict["set_up_script_md5sum"]
- proc = subprocess.run(
- command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True
- )
- git_commit_hash = proc.stdout.decode("utf-8").strip("\n")
- proc.check_returncode()
+ set_up_script_md5sum_current = get_md5sum_for_file(set_up_script_path)
- if set_up_script_hash == git_commit_hash:
+ if set_up_script_md5sum_current == set_up_script_md5sum_metadata:
return 0
+
# Return code 1 if the resources need to be refreshed.
+ print('Error: hash mismatch!')
+ print(f'Metadata: {set_up_script_md5sum_metadata}')
+ print(f'Current : {set_up_script_md5sum_current}')
return 1
+
# Return error code 2 if the file doesn't exists.
+ print(f'Error: could not find {metadata_file_path}')
return 2
@@ -75,18 +99,8 @@ if __name__ == "__main__":
if not os.path.isfile(args.setup_script_path):
raise ValueError(f'Invalid script path: {args.setup_script_path}')
- # Check if the repo root directory is a git repository
- root_file_dir = os.path.dirname(os.path.abspath(args.setup_script_path))
- is_git_repo = os.path.exists(os.path.join(root_file_dir, ".git"))
-
- # if we have a git repo then check the resources are downloaded,
- # otherwise it's considered a prerequisite to have run
- # the set_up_default_resources.py
- status = (
- check_update_resources_downloaded(
- args.resource_downloaded_dir, args.setup_script_path
- )
- if is_git_repo
- else 0
- )
+ # Check the resources are downloaded as expected
+ status = check_update_resources_downloaded(
+ args.resource_downloaded_dir,
+ args.setup_script_path)
sys.exit(status)