From nobody Tue May 13 19:44:59 2025 Delivered-To: importer2@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=patchew-devel-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=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555604519; cv=none; d=zoho.com; s=zohoarc; b=bGa/0I/kp6JwWX7Is8nMu6LWV2jAd96YMiEczqt1VFcLKG5HGfKljlCkIQJg3DwPKWyztj35fLrZDYrmkaxS/ElPZAQSeUfU+mrDgYO0ini8FwExMHzohgUrfvLLOjvz0qVqUW2TyAGM6vUKGcQUBK1z2s+4DzgBWb1vZx618R0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555604519; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=esXftvnr9ks6nAieGNuPhQO+zIFNdFGhYID2DsZicM0=; b=ZxTNiAPI/wAmSqU3TG6+4mSU2QxOgriSYV7TFluPmrGTKIt15ukRfO548TKDDPwl6WxkPomhxKUmkcjiqYY+8iFYKGkWTjy5edtzUVbakflDX1Oj+Mku886Fk9tv0YEZqvJcYpWpNSlLC9P8tbaHS1p0Q2eZ/zhssVvZCpCIGHQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555604519954109.80173670775525; Thu, 18 Apr 2019 09:21:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A94BC88ABB; Thu, 18 Apr 2019 16:21:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D7CD600C1; Thu, 18 Apr 2019 16:21:58 +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 94C05181AC45; Thu, 18 Apr 2019 16:21:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3IGLvp0009197 for ; Thu, 18 Apr 2019 12:21:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55E6E60BF7; Thu, 18 Apr 2019 16:21:57 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id B197760BE5 for ; Thu, 18 Apr 2019 16:21:56 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 18 Apr 2019 18:21:42 +0200 Message-Id: <20190418162146.5695-7-pbonzini@redhat.com> In-Reply-To: <20190418162146.5695-1-pbonzini@redhat.com> References: <20190418162146.5695-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 06/10] mods: refactor extraction of configuration into a dictionary X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Apr 2019 16:21:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Both the email and testing modules have code to extract the configuration from project properties into a dictionary. Generalize that code, using the project_config_schema to drive the conversion, and use it in the git plugin as well This matches the way configuration will be stored in the database when we move away from project properties. In fact, all this nice visitor code will disappear very soon... --- mod.py | 37 ++++++++++++++++++++++++++++++++++++- mods/email.py | 14 +------------- mods/git.py | 28 ++++++++++++++++------------ mods/testing.py | 25 ++++--------------------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/mod.py b/mod.py index 319d4d3..d24e924 100644 --- a/mod.py +++ b/mod.py @@ -53,7 +53,7 @@ class PatchewModule(object): prefix =3D prefix + scm.name + "." def _build_map_items(): r =3D {} - for p, v in project.get_properties().items(): + for p in project.get_properties().keys(): if not p.startswith(prefix): continue name =3D p[len(prefix):] @@ -152,6 +152,41 @@ class PatchewModule(object): tmpl +=3D self._render_template(request, project, TMPL_END) return tmpl =20 + def _get_map_scm(self, project, prop_name, scm): + prefix =3D prop_name + "." + result =3D {} + for p in project.get_properties().keys(): + if not p.startswith(prefix): + continue + name =3D p[len(prefix):] + name =3D name[:name.rfind(".")] + if name in result: + continue + assert scm.item.name =3D=3D '{name}' + value =3D self._get_one(project, prefix + name, scm.item) + result[name] =3D value + return result + + def _get_array_scm(self, project, prop_name, scm): + prefix =3D prop_name + "." + result =3D {} + for i in scm.members: + assert i.name !=3D '{name}' + result[i.name] =3D self._get_one(project, prefix + i.name, i) + return result + + def _get_one(self, project, prop_name, scm): + if type(scm) =3D=3D MapSchema: + return self._get_map_scm(project, prop_name, scm) + elif type(scm) =3D=3D ArraySchema: + return self._get_array_scm(project, prop_name, scm) + else: + return project.get_property(prop_name) + + def get_project_config(self, project): + scm =3D self.project_config_schema + return self._get_one(project, scm.name, scm) + _loaded_modules =3D {} =20 def _module_init_config(cls): diff --git a/mods/email.py b/mods/email.py index 14553f0..58dac57 100644 --- a/mods/email.py +++ b/mods/email.py @@ -191,19 +191,7 @@ Email information is configured in "INI" style: return "<%s@patchew.org>" % uuid.uuid1() =20 def get_notifications(self, project): - ret =3D {} - for k, v in project.get_properties().items(): - if not k.startswith("email.notifications."): - continue - tn =3D k[len("email.notifications."):] - if "." not in tn: - continue - an =3D tn[tn.find(".") + 1:] - tn =3D tn[:tn.find(".")] - ret.setdefault(tn, {}) - ret[tn][an] =3D v - ret[tn]["name"] =3D tn - return ret + return self.get_project_config(project).get("notifications", {}) =20 def on_event(self, event, **params): class EmailCancelled(Exception): diff --git a/mods/git.py b/mods/git.py index 110f261..d459a0b 100644 --- a/mods/git.py +++ b/mods/git.py @@ -98,9 +98,6 @@ class GitModule(PatchewModule): if series.is_complete: self.mark_as_pending_apply(series) =20 - def get_project_config(self, project, what): - return project.get_property("git." + what) - def _is_repo(self, path): if not os.path.isdir(path): return False @@ -116,10 +113,14 @@ class GitModule(PatchewModule): =20 def get_mirror(self, po, request, format): response =3D {} - for key, prop in (("head", "git.head"), - ("pushurl", "git.push_to"), - ("url", "git.public_repo")): - response[key] =3D po.get_property(prop) or None + config =3D self.get_project_config(po) + if "push_to" in config: + response["pushurl"] =3D config["push_to"] + if "public_repo" in config: + response["url"] =3D config["public_repo"] + head =3D po.get_property("git.head") + if head: + response["head"] =3D head return response =20 def rest_project_fields_hook(self, request, fields): @@ -130,7 +131,9 @@ class GitModule(PatchewModule): =20 def get_projects_prepare_hook(self, project, response): response["git.head"] =3D project.get_property("git.head") - response["git.push_to"] =3D project.get_property("git.push_to") + config =3D self.get_project_config(project) + if "push_to" in config: + response["git.push_to"] =3D config["push_to"] =20 def prepare_message_hook(self, request, message, detailed): if not message.is_series_head: @@ -264,9 +267,9 @@ class ApplierGetView(APILoginRequiredView): "properties", "tags"= ]) =20 po =3D m.project - for prop in ["git.push_to", "git.public_repo", "git.url_template"]: - if po.get_property(prop): - response[prop] =3D po.get_property(prop) + config =3D _instance.get_project_config(po) + for k, v in config.items(): + response["git." + k] =3D v base =3D _instance.get_base(m) if base: response["git.repo"] =3D base.data["repo"] @@ -296,7 +299,8 @@ class ApplierReportView(APILoginRequiredView): if url: data['url'] =3D url elif tag: - url_template =3D p.get_property("git.url_template") + config =3D _instance.get_project_config(po) + url_template =3D config.get("url_template") if url_template: data['url'] =3D url_template.replace("%t", tag) if base: diff --git a/mods/testing.py b/mods/testing.py index 9df4ccd..9e41307 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -298,18 +298,7 @@ class TestingModule(PatchewModule): ret =3D {} if isinstance(obj, Message): obj =3D obj.project - for k, v in obj.get_properties().items(): - if not k.startswith("testing.tests."): - continue - tn =3D k[len("testing.tests."):] - if "." not in tn: - continue - an =3D tn[tn.find(".") + 1:] - tn =3D tn[:tn.find(".")] - ret.setdefault(tn, {}) - ret[tn][an] =3D v - ret[tn]["name"] =3D tn - return ret + return self.get_project_config(obj).get("tests", {}) =20 def _build_reset_ops(self, obj): if isinstance(obj, Message): @@ -409,15 +398,8 @@ class TestingModule(PatchewModule): project.extra_ops +=3D self._build_reset_ops(project) =20 def get_capability_probes(self, project): - ret =3D {} - for k, v in project.get_properties().items(): - prefix =3D "testing.requirements." - if not k.startswith(prefix): - continue - name =3D k[len(prefix):] - name =3D name[:name.find(".")] - ret[name] =3D v - return ret + props =3D self.get_project_config(project).get('requirements', {}) + return {k: v['script'] for k, v in props.items()} =20 def get_testing_probes(self, project, request, format): return self.get_capability_probes(project) @@ -494,6 +476,7 @@ class TestingGetView(APILoginRequiredView): if req not in capabilities: break else: + t["name"] =3D tn yield r, t =20 def _find_project_test(self, request, po, tester, capabilities): --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel