From nobody Tue Jul 1 09:37:22 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; 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=1555495807; cv=none; d=zoho.com; s=zohoarc; b=R6COyi/cNVtI6Mb1mAf2RuKwPkg7oJAdeMGTqKnLqljNBv8wFpVcXQjd9Rfb3EYvmMU0fCPk0AzAwNHCDOLz0WoWX9YDG2wcRUnL0bQUdCfJvYzBkEEsDKiJLQwI8kA7Q1vYe8tuF/iup/uIHoU406pSPkPHYiSOxTKchbS0Ea8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555495807; 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=81Cmz6QK54GbQpFeIfSpl065G2QhWKnkC2Ic7eKQMAM=; b=AvXhPecySHsoRlkHFJjiCHR+N/jn9DAiNbiCR8uThD8TKjTAIzzJoCmBsDtajQEXgGT2kpd+o4ub9UYg7wHZ0wggpnUXCsTJu3paSgIFVEJ9KttlNl7IJFPOyPZHEuXdb+MHDDjn/MufyPImGoz8h1HhJdCojjoEmiHw+EMDKTc= 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 1555495807718309.81932091360886; Wed, 17 Apr 2019 03:10:07 -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 804EE66991; Wed, 17 Apr 2019 10:10:06 +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 718C460143; Wed, 17 Apr 2019 10:10:06 +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 64B1A181AC45; Wed, 17 Apr 2019 10:10:06 +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 x3HAA5Ra013107 for ; Wed, 17 Apr 2019 06:10:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE4511001E9F; Wed, 17 Apr 2019 10:10:05 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4E091001E8C for ; Wed, 17 Apr 2019 10:10:05 +0000 (UTC) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 97433C049D7C for ; Wed, 17 Apr 2019 10:09:58 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id c1so2661095wml.4 for ; Wed, 17 Apr 2019 03:09:58 -0700 (PDT) Received: from donizetti.redhat.com ([2001:b07:6468:f312:ac27:aac4:c65c:6eb]) by smtp.gmail.com with ESMTPSA id c13sm4949719wrx.88.2019.04.17.03.09.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 03:09:56 -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=Z8VpLMMSCbQWtvtNJVfCHemDzBifOTWUFjp6x9Uxd+s=; b=kgGce+oPpUmtsSm14jogQcKnIotSxSP1g3HpZQOz5BNOr964mUIdiIjbqx8uEaTiPn voWOAdJ4FjsraCZwknpkJ48WLVSwmi5MrYvvZ7tIVHbXIZmfASuF/463R5TgvNXjGfhh QkLwicnTRVCYuOxHyqiMuNMuHZ5lDF12MizM2mBS6uKspHplI9+Qa8bDGms0ScRvvcTG bkZkP59fzsDGQ/Di/mC6OZfr+qMeg5B9yC2BJNo6nJlWBm53A1x1bSqqA0UVvZKnTn70 0CLSAZVuxWfq4AcMB0ciKYmJagqHe+19XzJBGJSuDQlJYw4wLUZrTWVuJoSAp7JINBn6 Tqeg== 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=Z8VpLMMSCbQWtvtNJVfCHemDzBifOTWUFjp6x9Uxd+s=; b=f5S2/2bp46UmyWhhvGqZIYPoSR5qLMPvz8tMiKulh05YF/CwW3hGDOrjZ9HpZzEuRF Kcdodk+EWWGpEO9gqmCKNwgEzWjPrvczJX6oxdGx4e1Yi1JL+FcIzxr8aEeAcEFH6qP8 XzD2TTLewHgUlGC6akwaAg4Refu6ZVBF1xJvc4lUWHZ+KPEvN8LH/roo5mXHdgXXDFBY RggFoi4WqJSCQ/U2R+d24cSx9TR4mrWP856IvGhi3RhpQ/ymxHhOUAA5fKdTKTIeNPPJ ncqqA5Z0yXFxGolococ+HdpTYCQbtIwOlA1pWPOepecVFnLo/h+Zuo8pRNAxPE+f03OS bJew== X-Gm-Message-State: APjAAAVIk4hUGMku/HoWK58A7VGffBqZEQ1hrdAWY/J86NuK51VmBZNn vs1/a1jfu+59KU4MWRTq39FIPokm X-Google-Smtp-Source: APXvYqyc9nz8zJGZOCtTnsmMnMv+oASXPeuAt9dTeZKGDPjRZw0zi8lYqpLLpdgTsbievKg0CSGkhQ== X-Received: by 2002:a1c:988d:: with SMTP id a135mr32646259wme.24.1555495796966; Wed, 17 Apr 2019 03:09:56 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 17 Apr 2019 12:09:48 +0200 Message-Id: <20190417100948.8810-8-pbonzini@redhat.com> In-Reply-To: <20190417100948.8810-1-pbonzini@redhat.com> References: <20190417100948.8810-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.31]); Wed, 17 Apr 2019 10:09:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 17 Apr 2019 10:09:58 +0000 (UTC) for IP:'209.85.128.54' DOMAIN:'mail-wm1-f54.google.com' HELO:'mail-wm1-f54.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.25 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS, T_FILL_THIS_FORM_SHORT) 209.85.128.54 mail-wm1-f54.google.com 209.85.128.54 mail-wm1-f54.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 7/7] mods: refactor extraction of properties 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.38]); Wed, 17 Apr 2019 10:10:06 +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_property_schema to drive the conversion. This will be useful in order to support YAML-based configuration and also to de-JSONify project properties. --- mod.py | 34 ++++++++++++++++++++++++++++++++++ mods/email.py | 14 +------------- mods/testing.py | 13 +------------ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/mod.py b/mod.py index 696dda1..3481a73 100644 --- a/mod.py +++ b/mod.py @@ -152,6 +152,40 @@ 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, v in project.get_properties().items(): + 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) + if isinstance(value, dict): + value["name"] =3D name + result[name] =3D value + 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: + 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 + else: + return project.get_property(prop_name) + + def get_module_properties(self, project): + scm =3D self.project_property_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 91c7d28..7ee7724 100644 --- a/mods/email.py +++ b/mods/email.py @@ -188,19 +188,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_module_properties(project)["notifications"] =20 def on_event(self, event, **params): class EmailCancelled(Exception): diff --git a/mods/testing.py b/mods/testing.py index e390e30..05493f0 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_module_properties(obj)["tests"] =20 def _build_reset_ops(self, obj): if isinstance(obj, Message): --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel