|
|
9bbebd |
From b2993d464e05291020dbf60fc2948ac152eb0003 Mon Sep 17 00:00:00 2001
|
|
|
9bbebd |
From: Miroslav Grepl <mgrepl@redhat.com>
|
|
|
9bbebd |
Date: Thu, 19 Feb 2015 17:45:15 +0100
|
|
|
9bbebd |
Subject: [PATCH] Simplication of sepolicy-manpage web functionality.
|
|
|
9bbebd |
system_release is no longer hardcoded and it creates only index.html and html
|
|
|
9bbebd |
man pages in the directory for the system release.
|
|
|
9bbebd |
|
|
|
9bbebd |
---
|
|
|
9bbebd |
python/sepolicy/sepolicy/__init__.py | 25 +++--------
|
|
|
9bbebd |
python/sepolicy/sepolicy/manpage.py | 65 +++-------------------------
|
|
|
9bbebd |
2 files changed, 13 insertions(+), 77 deletions(-)
|
|
|
9bbebd |
|
|
|
9bbebd |
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
|
|
|
9bbebd |
index 6aed31bd..88a2b8f6 100644
|
|
|
9bbebd |
--- a/python/sepolicy/sepolicy/__init__.py
|
|
|
9bbebd |
+++ b/python/sepolicy/sepolicy/__init__.py
|
|
|
9bbebd |
@@ -1209,27 +1209,14 @@ def boolean_desc(boolean):
|
|
|
9bbebd |
|
|
|
9bbebd |
|
|
|
9bbebd |
def get_os_version():
|
|
|
9bbebd |
- os_version = ""
|
|
|
9bbebd |
- pkg_name = "selinux-policy"
|
|
|
9bbebd |
+ system_release = ""
|
|
|
9bbebd |
try:
|
|
|
9bbebd |
- try:
|
|
|
9bbebd |
- from commands import getstatusoutput
|
|
|
9bbebd |
- except ImportError:
|
|
|
9bbebd |
- from subprocess import getstatusoutput
|
|
|
9bbebd |
- rc, output = getstatusoutput("rpm -q '%s'" % pkg_name)
|
|
|
9bbebd |
- if rc == 0:
|
|
|
9bbebd |
- os_version = output.split(".")[-2]
|
|
|
9bbebd |
- except:
|
|
|
9bbebd |
- os_version = ""
|
|
|
9bbebd |
-
|
|
|
9bbebd |
- if os_version[0:2] == "fc":
|
|
|
9bbebd |
- os_version = "Fedora" + os_version[2:]
|
|
|
9bbebd |
- elif os_version[0:2] == "el":
|
|
|
9bbebd |
- os_version = "RHEL" + os_version[2:]
|
|
|
9bbebd |
- else:
|
|
|
9bbebd |
- os_version = ""
|
|
|
9bbebd |
+ with open('/etc/system-release') as f:
|
|
|
9bbebd |
+ system_release = f.readline()
|
|
|
9bbebd |
+ except IOError:
|
|
|
9bbebd |
+ system_release = "Misc"
|
|
|
9bbebd |
|
|
|
9bbebd |
- return os_version
|
|
|
9bbebd |
+ return system_release
|
|
|
9bbebd |
|
|
|
9bbebd |
|
|
|
9bbebd |
def reinit():
|
|
|
9bbebd |
diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
|
|
|
9bbebd |
index 46092be0..d60acfaf 100755
|
|
|
9bbebd |
--- a/python/sepolicy/sepolicy/manpage.py
|
|
|
9bbebd |
+++ b/python/sepolicy/sepolicy/manpage.py
|
|
|
9bbebd |
@@ -149,10 +149,6 @@ def prettyprint(f, trim):
|
|
|
9bbebd |
manpage_domains = []
|
|
|
9bbebd |
manpage_roles = []
|
|
|
9bbebd |
|
|
|
9bbebd |
-fedora_releases = ["Fedora17", "Fedora18"]
|
|
|
9bbebd |
-rhel_releases = ["RHEL6", "RHEL7"]
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
def get_alphabet_manpages(manpage_list):
|
|
|
9bbebd |
alphabet_manpages = dict.fromkeys(string.ascii_letters, [])
|
|
|
9bbebd |
for i in string.ascii_letters:
|
|
|
9bbebd |
@@ -182,7 +178,7 @@ def convert_manpage_to_html(html_manpage, manpage):
|
|
|
9bbebd |
class HTMLManPages:
|
|
|
9bbebd |
|
|
|
9bbebd |
"""
|
|
|
9bbebd |
- Generate a HHTML Manpages on an given SELinux domains
|
|
|
9bbebd |
+ Generate a HTML Manpages on an given SELinux domains
|
|
|
9bbebd |
"""
|
|
|
9bbebd |
|
|
|
9bbebd |
def __init__(self, manpage_roles, manpage_domains, path, os_version):
|
|
|
9bbebd |
@@ -190,9 +186,9 @@ class HTMLManPages:
|
|
|
9bbebd |
self.manpage_domains = get_alphabet_manpages(manpage_domains)
|
|
|
9bbebd |
self.os_version = os_version
|
|
|
9bbebd |
self.old_path = path + "/"
|
|
|
9bbebd |
- self.new_path = self.old_path + self.os_version + "/"
|
|
|
9bbebd |
+ self.new_path = self.old_path
|
|
|
9bbebd |
|
|
|
9bbebd |
- if self.os_version in fedora_releases or self.os_version in rhel_releases:
|
|
|
9bbebd |
+ if self.os_version:
|
|
|
9bbebd |
self.__gen_html_manpages()
|
|
|
9bbebd |
else:
|
|
|
9bbebd |
print("SELinux HTML man pages can not be generated for this %s" % os_version)
|
|
|
9bbebd |
@@ -201,7 +197,6 @@ class HTMLManPages:
|
|
|
9bbebd |
def __gen_html_manpages(self):
|
|
|
9bbebd |
self._write_html_manpage()
|
|
|
9bbebd |
self._gen_index()
|
|
|
9bbebd |
- self._gen_body()
|
|
|
9bbebd |
self._gen_css()
|
|
|
9bbebd |
|
|
|
9bbebd |
def _write_html_manpage(self):
|
|
|
9bbebd |
@@ -219,67 +214,21 @@ class HTMLManPages:
|
|
|
9bbebd |
convert_manpage_to_html((self.new_path + r.rsplit("_selinux", 1)[0] + ".html"), self.old_path + r)
|
|
|
9bbebd |
|
|
|
9bbebd |
def _gen_index(self):
|
|
|
9bbebd |
- index = self.old_path + "index.html"
|
|
|
9bbebd |
- fd = open(index, 'w')
|
|
|
9bbebd |
- fd.write("""
|
|
|
9bbebd |
-<html>
|
|
|
9bbebd |
-<head>
|
|
|
9bbebd |
- <link rel=stylesheet type="text/css" href="style.css" title="style">
|
|
|
9bbebd |
- <title>SELinux man pages online</title>
|
|
|
9bbebd |
-</head>
|
|
|
9bbebd |
-<body>
|
|
|
9bbebd |
-SELinux man pages
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-Fedora or Red Hat Enterprise Linux Man Pages.
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-Fedora
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-""")
|
|
|
9bbebd |
- for f in fedora_releases:
|
|
|
9bbebd |
- fd.write("""
|
|
|
9bbebd |
-%s - SELinux man pages for %s """ % (f, f, f, f))
|
|
|
9bbebd |
-
|
|
|
9bbebd |
- fd.write("""
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-RHEL
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-
|
|
|
9bbebd |
-""")
|
|
|
9bbebd |
- for r in rhel_releases:
|
|
|
9bbebd |
- fd.write("""
|
|
|
9bbebd |
-%s - SELinux man pages for %s """ % (r, r, r, r))
|
|
|
9bbebd |
-
|
|
|
9bbebd |
- fd.write("""
|
|
|
9bbebd |
-
|
|
|
9bbebd |
- """)
|
|
|
9bbebd |
- fd.close()
|
|
|
9bbebd |
- print("%s has been created" % index)
|
|
|
9bbebd |
-
|
|
|
9bbebd |
- def _gen_body(self):
|
|
|
9bbebd |
html = self.new_path + self.os_version + ".html"
|
|
|
9bbebd |
fd = open(html, 'w')
|
|
|
9bbebd |
fd.write("""
|
|
|
9bbebd |
<html>
|
|
|
9bbebd |
<head>
|
|
|
9bbebd |
- <link rel=stylesheet type="text/css" href="../style.css" title="style">
|
|
|
9bbebd |
- <title>Linux man-pages online for Fedora18</title>
|
|
|
9bbebd |
+ <link rel=stylesheet type="text/css" href="style.css" title="style">
|
|
|
9bbebd |
+ <title>SELinux man pages online</title>
|
|
|
9bbebd |
</head>
|
|
|
9bbebd |
<body>
|
|
|
9bbebd |
-SELinux man pages for Fedora18
|
|
|
9bbebd |
+SELinux man pages for %s
|
|
|
9bbebd |
|
|
|
9bbebd |
|
|
|
9bbebd |
|
|
|
9bbebd |
SELinux roles
|
|
|
9bbebd |
-""")
|
|
|
9bbebd |
+""" % self.os_version)
|
|
|
9bbebd |
for letter in self.manpage_roles:
|
|
|
9bbebd |
if len(self.manpage_roles[letter]):
|
|
|
9bbebd |
fd.write("""
|
|
|
9bbebd |
--
|
|
|
9bbebd |
2.21.0
|
|
|
9bbebd |
|