-
-
Save jamincollins/0ff946d34d3763ca9d7e85c29ba7dff3 to your computer and use it in GitHub Desktop.
update the AUR spotify package based on upstream changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import re | |
import requests | |
import subprocess | |
import sys | |
from pprint import pprint | |
def get_latest_release(): | |
url = "http://repository.spotify.com/dists/testing/non-free/binary-amd64/Packages" | |
resp = requests.get(url) | |
resp.raise_for_status() | |
version = githash = None | |
for line in resp.text.splitlines(): | |
if line.startswith("Version:"): | |
string = line[9:].strip() | |
pattern = r"(?P<epoch>[^:]*):(?P<version>[0-9]*.[0-9]*.[0-9]*.[0-9]*).(?P<githash>.*)" | |
m = re.match(pattern, string) | |
version = m.group("version") | |
githash = m.group("githash") | |
return version, githash | |
def update_pkgbuild(version, githash): | |
updated = [] | |
with open("PKGBUILD", mode="r") as handle: | |
contents = handle.read() | |
for line in contents.splitlines(): | |
if line.startswith("pkgver="): | |
line = f"pkgver={version}" | |
elif line.startswith("_commit="): | |
line = f"_commit={githash}" | |
updated.append(line + "\n") | |
with open("PKGBUILD", mode="w") as handle: | |
handle.writelines(updated) | |
# ensure the sha256sums are updated | |
updpkgsums_cmd = ["updpkgsums"] | |
subprocess.call(updpkgsums_cmd, shell=False) | |
# ensure .SRCINFO is updated | |
makepkg_cmd = ["makepkg", "--printsrcinfo"] | |
with open(".SRCINFO", mode="w") as handle: | |
subprocess.call(makepkg_cmd, stdout=handle, shell=False) | |
def main(): | |
version, githash = get_latest_release() | |
if not version or not githash: | |
raise AssertionError() | |
update_pkgbuild(version, githash) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment