From nobody Sun Feb 8 03:57:56 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 ARC-Seal: i=1; a=rsa-sha256; t=1568219323; cv=none; d=zoho.com; s=zohoarc; b=NORdXL8P3xAvIrI/seQ7Lyr67Z7nD4fQ36268EQnOlGCl4A8+ngoAYp3Hp9IJ4/74xsN5xNzfUDNcMqRiIfozEMZdGqtoPsJhNWCe4YEReg2wygpdW6oQDG0/lTplbTjYlOU1zHdptvMJ/7TNnvO03iIFFy6v6f74A7eMJtLhwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568219323; 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=D728OjqJCOHuuGS9GOhjiC35LzoEaTm4pIk5eJ1aHm8=; b=ikjGGvg/LzQrryWv7AENquw2zopdLeI9ksBNO/75szBsfw/1uLQDy5sNhgt3/C1R0awKVynee3B3MvmsHuKmd8CMTkkPZuCpC2qbYo0wIKvbew64heOmyF+QA01D4Q46fk0rTcw4avn42iEvrng09FtibWLnwKCi4lcmpWTRvLE= 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=libvir-list-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 1568219323871659.8732767364228; Wed, 11 Sep 2019 09:28:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32B643090FC2; Wed, 11 Sep 2019 16:28:42 +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 0B6AD10018FF; Wed, 11 Sep 2019 16:28:42 +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 BB8CB1806B13; Wed, 11 Sep 2019 16:28:41 +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 x8BGSaEu013321 for ; Wed, 11 Sep 2019 12:28:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id DFB9A6017E; Wed, 11 Sep 2019 16:28:36 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5004B60BC1; Wed, 11 Sep 2019 16:28:36 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 11 Sep 2019 17:23:33 +0100 Message-Id: <20190911162333.8668-25-berrange@redhat.com> In-Reply-To: <20190911162333.8668-1-berrange@redhat.com> References: <20190911162333.8668-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 24/24] docs: rewrite polkit docs generator in Python 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 11 Sep 2019 16:28:42 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the genaclperms.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/Makefile.am | 6 +-- docs/genaclperms.pl | 125 -------------------------------------------- docs/genaclperms.py | 122 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 128 deletions(-) delete mode 100755 docs/genaclperms.pl create mode 100755 docs/genaclperms.py diff --git a/docs/Makefile.am b/docs/Makefile.am index e4aa8b4ad9..2f702821ba 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -184,7 +184,7 @@ schemadir =3D $(pkgdatadir)/schemas schema_DATA =3D $(wildcard $(srcdir)/schemas/*.rng) =20 EXTRA_DIST=3D \ - apibuild.py genaclperms.pl \ + apibuild.py genaclperms.py \ site.xsl subsite.xsl newapi.xsl page.xsl \ wrapstring.xsl \ $(dot_html) $(dot_html_in) $(gif) $(apihtml) $(apipng) \ @@ -200,8 +200,8 @@ EXTRA_DIST=3D \ acl_generated =3D aclperms.htmlinc =20 $(srcdir)/aclperms.htmlinc: $(top_srcdir)/src/access/viraccessperm.h \ - $(srcdir)/genaclperms.pl Makefile.am - $(AM_V_GEN)$(PERL) $(srcdir)/genaclperms.pl $< > $@ + $(srcdir)/genaclperms.py Makefile.am + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/genaclperms.py $< > $@ =20 MAINTAINERCLEANFILES =3D \ $(addprefix $(srcdir)/,$(dot_html)) \ diff --git a/docs/genaclperms.pl b/docs/genaclperms.pl deleted file mode 100755 index e20b4c11c3..0000000000 --- a/docs/genaclperms.pl +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2013 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# . -# - -use strict; -use warnings; - -my @objects =3D ( - "CONNECT", "DOMAIN", "INTERFACE", - "NETWORK_PORT", "NETWORK", "NODE_DEVICE", - "NWFILTER_BINDING", "NWFILTER", - "SECRET", "STORAGE_POOL", "STORAGE_VOL", - ); - -my %class; - -foreach my $object (@objects) { - my $class =3D lc $object; - - $class =3D~ s/(^\w|_\w)/uc $1/eg; - $class =3D~ s/_//g; - $class =3D~ s/Nwfilter/NWFilter/; - $class =3D "vir" . $class . "Ptr"; - - $class{$object} =3D $class; -} - -my $objects =3D join ("|", @objects); - -my %opts; -my $in_opts =3D 0; - -my %perms; - -while (<>) { - if ($in_opts) { - if (m,\*/,) { - $in_opts =3D 0; - } elsif (/\*\s*\@(\w+):\s*(.*?)\s*$/) { - $opts{$1} =3D $2; - } - } elsif (m,/\*\*,) { - $in_opts =3D 1; - } elsif (/VIR_ACCESS_PERM_($objects)_((?:\w|_)+),/) { - my $object =3D $1; - my $perm =3D lc $2; - next if $perm eq "last"; - - $perm =3D~ s/_/-/g; - - $perms{$object} =3D {} unless exists $perms{$object}; - $perms{$object}->{$perm} =3D { - desc =3D> $opts{desc}, - message =3D> $opts{message}, - anonymous =3D> $opts{anonymous} - }; - %opts =3D (); - } -} - -print < - - - -EOF - -foreach my $object (sort { $a cmp $b } keys %perms) { - my $class =3D $class{$object}; - my $olink =3D lc "object_" . $object; - print <$class - - - - - - - - -EOF - - foreach my $perm (sort { $a cmp $b } keys %{$perms{$object}}) { - my $description =3D $perms{$object}->{$perm}->{desc}; - - die "missing description for $object.$perm" unless - defined $description; - - my $plink =3D lc "perm_" . $object . "_" . $perm; - $plink =3D~ s/-/_/g; - - print < - - - -EOF - - } - - print < -
PermissionDescription
$perm$description
-EOF -} - -print < - -EOF diff --git a/docs/genaclperms.py b/docs/genaclperms.py new file mode 100755 index 0000000000..0cb5856716 --- /dev/null +++ b/docs/genaclperms.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# +# Copyright (C) 2013-2019 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . +# + +from __future__ import print_function + +import re +import sys + +objects =3D [ + "CONNECT", "DOMAIN", "INTERFACE", + "NETWORK_PORT", "NETWORK", "NODE_DEVICE", + "NWFILTER_BINDING", "NWFILTER", + "SECRET", "STORAGE_POOL", "STORAGE_VOL", +] + + +classes =3D {} + +for obj in objects: + klass =3D obj.lower() + + klass =3D re.sub(r'''(^\w|_\w)''', lambda a: a.group(1).upper(), klass) + klass =3D klass.replace("_", "") + klass =3D klass.replace("Nwfilter", "NWFilter") + klass =3D "vir" + klass + "Ptr" + + classes[obj] =3D klass + + +objectstr =3D "|".join(objects) + +opts =3D {} +in_opts =3D {} + +perms =3D {} + +aclfile =3D sys.argv[1] +with open(aclfile, "r") as fh: + for line in fh: + if in_opts: + if line.find("*/") !=3D -1: + in_opts =3D False + else: + m =3D re.match(r'''.*\*\s*\@(\w+):\s*(.*?)\s*$''', line) + if m is not None: + opts[m.group(1)] =3D m.group(2) + elif line.find("**") !=3D -1: + in_opts =3D True + else: + m =3D re.match(r'''.*VIR_ACCESS_PERM_(%s)_((?:\w|_)+),''' % ob= jectstr, line) + if m is not None: + obj =3D m.group(1) + perm =3D m.group(2).lower() + if perm =3D=3D "last": + continue + + perm =3D perm.replace("_", "-") + + if obj not in perms: + perms[obj] =3D {} + perms[obj][perm] =3D { + "desc": opts.get("desc", None), + "message": opts.get("message", None), + "anonymous": opts.get("anonymous", None), + } + opts =3D {} + +print('') +print('') +print('') +print(' ') + +for obj in sorted(perms.keys()): + klass =3D classes[obj] + + olink =3D "object_" + obj.lower() + + print('

%s

' % (olink, klass)) + print(' ') + print(' ') + print(' ') + print(' ') + print(' ') + print(' ') + print(' ') + print(' ') + + for perm in sorted(perms[obj].keys()): + description =3D perms[obj][perm]["desc"] + + if description is None: + raise Exception("missing description for %s.%s" % (obj, perm)) + + plink =3D "perm_" + obj.lower() + "_" + perm.lower() + plink =3D plink.replace("-", "_") + + print(' ') + print(' ' % (plink, perm)) + print(' ' % description) + print(' ') + + print(' ') + print('
PermissionDescription
%s%s
') + +print(' ') +print('') --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list