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

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

SELinux man pages

60475e
-

60475e
-Fedora or Red Hat Enterprise Linux Man Pages.
60475e
-

60475e
-
60475e
-

Fedora

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

RHEL

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

SELinux man pages for Fedora18

60475e
+

SELinux man pages for %s

60475e
 
60475e
 
60475e
 
60475e
 

SELinux roles

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