Skip to content
Snippets Groups Projects
Commit 04ef4022 authored by Nico's avatar Nico
Browse files

add logging

parent 168d7921
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import os.path ...@@ -10,6 +10,7 @@ import os.path
import re import re
import tempfile import tempfile
import sys import sys
import logging
import subprocess import subprocess
GITLAB_API_BASE = "https://gitlab.freifunk-stuttgart.de/api/v4" GITLAB_API_BASE = "https://gitlab.freifunk-stuttgart.de/api/v4"
...@@ -19,6 +20,7 @@ ap = argparse.ArgumentParser() ...@@ -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", 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("--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("--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() args = ap.parse_args()
def find_version_from_archive(archive_file_list): def find_version_from_archive(archive_file_list):
...@@ -28,30 +30,38 @@ 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_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) version_matches = version_regex.match(filename)
if version_matches: if version_matches:
logging.debug("Found version number {}".format(version_matches.group(2)))
return version_matches.group(2) return version_matches.group(2)
return None return None
def extract_zip(artifact_zipfile): def extract_zip(artifact_zipfile):
logging.debug("Extracting ZIP from FD {}".format(artifact_zipfile))
with zipfile.ZipFile(artifact_zipfile) as artifact_zip: with zipfile.ZipFile(artifact_zipfile) as artifact_zip:
version = find_version_from_archive(artifact_zip.infolist()) version = find_version_from_archive(artifact_zip.infolist())
with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir: with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir:
# Python ZipFile doesn't support symlinks # Python ZipFile doesn't support symlinks
# https://bugs.python.org/issue27318 # https://bugs.python.org/issue27318
logging.debug("Running 'unzip'")
subprocess.check_call(['unzip', artifact_zipfile.name, '-d{}'.format(tempdir)], stdin=artifact_zipfile) subprocess.check_call(['unzip', artifact_zipfile.name, '-d{}'.format(tempdir)], stdin=artifact_zipfile)
outputdir = os.path.join(tempdir, "gluon", "output") outputdir = os.path.join(tempdir, "gluon", "output")
os.rename(outputdir, version) os.rename(outputdir, version)
return version return version
def find_latest_pipeline_id(): def find_latest_pipeline_id():
logging.debug("Finding pipeline ID")
pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID)) pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID))
pipelines_request.raise_for_status() pipelines_request.raise_for_status()
pipelines = pipelines_request.json() pipelines = pipelines_request.json()
for pipeline in pipelines: for pipeline in pipelines:
if pipeline["status"] == "success" and pipeline["ref"].startswith("v"): if pipeline["status"] == "success" and pipeline["ref"].startswith("v"):
logging.debug("Found Pipeline ID: {}".format(pipeline["id"]))
return pipeline["id"] return pipeline["id"]
return None return None
if args.debug:
logging.basicConfig(level=logging.DEBUG)
if args.pipeline_id is None: if args.pipeline_id is None:
pipeline_id = int(find_latest_pipeline_id()) pipeline_id = int(find_latest_pipeline_id())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment