Commit 04ef4022 authored by Nico's avatar Nico
Browse files

add logging

parent 168d7921
......@@ -10,6 +10,7 @@ import os.path
import re
import tempfile
import sys
import logging
import subprocess
GITLAB_API_BASE = "https://gitlab.freifunk-stuttgart.de/api/v4"
......@@ -19,6 +20,7 @@ ap = argparse.ArgumentParser()
ap.add_argument("--pipeline-id", help="Pipeline ID to download. If omitted, download latest successfull.", default=None)
ap.add_argument("--pipeline-id-file", help="Store downloaded Pipeline ID in this file and only download if latest pipeline ID doesn't match file contents")
ap.add_argument("--create-symlink", help="Create symlink to downloaded firmware at the specified path")
ap.add_argument("--debug", action="store_true", help="Produce lots of debug output")
args = ap.parse_args()
def find_version_from_archive(archive_file_list):
......@@ -28,30 +30,38 @@ def find_version_from_archive(archive_file_list):
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:
logging.debug("Found version number {}".format(version_matches.group(2)))
return version_matches.group(2)
return None
def extract_zip(artifact_zipfile):
logging.debug("Extracting ZIP from FD {}".format(artifact_zipfile))
with zipfile.ZipFile(artifact_zipfile) as artifact_zip:
version = find_version_from_archive(artifact_zip.infolist())
with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir:
# Python ZipFile doesn't support symlinks
# https://bugs.python.org/issue27318
logging.debug("Running 'unzip'")
subprocess.check_call(['unzip', artifact_zipfile.name, '-d{}'.format(tempdir)], stdin=artifact_zipfile)
outputdir = os.path.join(tempdir, "gluon", "output")
os.rename(outputdir, version)
return version
def find_latest_pipeline_id():
logging.debug("Finding pipeline ID")
pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID))
pipelines_request.raise_for_status()
pipelines = pipelines_request.json()
for pipeline in pipelines:
if pipeline["status"] == "success" and pipeline["ref"].startswith("v"):
logging.debug("Found Pipeline ID: {}".format(pipeline["id"]))
return pipeline["id"]
return None
if args.debug:
logging.basicConfig(level=logging.DEBUG)
if args.pipeline_id is None:
pipeline_id = int(find_latest_pipeline_id())
......
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