* [PATCH v2 2/3] python/sepolicy: Use distro module to get os version
2022-11-15 19:45 [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w Petr Lautrbach
@ 2022-11-15 19:45 ` Petr Lautrbach
2022-11-15 19:45 ` [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages Petr Lautrbach
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Petr Lautrbach @ 2022-11-15 19:45 UTC (permalink / raw)
To: selinux; +Cc: Petr Lautrbach
From: Petr Lautrbach <lautrbach@redhat.com>
distro module uses /etc/os-release file which contains operating system
identification data, see os-release(5). Given that the mechanism doesn't
use `rpm` it should be possible to generate man pages on other
distributions.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---
python/sepolicy/sepolicy/__init__.py | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
index 9c3caa05b80b..baa4c8e62e97 100644
--- a/python/sepolicy/sepolicy/__init__.py
+++ b/python/sepolicy/sepolicy/__init__.py
@@ -1226,27 +1226,14 @@ def boolean_desc(boolean):
def get_os_version():
- os_version = ""
- pkg_name = "selinux-policy"
+ system_release = ""
try:
- try:
- from commands import getstatusoutput
- except ImportError:
- from subprocess import getstatusoutput
- rc, output = getstatusoutput("rpm -q '%s'" % pkg_name)
- if rc == 0:
- os_version = output.split(".")[-2]
- except:
- os_version = ""
-
- if os_version[0:2] == "fc":
- os_version = "Fedora" + os_version[2:]
- elif os_version[0:2] == "el":
- os_version = "RHEL" + os_version[2:]
- else:
- os_version = ""
+ import distro
+ system_release = distro.name(pretty=True)
+ except IOError:
+ system_release = "Misc"
- return os_version
+ return system_release
def reinit():
--
2.38.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages
2022-11-15 19:45 [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w Petr Lautrbach
2022-11-15 19:45 ` [PATCH v2 2/3] python/sepolicy: Use distro module to get os version Petr Lautrbach
@ 2022-11-15 19:45 ` Petr Lautrbach
2022-11-17 12:46 ` Petr Lautrbach
2022-11-16 21:50 ` [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w James Carter
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Petr Lautrbach @ 2022-11-15 19:45 UTC (permalink / raw)
To: selinux; +Cc: Petr Lautrbach
From: Petr Lautrbach <lautrbach@redhat.com>
And do not hardcode Fedora and RHEL versions.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---
python/sepolicy/sepolicy/manpage.py | 71 ++++-------------------------
1 file changed, 8 insertions(+), 63 deletions(-)
diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
index de72cb6cda5f..d9973170f3c3 100755
--- a/python/sepolicy/sepolicy/manpage.py
+++ b/python/sepolicy/sepolicy/manpage.py
@@ -147,9 +147,6 @@ def _gen_types():
def prettyprint(f, trim):
return " ".join(f[:-len(trim)].split("_"))
-fedora_releases = ["Fedora17", "Fedora18"]
-rhel_releases = ["RHEL6", "RHEL7"]
-
def get_alphabet_manpages(manpage_list):
alphabet_manpages = dict.fromkeys(string.ascii_letters, [])
@@ -180,7 +177,7 @@ def convert_manpage_to_html(html_manpage, manpage):
class HTMLManPages:
"""
- Generate a HHTML Manpages on an given SELinux domains
+ Generate a HTML Manpages on an given SELinux domains
"""
def __init__(self, manpage_roles, manpage_domains, path, os_version):
@@ -188,18 +185,12 @@ class HTMLManPages:
self.manpage_domains = get_alphabet_manpages(manpage_domains)
self.os_version = os_version
self.old_path = path + "/"
- self.new_path = self.old_path + self.os_version + "/"
-
- if self.os_version in fedora_releases or self.os_version in rhel_releases:
- self.__gen_html_manpages()
- else:
- print("SELinux HTML man pages can not be generated for this %s" % os_version)
- exit(1)
+ self.new_path = self.old_path
+ self.__gen_html_manpages()
def __gen_html_manpages(self):
self._write_html_manpage()
self._gen_index()
- self._gen_body()
self._gen_css()
def _write_html_manpage(self):
@@ -217,67 +208,21 @@ class HTMLManPages:
convert_manpage_to_html((self.new_path + r.rsplit("_selinux", 1)[0] + ".html"), self.old_path + r)
def _gen_index(self):
- index = self.old_path + "index.html"
- fd = open(index, 'w')
- fd.write("""
-<html>
-<head>
- <link rel=stylesheet type="text/css" href="style.css" title="style">
- <title>SELinux man pages online</title>
-</head>
-<body>
-<h1>SELinux man pages</h1>
-<br></br>
-Fedora or Red Hat Enterprise Linux Man Pages.</h2>
-<br></br>
-<hr>
-<h3>Fedora</h3>
-<table><tr>
-<td valign="middle">
-</td>
-</tr></table>
-<pre>
-""")
- for f in fedora_releases:
- fd.write("""
-<a href=%s/%s.html>%s</a> - SELinux man pages for %s """ % (f, f, f, f))
-
- fd.write("""
-</pre>
-<hr>
-<h3>RHEL</h3>
-<table><tr>
-<td valign="middle">
-</td>
-</tr></table>
-<pre>
-""")
- for r in rhel_releases:
- fd.write("""
-<a href=%s/%s.html>%s</a> - SELinux man pages for %s """ % (r, r, r, r))
-
- fd.write("""
-</pre>
- """)
- fd.close()
- print("%s has been created" % index)
-
- def _gen_body(self):
- html = self.new_path + self.os_version + ".html"
+ html = self.new_path + "index.html"
fd = open(html, 'w')
fd.write("""
<html>
<head>
- <link rel=stylesheet type="text/css" href="../style.css" title="style">
- <title>Linux man-pages online for Fedora18</title>
+ <link rel=stylesheet type="text/css" href="style.css" title="style">
+ <title>SELinux man pages online</title>
</head>
<body>
-<h1>SELinux man pages for Fedora18</h1>
+<h1>SELinux man pages for %s</h1>
<hr>
<table><tr>
<td valign="middle">
<h3>SELinux roles</h3>
-""")
+""" % self.os_version)
for letter in self.manpage_roles:
if len(self.manpage_roles[letter]):
fd.write("""
--
2.38.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages
2022-11-15 19:45 ` [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages Petr Lautrbach
@ 2022-11-17 12:46 ` Petr Lautrbach
0 siblings, 0 replies; 9+ messages in thread
From: Petr Lautrbach @ 2022-11-17 12:46 UTC (permalink / raw)
To: selinux
Petr Lautrbach <plautrba@redhat.com> writes:
> From: Petr Lautrbach <lautrbach@redhat.com>
>
> And do not hardcode Fedora and RHEL versions.
>
> Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
> ---
> python/sepolicy/sepolicy/manpage.py | 71 ++++-------------------------
> 1 file changed, 8 insertions(+), 63 deletions(-)
>
> diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
> index de72cb6cda5f..d9973170f3c3 100755
> --- a/python/sepolicy/sepolicy/manpage.py
> +++ b/python/sepolicy/sepolicy/manpage.py
> @@ -147,9 +147,6 @@ def _gen_types():
> def prettyprint(f, trim):
> return " ".join(f[:-len(trim)].split("_"))
>
> -fedora_releases = ["Fedora17", "Fedora18"]
> -rhel_releases = ["RHEL6", "RHEL7"]
> -
>
> def get_alphabet_manpages(manpage_list):
> alphabet_manpages = dict.fromkeys(string.ascii_letters, [])
> @@ -180,7 +177,7 @@ def convert_manpage_to_html(html_manpage, manpage):
> class HTMLManPages:
>
> """
> - Generate a HHTML Manpages on an given SELinux domains
> + Generate a HTML Manpages on an given SELinux domains
> """
>
> def __init__(self, manpage_roles, manpage_domains, path, os_version):
> @@ -188,18 +185,12 @@ class HTMLManPages:
> self.manpage_domains = get_alphabet_manpages(manpage_domains)
> self.os_version = os_version
> self.old_path = path + "/"
> - self.new_path = self.old_path + self.os_version + "/"
> -
> - if self.os_version in fedora_releases or self.os_version in rhel_releases:
> - self.__gen_html_manpages()
> - else:
> - print("SELinux HTML man pages can not be generated for this %s" % os_version)
> - exit(1)
> + self.new_path = self.old_path
> + self.__gen_html_manpages()
>
> def __gen_html_manpages(self):
> self._write_html_manpage()
> self._gen_index()
> - self._gen_body()
> self._gen_css()
>
> def _write_html_manpage(self):
> @@ -217,67 +208,21 @@ class HTMLManPages:
> convert_manpage_to_html((self.new_path + r.rsplit("_selinux", 1)[0] + ".html"), self.old_path + r)
>
> def _gen_index(self):
> - index = self.old_path + "index.html"
> - fd = open(index, 'w')
> - fd.write("""
> -<html>
> -<head>
> - <link rel=stylesheet type="text/css" href="style.css" title="style">
> - <title>SELinux man pages online</title>
It should be just "SELinux man pages", without "online"
> -</head>
> -<body>
> -<h1>SELinux man pages</h1>
> -<br></br>
> -Fedora or Red Hat Enterprise Linux Man Pages.</h2>
> -<br></br>
> -<hr>
> -<h3>Fedora</h3>
> -<table><tr>
> -<td valign="middle">
> -</td>
> -</tr></table>
> -<pre>
> -""")
> - for f in fedora_releases:
> - fd.write("""
> -<a href=%s/%s.html>%s</a> - SELinux man pages for %s """ % (f, f, f, f))
> -
> - fd.write("""
> -</pre>
> -<hr>
> -<h3>RHEL</h3>
> -<table><tr>
> -<td valign="middle">
> -</td>
> -</tr></table>
> -<pre>
> -""")
> - for r in rhel_releases:
> - fd.write("""
> -<a href=%s/%s.html>%s</a> - SELinux man pages for %s """ % (r, r, r, r))
> -
> - fd.write("""
> -</pre>
> - """)
> - fd.close()
> - print("%s has been created" % index)
> -
> - def _gen_body(self):
> - html = self.new_path + self.os_version + ".html"
> + html = self.new_path + "index.html"
> fd = open(html, 'w')
> fd.write("""
> <html>
> <head>
> - <link rel=stylesheet type="text/css" href="../style.css" title="style">
> - <title>Linux man-pages online for Fedora18</title>
> + <link rel=stylesheet type="text/css" href="style.css" title="style">
> + <title>SELinux man pages online</title>
> </head>
> <body>
> -<h1>SELinux man pages for Fedora18</h1>
> +<h1>SELinux man pages for %s</h1>
> <hr>
> <table><tr>
> <td valign="middle">
> <h3>SELinux roles</h3>
> -""")
> +""" % self.os_version)
> for letter in self.manpage_roles:
> if len(self.manpage_roles[letter]):
> fd.write("""
> --
> 2.38.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ...
2022-11-15 19:45 [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w Petr Lautrbach
2022-11-15 19:45 ` [PATCH v2 2/3] python/sepolicy: Use distro module to get os version Petr Lautrbach
2022-11-15 19:45 ` [PATCH v2 3/3] python/sepolicy: Simplify generation of man pages Petr Lautrbach
@ 2022-11-16 21:50 ` James Carter
2022-11-17 12:39 ` Petr Lautrbach
2022-11-17 18:37 ` James Carter
2022-11-18 8:34 ` Ondrej Mosnacek
4 siblings, 1 reply; 9+ messages in thread
From: James Carter @ 2022-11-16 21:50 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: selinux, Petr Lautrbach
On Tue, Nov 15, 2022 at 2:58 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> From: Petr Lautrbach <lautrbach@redhat.com>
>
> 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>
I ran `sepolicy manpage -w -d unconfined_t` and received the following error:
"""
Traceback (most recent call last):
File "/usr/lib64/python3.10/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/home/jim/local/usr/bin/./sepolicy", line 335, in manpage_work
return (m.manpage_domains, m.manpage_roles)
AttributeError: 'ManPage' object has no attribute 'manpage_domains'
"""
I don't get the error from the master branch, but I do confirm the bug
you reported above.
Thanks,
Jim
> ---
> 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..2ca02ee9a0cf 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]))
> + results = map(lambda x: x.get(), async_results)
> + for result in results:
> + manpage_domains.update(set(result[0]))
> + manpage_roles.update(set(result[1]))
> +
> 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
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ...
2022-11-16 21:50 ` [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w James Carter
@ 2022-11-17 12:39 ` Petr Lautrbach
2022-11-17 18:36 ` James Carter
0 siblings, 1 reply; 9+ messages in thread
From: Petr Lautrbach @ 2022-11-17 12:39 UTC (permalink / raw)
To: James Carter; +Cc: selinux
James Carter <jwcart2@gmail.com> writes:
> On Tue, Nov 15, 2022 at 2:58 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>>
>> From: Petr Lautrbach <lautrbach@redhat.com>
>>
>> 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>
>
> I ran `sepolicy manpage -w -d unconfined_t` and received the following error:
> """
> Traceback (most recent call last):
> File "/usr/lib64/python3.10/multiprocessing/pool.py", line 125, in worker
> result = (True, func(*args, **kwds))
> File "/home/jim/local/usr/bin/./sepolicy", line 335, in manpage_work
> return (m.manpage_domains, m.manpage_roles)
> AttributeError: 'ManPage' object has no attribute 'manpage_domains'
> """
>
I think you nee to remove "-Es" command line options from /home/jim/local/usr/bin/./sepolicy
sed -i '1s/ -Es//' /home/jim/local/usr/bin/./sepolicy
> I don't get the error from the master branch, but I do confirm the bug
> you reported above.
>
> Thanks,
> Jim
>
>> ---
>> 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..2ca02ee9a0cf 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]))
>> + results = map(lambda x: x.get(), async_results)
>> + for result in results:
>> + manpage_domains.update(set(result[0]))
>> + manpage_roles.update(set(result[1]))
>> +
>> 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
>>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ...
2022-11-17 12:39 ` Petr Lautrbach
@ 2022-11-17 18:36 ` James Carter
0 siblings, 0 replies; 9+ messages in thread
From: James Carter @ 2022-11-17 18:36 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: selinux
On Thu, Nov 17, 2022 at 7:39 AM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> James Carter <jwcart2@gmail.com> writes:
>
> > On Tue, Nov 15, 2022 at 2:58 PM Petr Lautrbach <plautrba@redhat.com> wrote:
> >>
> >> From: Petr Lautrbach <lautrbach@redhat.com>
> >>
> >> 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>
> >
> > I ran `sepolicy manpage -w -d unconfined_t` and received the following error:
> > """
> > Traceback (most recent call last):
> > File "/usr/lib64/python3.10/multiprocessing/pool.py", line 125, in worker
> > result = (True, func(*args, **kwds))
> > File "/home/jim/local/usr/bin/./sepolicy", line 335, in manpage_work
> > return (m.manpage_domains, m.manpage_roles)
> > AttributeError: 'ManPage' object has no attribute 'manpage_domains'
> > """
> >
>
> I think you nee to remove "-Es" command line options from /home/jim/local/usr/bin/./sepolicy
>
> sed -i '1s/ -Es//' /home/jim/local/usr/bin/./sepolicy
>
That worked.
Thanks,
Jim
>
> > I don't get the error from the master branch, but I do confirm the bug
> > you reported above.
> >
> > Thanks,
> > Jim
> >
> >> ---
> >> 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..2ca02ee9a0cf 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]))
> >> + results = map(lambda x: x.get(), async_results)
> >> + for result in results:
> >> + manpage_domains.update(set(result[0]))
> >> + manpage_roles.update(set(result[1]))
> >> +
> >> 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
> >>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ...
2022-11-15 19:45 [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w Petr Lautrbach
` (2 preceding siblings ...)
2022-11-16 21:50 ` [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w James Carter
@ 2022-11-17 18:37 ` James Carter
2022-11-18 8:34 ` Ondrej Mosnacek
4 siblings, 0 replies; 9+ messages in thread
From: James Carter @ 2022-11-17 18:37 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: selinux, Petr Lautrbach
On Tue, Nov 15, 2022 at 2:58 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> From: Petr Lautrbach <lautrbach@redhat.com>
>
> 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>
> ---
> 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..2ca02ee9a0cf 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]))
> + results = map(lambda x: x.get(), async_results)
> + for result in results:
> + manpage_domains.update(set(result[0]))
> + manpage_roles.update(set(result[1]))
> +
> 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
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w ...
2022-11-15 19:45 [PATCH v2 1/3] python/sepolicy: Fix sepolicy manpage -w Petr Lautrbach
` (3 preceding siblings ...)
2022-11-17 18:37 ` James Carter
@ 2022-11-18 8:34 ` Ondrej Mosnacek
4 siblings, 0 replies; 9+ messages in thread
From: Ondrej Mosnacek @ 2022-11-18 8:34 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: selinux, Petr Lautrbach
On Tue, Nov 15, 2022 at 8:49 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> From: Petr Lautrbach <lautrbach@redhat.com>
>
> 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>
> ---
> 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..2ca02ee9a0cf 100755
> --- a/python/sepolicy/sepolicy.py
> +++ b/python/sepolicy/sepolicy.py
[...]
> @@ -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]))
> + results = map(lambda x: x.get(), async_results)
> + for result in results:
> + manpage_domains.update(set(result[0]))
> + manpage_roles.update(set(result[1]))
The above four lines can be written a bit more nicely as follows:
for result in async_results:
domains, roles = result.get()
manpage_domains.update(domains)
manpage_roles.update(roles)
Note that set.update() accepts any iterable, it doesn't need to be a set.
> +
> p.close()
> p.join()
>
[...]
--
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
^ permalink raw reply [flat|nested] 9+ messages in thread