Browse Source

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>
pull/49638/head
Carles Cufi 3 years ago committed by Carles Cufí
parent
commit
b662bc9093
  1. 23
      scripts/west_commands/blobs.py
  2. 32
      scripts/zephyr_module.py

23
scripts/west_commands/blobs.py

@ -3,7 +3,6 @@ @@ -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 @@ class Blobs(WestCommand): @@ -79,36 +78,16 @@ class Blobs(WestCommand):
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

32
scripts/zephyr_module.py

@ -18,6 +18,7 @@ maintained in modules in addition to what is available in the main Zephyr tree. @@ -18,6 +18,7 @@ maintained in modules in addition to what is available in the main Zephyr tree.
'''
import argparse
import hashlib
import os
import re
import subprocess
@ -131,6 +132,9 @@ mapping: @@ -131,6 +132,9 @@ mapping:
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 @@ def process_settings(module, meta): @@ -225,6 +229,34 @@ def process_settings(module, meta):
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']

Loading…
Cancel
Save