Commit 95c9127c authored by Nico's avatar Nico
Browse files

Initial commit

parents
#!/usr/bin/python3
from pprint import pprint
import requests
import zipfile
import tempfile
from io import BytesIO
import argparse
import os.path
import re
import tempfile
GITLAB_API_BASE = "https://gitlab.freifunk-stuttgart.de/api/v4"
PROJECT_ID = 1
ap = argparse.ArgumentParser()
ap.add_argument("--pipeline-id", help="Pipeline ID to download. If omitted, download latest.", default=None)
ap.add_argument("gluonzip")
args = ap.parse_args()
def find_version_from_archive(archive_file_list):
for file in archive_file_list:
if file.filename.startswith("gluon/output/images"):
filename = os.path.basename(file.filename)
version_regex = re.compile(r'gluon-ffs-(([0-9]+\.[0-9]+[+][0-9]{4}-[0-9]{2}-[0-9]{2})-g\.[a-f0-9]+-s\.[a-f0-9]+-)')
version_matches = version_regex.match(filename)
if version_matches:
return version_matches.group(2)
return None
def extract_zip(artifact_zipfile):
with zipfile.ZipFile(artifact_zipfile) as artifact_zip:
version = find_version_from_archive(artifact_zip.infolist())
print(f"Version is {version}")
with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir:
artifact_zip.extractall(tempdir)
outputdir = os.path.join(tempdir, "gluon", "output")
os.rename(outputdir, version)
if args.gluonzip:
extract_zip(args.gluonzip)
sys.exit(0)
if args.pipeline_id is None:
pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID))
pipelines_request.raise_for_status()
pipelines = pipelines_request.json()
pipeline_id = pipelines[0]["id"]
else:
pipeline_id = args.pipeline_id
pipeline_jobs_request = requests.get("{}/projects/{}/pipelines/{}/jobs".format(GITLAB_API_BASE, PROJECT_ID, pipeline_id))
pipeline_jobs_request.raise_for_status()
pipeline_jobs = pipeline_jobs_request.json()
for job in pipeline_jobs:
if job["name"] == "package":
with tempfile.TemporaryFile() as artifact_temp:
with requests.get("{}/projects/{}/jobs/{}/artifacts".format(GITLAB_API_BASE, PROJECT_ID, job["id"]), stream=True) as artifact_request:
artifact_request.raise_for_status()
for chunk in artifact_request.iter_content(chunk_size=1024*1024):
artifact_temp.write(chunk)
with zipfile.ZipFile(artifact_temp) as artifact_zip:
version = find_version_from_archive(artifact_zip.infolist())
print(f"Version is {version}")
artifact_zip.extractall("gluon/output/")
os.rename("gluon/output", version)
os.removedirs("gluon")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment