From nobody Fri Apr 26 21:35:09 2024 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=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; 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=1556795902; cv=none; d=zoho.com; s=zohoarc; b=W8yp8Wcm8OKBbnWXPdXNjoXyYuvB7bDnIA813BmMjOmkaqtmAuilXeTK0xhCmh+GVYgOQBvUwfb+zxK3Z+ZlzSL4lqJa4+7NqVfSAPFZddXCHnrTCSVWZGPIiUkHvkpAlqy7D7juSmr8KJFmuUgvaKOnxqFojz6FUY9TkAw08Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556795902; 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=wxs07UtSsZMJ5mi/Fu/k1RwbmJo6YITG76D4TKRP6DU=; b=deYlBPOzKemTToFkJB07hC82A9eGTH4AK51swziHvXpShc4yCpfyVP/OrhYZYmckotNFnthIQznBjfVUxgUO/7lOrVV0uIXvYQm0SB98y3HsZC8Qj7SfBdvi6TqMtmGkjuVspnoZn6nlJrxYjCOvXEuWExcr11ak9pNwPH+YrU4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1556795902855414.5119187729838; Thu, 2 May 2019 04:18:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 958EE307D978; Thu, 2 May 2019 11:18:21 +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 87C9BA219; Thu, 2 May 2019 11:18:21 +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 7E04318089D2; Thu, 2 May 2019 11:18:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x42BIJdV009037 for ; Thu, 2 May 2019 07:18:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9AE37EE8B; Thu, 2 May 2019 11:18:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3C2B7EF44 for ; Thu, 2 May 2019 11:18:19 +0000 (UTC) Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 013D130944B6 for ; Thu, 2 May 2019 11:18:12 +0000 (UTC) Received: by mail-ot1-f45.google.com with SMTP id r20so1692313otg.4 for ; Thu, 02 May 2019 04:18:11 -0700 (PDT) Received: from localhost.localdomain ([198.59.53.9]) by smtp.gmail.com with ESMTPSA id o1sm19095697otj.11.2019.05.02.04.18.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 04:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hi8TV2CdaeVFCN/c5P8sTwYBHNQMocxdqLYQjugNd+4=; b=HugvaykWcn5L1WegHUiVhxN9PR0QWRGKJsWo4gv1BIST1yS5d95ssBMSPmo4CDHIfX /obHG/cx6qiIa14sq2chTASyVloXrp5LBMg6YDJe29JcOR68V2uRh+rRaF/H/UtJ4vFh AMCa43/+WN5i4pZy0e5+C126fa9fvhtpzk4EKvIHLLVRV6BS++Na9gcbNJKx+Fh3dOxV xMmmeESNJYQqyMb/tFOvaI0PhwFcYrDRVQ4izYzc5yjjlqEOVmJ5X0t/d2nVCFd7UkP3 mlY2Ksyn573vHH2rooHMlsi13nKnxWOTFT4DCD22QYDwI9HCWxWp0x/VcCEel93A1Zob CZvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Hi8TV2CdaeVFCN/c5P8sTwYBHNQMocxdqLYQjugNd+4=; b=JbH0aa9LxXjY4PEyEv0Z3m3BT2FJBz/XxVSdfKLiQuOaD5L/GeC2MLxOqBYFzIQZcS MZbXUc6XFwD0UlKXzjl2kwl5H78Mvw8dMbhmZB5YxYAdKbl1/PxKY10qRsen+Ow7Euj0 BHQDiD8c1AQtGs6oGGaokjdLoQuWkaMfUiuZbcfK4SvQUgOUTDpMHIGzh+JdbxVGo225 jTDjtOLz6ZkOFTPRcxvD6FMwV/kIQdjK7HaXJSQT6kImwZg8VZTQPyzK84le7KhlXrV1 QIrauPLi89/AU/YXf00fyD3+SMNUtpUNbLgkJJdVt4EitwPyFxgdXLOug3+O0T5ZzWa9 TQow== X-Gm-Message-State: APjAAAUvJz49Cuf2DIeAlCOgrqBu7PccTInc02tEfkk9tiIUny2+Jijy GRTMxrs5vpmtIp/3Fwy/sGcrqBqLf+I= X-Google-Smtp-Source: APXvYqyL3z4OtwKJCet2PEEtgTSArS5V2hvucNHBdRtvtWHUsNDowPTvfjgZosrRsXm6ccFM006o3Q== X-Received: by 2002:a9d:3c2:: with SMTP id f60mr2013071otf.36.1556795891214; Thu, 02 May 2019 04:18:11 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 2 May 2019 05:17:54 -0600 Message-Id: <20190502111804.15843-8-pbonzini@redhat.com> In-Reply-To: <20190502111804.15843-1-pbonzini@redhat.com> References: <20190502111804.15843-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 02 May 2019 11:18:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 02 May 2019 11:18:12 +0000 (UTC) for IP:'209.85.210.45' DOMAIN:'mail-ot1-f45.google.com' HELO:'mail-ot1-f45.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.145 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H2, SPF_PASS, T_FILL_THIS_FORM_SHORT) 209.85.210.45 mail-ot1-f45.google.com 209.85.210.45 mail-ot1-f45.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 07/17] 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 02 May 2019 11:18:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) 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... Signed-off-by: Paolo Bonzini --- mod.py | 37 ++++++++++++++++++++++++++++++++++++- mods/email.py | 16 ++-------------- mods/git.py | 28 ++++++++++++++++------------ mods/testing.py | 25 ++++--------------------- 4 files changed, 58 insertions(+), 48 deletions(-) diff --git a/mod.py b/mod.py index 6f172d5..9e15064 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):] @@ -150,6 +150,41 @@ class PatchewModule(object): scm =3D self.project_config_schema return self._build_one(request, project, scm.name + ".", scm) =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..23590d4 100644 --- a/mods/email.py +++ b/mods/email.py @@ -52,7 +52,7 @@ Email information is configured in "INI" style: default_config =3D _default_config =20 email_schema =3D \ - ArraySchema("email_notification", "Email Notification", + ArraySchema("{name}", "Email Notification", desc=3D"Email notification", members=3D[ EnumSchema("event", "Event", @@ -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 caafc19..0125288 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