36 lines
1001 B
Python
36 lines
1001 B
Python
import hashlib, logging, os, re
|
|
import jinja2 as j2
|
|
import requests as r
|
|
|
|
|
|
env = j2.Environment(
|
|
loader=j2.FileSystemLoader('templates'),
|
|
autoescape=j2.select_autoescape([])
|
|
)
|
|
|
|
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
|
|
|
|
def render_pkgbuild(name, tag):
|
|
template = env.get_template(f"{name}.j2")
|
|
hash = get_hash(name, tag)
|
|
|
|
os.mkdir(f"pkgbuilds/{name}")
|
|
|
|
with open(f"pkgbuilds/{name}/PKGBUILD", "w") as file:
|
|
file.write(template.render(tag=tag, hash=hash, maintainer=MAINTAINER))
|