Skip to content

Instantly share code, notes, and snippets.

@fosslinux
Last active October 3, 2021 23:41
Show Gist options
  • Select an option

  • Save fosslinux/cd05e1520ade53521c347e5c809926d6 to your computer and use it in GitHub Desktop.

Select an option

Save fosslinux/cd05e1520ade53521c347e5c809926d6 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys
import os
import re
import io
import requests
import json
import io
import html
# Assume infile is the "build number"
builder = sys.argv[1]
number = sys.argv[2]
out = sys.argv[3]
json_raw = requests.get(f"https://build.voidlinux.org/json/builders/{builder}_builder/builds/{number}", stream=True)
json_raw.raw.decode_content = True
json = json.load(io.BytesIO(json_raw.content))
logfile_url = json["logs"][7][1] + "/text"
logfile_raw = requests.get(logfile_url, stream=True)
logfile_raw.raw.decode_content = True
fin = io.StringIO(html.unescape(logfile_raw.content.decode()))
l = fin.readline()
while l:
pkg = l.replace("[xbps-src] ", "").strip()
# Read until next [xbps-src], writing in meantime
try:
os.makedirs(out)
except FileExistsError:
pass
# We do not know the exact output path yet
# Write into a buffer until we do
buf = ""
l = fin.readline()
while not ": building [" in l:
buf += l
l = fin.readline()
# Find remaning information
ver = re.sub(r'=> .*-', '', re.sub(r':.*', '', l)).strip()
arch = re.sub(r'.* ', '', l.replace("...", "").strip())
dirs = os.path.join(out, pkg, ver)
try:
os.makedirs(dirs)
except FileExistsError:
pass
with open(os.path.join(dirs, arch), 'w') as fout:
# Write in the buffer first
fout.write(buf)
while l and not l.startswith("[xbps-src]"):
fout.write(l)
l = fin.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment