Blame SOURCES/0006-Simplication-of-sepolicy-manpage-web-functionality.-.patch

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

SELinux man pages

0cec52
-

0cec52
-Fedora or Red Hat Enterprise Linux Man Pages.
0cec52
-

0cec52
-
0cec52
-

Fedora

0cec52
-
0cec52
-
0cec52
-
0cec52
-
0cec52
-
0cec52
-""")
0cec52
-        for f in fedora_releases:
0cec52
-            fd.write("""
0cec52
-%s - SELinux man pages for %s """ % (f, f, f, f))
0cec52
-
0cec52
-        fd.write("""
0cec52
-
0cec52
-
0cec52
-

RHEL

0cec52
-
0cec52
-
0cec52
-
0cec52
-
0cec52
-
0cec52
-""")
0cec52
-        for r in rhel_releases:
0cec52
-            fd.write("""
0cec52
-%s - SELinux man pages for %s """ % (r, r, r, r))
0cec52
-
0cec52
-        fd.write("""
0cec52
-
0cec52
-	""")
0cec52
-        fd.close()
0cec52
-        print("%s has been created" % index)
0cec52
-
0cec52
-    def _gen_body(self):
0cec52
         html = self.new_path + self.os_version + ".html"
0cec52
         fd = open(html, 'w')
0cec52
         fd.write("""
0cec52
 <html>
0cec52
 <head>
0cec52
-	<link rel=stylesheet type="text/css" href="../style.css" title="style">
0cec52
-	<title>Linux man-pages online for Fedora18</title>
0cec52
+	<link rel=stylesheet type="text/css" href="style.css" title="style">
0cec52
+	<title>SELinux man pages online</title>
0cec52
 </head>
0cec52
 <body>
0cec52
-

SELinux man pages for Fedora18

0cec52
+

SELinux man pages for %s

0cec52
 
0cec52
 
0cec52
 
0cec52
 

SELinux roles

0cec52
-""")
0cec52
+""" % self.os_version)
0cec52
         for letter in self.manpage_roles:
0cec52
             if len(self.manpage_roles[letter]):
0cec52
                 fd.write("""
0cec52
-- 
0cec52
2.21.0
0cec52