From nobody Sat Feb 7 21:15:43 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=1570621418; cv=none; d=zoho.com; s=zohoarc; b=K15rBx5FaaMt4b4tvDGb/mzXRJiUAQcd0jSuNMFBjT2i+DnCNd6vSQB5BVNB+kpq13eWli8RrglYyInEZ1qXSgG70J0+EQzgdrnujlGOsy27yZBDHCbcp0KgoR2hUENib7cisKiO1yeTrnn/tPBJsfahGzdrwkqEevmjJMyC280= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570621418; 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; bh=oQVG9mjMZFjKTLSs2OGyOUDJheaslU2emReEaxsfj5M=; b=YhS5otcA9cwmM4RNMrA5NLDeGx92HeOSd26t4o1qm7JI4inCAFofPGQCZkEzigDdnp0xu+1lQawd7j9UKD1uAkLkUG+TQruoVESKRyeiBhXuu4bH9sZp8NQc7bN7GAS/E+agUHXK2iUGWyHoUjI0n5sXcmhrFWxdE3NzQDTU/9M= 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 1570621418324406.3316586604752; Wed, 9 Oct 2019 04:43:38 -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 ACC6D2A09AD; Wed, 9 Oct 2019 11:43:36 +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 85373166BE; Wed, 9 Oct 2019 11:43:36 +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 3F3141803B4A; Wed, 9 Oct 2019 11:43:36 +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 x99BhV7t030182 for ; Wed, 9 Oct 2019 07:43:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23F3C6017E; Wed, 9 Oct 2019 11:43:31 +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 8B6D7601B3; Wed, 9 Oct 2019 11:43:30 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 9 Oct 2019 12:37:37 +0100 Message-Id: <20191009113741.5002-23-berrange@redhat.com> In-Reply-To: <20191009113741.5002-1-berrange@redhat.com> References: <20191009113741.5002-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 v4 22/26] 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 09 Oct 2019 11:43:37 +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 --- Makefile.am | 1 + docs/Makefile.am | 6 +- docs/genaclperms.pl | 125 ----------------------------------------- scripts/genaclperms.py | 123 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 128 deletions(-) delete mode 100755 docs/genaclperms.pl create mode 100755 scripts/genaclperms.py diff --git a/Makefile.am b/Makefile.am index fef886ad31..4b82cdee35 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ EXTRA_DIST =3D \ scripts/check-symfile.py \ scripts/check-symsorting.py \ scripts/dtrace2systemtap.py \ + scripts/genaclperms.py \ scripts/genpolkit.py \ scripts/gensystemtap.py \ scripts/group-qemu-caps.py \ diff --git a/docs/Makefile.am b/docs/Makefile.am index f59f3e0b9d..3cbf573e25 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -163,7 +163,7 @@ schemadir =3D $(pkgdatadir)/schemas schema_DATA =3D $(wildcard $(srcdir)/schemas/*.rng) =20 EXTRA_DIST=3D \ - apibuild.py genaclperms.pl \ + apibuild.py \ site.xsl subsite.xsl newapi.xsl page.xsl \ wrapstring.xsl \ $(dot_html) $(dot_html_in) $(gif) $(apihtml) $(apipng) \ @@ -177,8 +177,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 $< > $@ + $(top_srcdir)/scripts/genaclperms.py Makefile.am + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/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/scripts/genaclperms.py b/scripts/genaclperms.py new file mode 100755 index 0000000000..cd92346449 --- /dev/null +++ b/scripts/genaclperms.py @@ -0,0 +1,123 @@ +#!/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.search(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.search(r'''VIR_ACCESS_PERM_(%s)_((?:\w|_)+),''' % + objectstr, 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