scripts: modules: Move blob processing to zephyr_module.py

In preparation for the handling of taint flags in zephyr_module.py, move
blob-processing code from the west command to it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
diff --git a/scripts/west_commands/blobs.py b/scripts/west_commands/blobs.py
index 5336b83..d501416 100644
--- a/scripts/west_commands/blobs.py
+++ b/scripts/west_commands/blobs.py
@@ -3,7 +3,6 @@
 # SPDX-License-Identifier: Apache-2.0
 
 import argparse
-import hashlib
 import os
 from pathlib import Path
 import sys
@@ -79,36 +78,16 @@
 
         return parser
 
-    def get_status(self, path, sha256):
-        if not path.is_file():
-            return 'D'
-        with path.open('rb') as f:
-            m = hashlib.sha256()
-            m.update(f.read())
-            if sha256.lower() == m.hexdigest():
-                return 'A'
-            else:
-                return 'M'
-
     def get_blobs(self, args):
         blobs = []
         modules = args.modules
         for module in zephyr_module.parse_modules(ZEPHYR_BASE, self.manifest):
-            mblobs = module.meta.get('blobs', None)
-            if not mblobs:
-                continue
-
             # Filter by module
             module_name = module.meta.get('name', None)
             if len(modules) and module_name not in modules:
                 continue
 
-            blobs_path = Path(module.project) / zephyr_module.MODULE_BLOBS_PATH
-            for blob in mblobs:
-                blob['module'] = module_name
-                blob['abspath'] = blobs_path / Path(blob['path'])
-                blob['status'] = self.get_status(blob['abspath'], blob['sha256'])
-                blobs.append(blob)
+            blobs += zephyr_module.process_blobs(module.project, module.meta)
 
         return blobs
 
diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py
index be7e127..c8d2e3b 100755
--- a/scripts/zephyr_module.py
+++ b/scripts/zephyr_module.py
@@ -18,6 +18,7 @@
 '''
 
 import argparse
+import hashlib
 import os
 import re
 import subprocess
@@ -131,6 +132,9 @@
 MODULE_YML_PATH = PurePath('zephyr/module.yml')
 # Path to the blobs folder
 MODULE_BLOBS_PATH = PurePath('zephyr/blobs')
+BLOB_PRESENT = 'A'
+BLOB_NOT_PRESENT = 'D'
+BLOB_OUTDATED = 'M'
 
 schema = yaml.safe_load(METADATA_SCHEMA)
 
@@ -225,6 +229,34 @@
     return out_text
 
 
+def get_blob_status(path, sha256):
+    if not path.is_file():
+        return BLOB_NOT_PRESENT
+    with path.open('rb') as f:
+        m = hashlib.sha256()
+        m.update(f.read())
+        if sha256.lower() == m.hexdigest():
+            return BLOB_PRESENT
+        else:
+            return BLOB_OUTDATED
+
+
+def process_blobs(module, meta):
+    blobs = []
+    mblobs = meta.get('blobs', None)
+    if not mblobs:
+        return blobs
+
+    blobs_path = Path(module) / MODULE_BLOBS_PATH
+    for blob in mblobs:
+        blob['module'] = meta.get('name', None)
+        blob['abspath'] = blobs_path / Path(blob['path'])
+        blob['status'] = get_blob_status(blob['abspath'], blob['sha256'])
+        blobs.append(blob)
+
+    return blobs
+
+
 def kconfig_snippet(meta, path, kconfig_file=None):
     name = meta['name']
     name_sanitized = meta['name-sanitized']