MiddleArch/middlearch/template.py

23 lines
631 B
Python

import hashlib, logging, os, re
import jinja2 as j2
import os.path as path
import requests as r
def get_hash(name, tag):
regex = re.compile("^source=.+(https://.+\.tar\.[a-z]+)", re.MULTILINE)
with open(f"templates/{name}.j2") as file:
content = file.read()
try:
url = regex.search(content).group(1)
except:
logging.warning(f"cannot find valid source for {name} (is it a git version?)")
return "SKIP"
url = url.replace("${pkgver}", tag)
url = url.replace("${pkgname}", name)
archive = r.get(url)
hash = hashlib.sha256(archive.content).hexdigest()
return hash