diff --git a/layerindex/tools/import_otherdistro.py b/layerindex/tools/import_otherdistro.py index f448b45..e036842 100755 --- a/layerindex/tools/import_otherdistro.py +++ b/layerindex/tools/import_otherdistro.py @@ -292,6 +292,12 @@ def update_recipe_file(path, recipe, repodir, raiseexceptions=False): existing_ids = list(recipe.source_set.values_list('id', flat=True)) for src in sources: srcobj, _ = Source.objects.get_or_create(recipe=recipe, url=src) + if not '://' in src: + sourcepath = os.path.join(os.path.dirname(path), src) + if os.path.exists(sourcepath): + srcobj.sha256sum = utils.sha256_file(sourcepath) + else: + srcobj.sha256sum = '' srcobj.save() if srcobj.id in existing_ids: existing_ids.remove(srcobj.id) diff --git a/layerindex/utils.py b/layerindex/utils.py index 75a0423..e5df54c 100644 --- a/layerindex/utils.py +++ b/layerindex/utils.py @@ -469,6 +469,14 @@ def sanitise_html(html): def squashspaces(string): return re.sub("\s+", " ", string).strip() +def sha256_file(ifn): + import hashlib + shash = hashlib.sha256() + with open(ifn, 'rb') as f: + for line in f: + shash.update(line) + return shash.hexdigest() + def timesince2(date, date2=None): # Based on http://www.didfinishlaunchingwithoptions.com/a-better-timesince-template-filter-for-django/ if date2 is None: