From nobody Mon Feb 9 17:35:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552068073179197.5432141241556; Fri, 8 Mar 2019 10:01:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4728F2D7E7; Fri, 8 Mar 2019 18:01:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C7671816C; Fri, 8 Mar 2019 18:01:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C86223D38A; Fri, 8 Mar 2019 18:01:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x28I0vRU009696 for ; Fri, 8 Mar 2019 13:00:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id B0B3B1001DFF; Fri, 8 Mar 2019 18:00:57 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 341E41001DDE for ; Fri, 8 Mar 2019 18:00:57 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 19:00:48 +0100 Message-Id: <20190308180050.21764-3-abologna@redhat.com> In-Reply-To: <20190308180050.21764-1-abologna@redhat.com> References: <20190308180050.21764-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [dockerfiles PATCH 2/4] refresh: Add Python implementation X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 08 Mar 2019 18:01:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This behaves mostly like a drop-in replacement for the original shell script, with a few differences: * the script figures out which Dockerfiles should be generated by looking at the contents of the repository rather than by asking lcitool. This makes it possible to skip generation of Dockerfiles that lcitool knows about without having to implement custom filtering logic in the script; * pointing the script to the libvirt-jenkins-ci repository is no longer mandatory, since it implements some very simple detection logic of its own; * the name of the Dockerfile being refreshed is printed on standard output, giving the user some indication that progress is being made. Moving to Python also makes it easier to extend the script, which is something that we'll take advantage of in a second. Signed-off-by: Andrea Bolognani --- refresh | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 refresh diff --git a/refresh b/refresh new file mode 100755 index 0000000..5f7c41c --- /dev/null +++ b/refresh @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 + +# refresh - Refresh Dockerfiles using lcitool +# Copyright (C) 2019 Andrea Bolognani +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +import pathlib +import subprocess +import sys + + +class Error(Exception): + + def __init__(self, message): + super(Error, self).__init__() + self.message =3D message + + +class MoveAlongException(Exception): + pass + + +class Dockerfile: + + PREFIX =3D "buildenv-" + SUFFIX =3D ".Dockerfile" + + def __init__(self, path): + + # Files that don't end with the expected suffix can be safely + # ignores + if not path.suffix =3D=3D Dockerfile.SUFFIX: + raise MoveAlongException() + + # Files that don't follow the expected format should be reported + if not path.stem.startswith(Dockerfile.PREFIX): + raise Error("Invalid name '{}'".format(path.stem)) + + self.path =3D path + self.os =3D path.stem[len(Dockerfile.PREFIX):] + + # Fedora Rawhide is special in that we use it to perform MinGW + # builds, so we need to add the corresponding projects + if self.os =3D=3D "fedora-rawhide": + self.projects =3D "libvirt,libvirt+mingw*" + else: + self.projects =3D "libvirt" + + def refresh(self, lcitool): + + args =3D [ + lcitool, + "dockerfile", + "libvirt-" + self.os, + self.projects, + ] + + rc =3D subprocess.run(args, capture_output=3DTrue) + + if rc.returncode !=3D 0: + raise Error("lcitool failed: {}".format(rc.stderr.decode())) + + with self.path.open('w') as f: + print(rc.stdout.decode().strip(), file=3Df) + + +class Application: + + def __init__(self): + + # Find the directory the script lives in + me =3D pathlib.Path(sys.argv[0]).resolve() + self.here =3D me.parent + + # If an argument has been provided, we're going to consider it as + # the path to a clone of libvirt-jenkins-ci.git; otherwise, we're + # going to assume such a clone exists besides the clone of + # libvirt-dockerfiles.git we're running the script from + if len(sys.argv) >=3D 2: + ci_repo =3D pathlib.Path(sys.argv[1]).resolve() + else: + ci_repo =3D self.here.parent.joinpath("libvirt-jenkins-ci") + + self.lcitool =3D ci_repo.joinpath("guests").joinpath("lcitool") + + if not self.lcitool.exists(): + raise Error("{} does not exist".format(self.lcitool)) + + def run(self): + + for item in self.here.iterdir(): + try: + dockerfile =3D Dockerfile(item) + except MoveAlongException: + continue + + print(item.stem + item.suffix) + dockerfile.refresh(self.lcitool) + + +if __name__ =3D=3D "__main__": + try: + Application().run() + except Error as err: + sys.stderr.write("{}: {}\n".format(sys.argv[0], err.message)) + sys.exit(1) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list