Record sha256sum of other distro source files

If a source points to a local file, get the sha256sum of it and save it
into the field we just added.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-04-01 15:40:05 +13:00
parent 44aa397fbe
commit c32fdd8c9e
2 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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: