diff mbox series

[v3,1/3] python/sepolicy: Fix sepolicy manpage -w ...

Message ID 20221118125153.453700-1-lautrbach@redhat.com (mailing list archive)
State Accepted
Commit 7fd9628dd436
Headers show
Series [v3,1/3] python/sepolicy: Fix sepolicy manpage -w ... | expand

Commit Message

Petr Lautrbach Nov. 18, 2022, 12:51 p.m. UTC
Commit 7494bb1298b3 ("sepolicy: generate man pages in parallel")
improved sepolicy performance but broke `sepolicy manpage -w ...` as it
didn't collect data about domains and roles from ManPage() and so
HTMLManPages() generated only empty page. This is fixed now, domains
and roles are being collected and used for HTML pages.

Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---

- v3: improved the result loop, based on Ondrej Mosnacek <omosnace@redhat.com>'s suggestion


 python/sepolicy/sepolicy.py         | 13 +++++++++++--
 python/sepolicy/sepolicy/manpage.py | 12 +++++-------
 2 files changed, 16 insertions(+), 9 deletions(-)

Comments

James Carter Nov. 21, 2022, 2:58 p.m. UTC | #1
On Fri, Nov 18, 2022 at 8:07 AM Petr Lautrbach <lautrbach@redhat.com> wrote:
>
> Commit 7494bb1298b3 ("sepolicy: generate man pages in parallel")
> improved sepolicy performance but broke `sepolicy manpage -w ...` as it
> didn't collect data about domains and roles from ManPage() and so
> HTMLManPages() generated only empty page. This is fixed now, domains
> and roles are being collected and used for HTML pages.
>
> Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>

For these three patches:
Acked-by: James Carter <jwcart2@gmail.com>

> ---
>
> - v3: improved the result loop, based on Ondrej Mosnacek <omosnace@redhat.com>'s suggestion
>
>
>  python/sepolicy/sepolicy.py         | 13 +++++++++++--
>  python/sepolicy/sepolicy/manpage.py | 12 +++++-------
>  2 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/python/sepolicy/sepolicy.py b/python/sepolicy/sepolicy.py
> index 733d40484709..82ff6af2bc2d 100755
> --- a/python/sepolicy/sepolicy.py
> +++ b/python/sepolicy/sepolicy.py
> @@ -332,9 +332,10 @@ def manpage_work(domain, path, root, source_files, web):
>      from sepolicy.manpage import ManPage
>      m = ManPage(domain, path, root, source_files, web)
>      print(m.get_man_page_path())
> +    return (m.manpage_domains, m.manpage_roles)
>
>  def manpage(args):
> -    from sepolicy.manpage import HTMLManPages, manpage_domains, manpage_roles, gen_domains
> +    from sepolicy.manpage import HTMLManPages, gen_domains
>
>      path = args.path
>      if not args.policy and args.root != "/":
> @@ -347,9 +348,17 @@ def manpage(args):
>      else:
>          test_domains = args.domain
>
> +    manpage_domains = set()
> +    manpage_roles = set()
>      p = Pool()
> +    async_results = []
>      for domain in test_domains:
> -        p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web])
> +        async_results.append(p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web]))
> +    for result in async_results:
> +        domains, roles = result.get()
> +        manpage_domains.update(domains)
> +        manpage_roles.update(roles)
> +
>      p.close()
>      p.join()
>
> diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
> index 3e61e333193f..de72cb6cda5f 100755
> --- a/python/sepolicy/sepolicy/manpage.py
> +++ b/python/sepolicy/sepolicy/manpage.py
> @@ -21,7 +21,7 @@
>  #                                        02111-1307  USA
>  #
>  #
> -__all__ = ['ManPage', 'HTMLManPages', 'manpage_domains', 'manpage_roles', 'gen_domains']
> +__all__ = ['ManPage', 'HTMLManPages', 'gen_domains']
>
>  import string
>  import selinux
> @@ -147,10 +147,6 @@ def _gen_types():
>  def prettyprint(f, trim):
>      return " ".join(f[:-len(trim)].split("_"))
>
> -# for HTML man pages
> -manpage_domains = []
> -manpage_roles = []
> -
>  fedora_releases = ["Fedora17", "Fedora18"]
>  rhel_releases = ["RHEL6", "RHEL7"]
>
> @@ -408,6 +404,8 @@ class ManPage:
>      """
>      modules_dict = None
>      enabled_str = ["Disabled", "Enabled"]
> +    manpage_domains = []
> +    manpage_roles = []
>
>      def __init__(self, domainname, path="/tmp", root="/", source_files=False, html=False):
>          self.html = html
> @@ -453,10 +451,10 @@ class ManPage:
>          if self.domainname + "_r" in self.all_roles:
>              self.__gen_user_man_page()
>              if self.html:
> -                manpage_roles.append(self.man_page_path)
> +                self.manpage_roles.append(self.man_page_path)
>          else:
>              if self.html:
> -                manpage_domains.append(self.man_page_path)
> +                self.manpage_domains.append(self.man_page_path)
>              self.__gen_man_page()
>          self.fd.close()
>
> --
> 2.38.1
>
James Carter Nov. 23, 2022, 3:04 p.m. UTC | #2
On Mon, Nov 21, 2022 at 9:58 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Fri, Nov 18, 2022 at 8:07 AM Petr Lautrbach <lautrbach@redhat.com> wrote:
> >
> > Commit 7494bb1298b3 ("sepolicy: generate man pages in parallel")
> > improved sepolicy performance but broke `sepolicy manpage -w ...` as it
> > didn't collect data about domains and roles from ManPage() and so
> > HTMLManPages() generated only empty page. This is fixed now, domains
> > and roles are being collected and used for HTML pages.
> >
> > Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
>
> For these three patches:
> Acked-by: James Carter <jwcart2@gmail.com>
>
These three patches have been merged.
Thanks,
Jim

> > ---
> >
> > - v3: improved the result loop, based on Ondrej Mosnacek <omosnace@redhat.com>'s suggestion
> >
> >
> >  python/sepolicy/sepolicy.py         | 13 +++++++++++--
> >  python/sepolicy/sepolicy/manpage.py | 12 +++++-------
> >  2 files changed, 16 insertions(+), 9 deletions(-)
> >
> > diff --git a/python/sepolicy/sepolicy.py b/python/sepolicy/sepolicy.py
> > index 733d40484709..82ff6af2bc2d 100755
> > --- a/python/sepolicy/sepolicy.py
> > +++ b/python/sepolicy/sepolicy.py
> > @@ -332,9 +332,10 @@ def manpage_work(domain, path, root, source_files, web):
> >      from sepolicy.manpage import ManPage
> >      m = ManPage(domain, path, root, source_files, web)
> >      print(m.get_man_page_path())
> > +    return (m.manpage_domains, m.manpage_roles)
> >
> >  def manpage(args):
> > -    from sepolicy.manpage import HTMLManPages, manpage_domains, manpage_roles, gen_domains
> > +    from sepolicy.manpage import HTMLManPages, gen_domains
> >
> >      path = args.path
> >      if not args.policy and args.root != "/":
> > @@ -347,9 +348,17 @@ def manpage(args):
> >      else:
> >          test_domains = args.domain
> >
> > +    manpage_domains = set()
> > +    manpage_roles = set()
> >      p = Pool()
> > +    async_results = []
> >      for domain in test_domains:
> > -        p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web])
> > +        async_results.append(p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web]))
> > +    for result in async_results:
> > +        domains, roles = result.get()
> > +        manpage_domains.update(domains)
> > +        manpage_roles.update(roles)
> > +
> >      p.close()
> >      p.join()
> >
> > diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
> > index 3e61e333193f..de72cb6cda5f 100755
> > --- a/python/sepolicy/sepolicy/manpage.py
> > +++ b/python/sepolicy/sepolicy/manpage.py
> > @@ -21,7 +21,7 @@
> >  #                                        02111-1307  USA
> >  #
> >  #
> > -__all__ = ['ManPage', 'HTMLManPages', 'manpage_domains', 'manpage_roles', 'gen_domains']
> > +__all__ = ['ManPage', 'HTMLManPages', 'gen_domains']
> >
> >  import string
> >  import selinux
> > @@ -147,10 +147,6 @@ def _gen_types():
> >  def prettyprint(f, trim):
> >      return " ".join(f[:-len(trim)].split("_"))
> >
> > -# for HTML man pages
> > -manpage_domains = []
> > -manpage_roles = []
> > -
> >  fedora_releases = ["Fedora17", "Fedora18"]
> >  rhel_releases = ["RHEL6", "RHEL7"]
> >
> > @@ -408,6 +404,8 @@ class ManPage:
> >      """
> >      modules_dict = None
> >      enabled_str = ["Disabled", "Enabled"]
> > +    manpage_domains = []
> > +    manpage_roles = []
> >
> >      def __init__(self, domainname, path="/tmp", root="/", source_files=False, html=False):
> >          self.html = html
> > @@ -453,10 +451,10 @@ class ManPage:
> >          if self.domainname + "_r" in self.all_roles:
> >              self.__gen_user_man_page()
> >              if self.html:
> > -                manpage_roles.append(self.man_page_path)
> > +                self.manpage_roles.append(self.man_page_path)
> >          else:
> >              if self.html:
> > -                manpage_domains.append(self.man_page_path)
> > +                self.manpage_domains.append(self.man_page_path)
> >              self.__gen_man_page()
> >          self.fd.close()
> >
> > --
> > 2.38.1
> >
diff mbox series

Patch

diff --git a/python/sepolicy/sepolicy.py b/python/sepolicy/sepolicy.py
index 733d40484709..82ff6af2bc2d 100755
--- a/python/sepolicy/sepolicy.py
+++ b/python/sepolicy/sepolicy.py
@@ -332,9 +332,10 @@  def manpage_work(domain, path, root, source_files, web):
     from sepolicy.manpage import ManPage
     m = ManPage(domain, path, root, source_files, web)
     print(m.get_man_page_path())
+    return (m.manpage_domains, m.manpage_roles)
 
 def manpage(args):
-    from sepolicy.manpage import HTMLManPages, manpage_domains, manpage_roles, gen_domains
+    from sepolicy.manpage import HTMLManPages, gen_domains
 
     path = args.path
     if not args.policy and args.root != "/":
@@ -347,9 +348,17 @@  def manpage(args):
     else:
         test_domains = args.domain
 
+    manpage_domains = set()
+    manpage_roles = set()
     p = Pool()
+    async_results = []
     for domain in test_domains:
-        p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web])
+        async_results.append(p.apply_async(manpage_work, [domain, path, args.root, args.source_files, args.web]))
+    for result in async_results:
+        domains, roles = result.get()
+        manpage_domains.update(domains)
+        manpage_roles.update(roles)
+
     p.close()
     p.join()
 
diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
index 3e61e333193f..de72cb6cda5f 100755
--- a/python/sepolicy/sepolicy/manpage.py
+++ b/python/sepolicy/sepolicy/manpage.py
@@ -21,7 +21,7 @@ 
 #                                        02111-1307  USA
 #
 #
-__all__ = ['ManPage', 'HTMLManPages', 'manpage_domains', 'manpage_roles', 'gen_domains']
+__all__ = ['ManPage', 'HTMLManPages', 'gen_domains']
 
 import string
 import selinux
@@ -147,10 +147,6 @@  def _gen_types():
 def prettyprint(f, trim):
     return " ".join(f[:-len(trim)].split("_"))
 
-# for HTML man pages
-manpage_domains = []
-manpage_roles = []
-
 fedora_releases = ["Fedora17", "Fedora18"]
 rhel_releases = ["RHEL6", "RHEL7"]
 
@@ -408,6 +404,8 @@  class ManPage:
     """
     modules_dict = None
     enabled_str = ["Disabled", "Enabled"]
+    manpage_domains = []
+    manpage_roles = []
 
     def __init__(self, domainname, path="/tmp", root="/", source_files=False, html=False):
         self.html = html
@@ -453,10 +451,10 @@  class ManPage:
         if self.domainname + "_r" in self.all_roles:
             self.__gen_user_man_page()
             if self.html:
-                manpage_roles.append(self.man_page_path)
+                self.manpage_roles.append(self.man_page_path)
         else:
             if self.html:
-                manpage_domains.append(self.man_page_path)
+                self.manpage_domains.append(self.man_page_path)
             self.__gen_man_page()
         self.fd.close()