|
Petr Lautrbach |
577b79d |
From fe825bf76f7a6727a3654c96e7bc55ddc7069b76 Mon Sep 17 00:00:00 2001
|
|
Petr Lautrbach |
577b79d |
From: Petr Lautrbach <lautrbach@redhat.com>
|
|
Petr Lautrbach |
577b79d |
Date: Fri, 18 Nov 2022 13:51:53 +0100
|
|
Petr Lautrbach |
577b79d |
Subject: [PATCH] python/sepolicy: Use distro module to get os version
|
|
Petr Lautrbach |
577b79d |
Content-type: text/plain
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
distro module uses /etc/os-release file which contains operating system
|
|
Petr Lautrbach |
577b79d |
identification data, see os-release(5). Given that the mechanism doesn't
|
|
Petr Lautrbach |
577b79d |
use `rpm` it should be possible to generate man pages on other
|
|
Petr Lautrbach |
577b79d |
distributions.
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
|
|
Petr Lautrbach |
577b79d |
---
|
|
Petr Lautrbach |
577b79d |
python/sepolicy/sepolicy/__init__.py | 25 ++++++-------------------
|
|
Petr Lautrbach |
577b79d |
1 file changed, 6 insertions(+), 19 deletions(-)
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
|
|
Petr Lautrbach |
577b79d |
index 9c3caa05b80b..baa4c8e62e97 100644
|
|
Petr Lautrbach |
577b79d |
--- a/python/sepolicy/sepolicy/__init__.py
|
|
Petr Lautrbach |
577b79d |
+++ b/python/sepolicy/sepolicy/__init__.py
|
|
Petr Lautrbach |
577b79d |
@@ -1226,27 +1226,14 @@ def boolean_desc(boolean):
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
def get_os_version():
|
|
Petr Lautrbach |
577b79d |
- os_version = ""
|
|
Petr Lautrbach |
577b79d |
- pkg_name = "selinux-policy"
|
|
Petr Lautrbach |
577b79d |
+ system_release = ""
|
|
Petr Lautrbach |
577b79d |
try:
|
|
Petr Lautrbach |
577b79d |
- try:
|
|
Petr Lautrbach |
577b79d |
- from commands import getstatusoutput
|
|
Petr Lautrbach |
577b79d |
- except ImportError:
|
|
Petr Lautrbach |
577b79d |
- from subprocess import getstatusoutput
|
|
Petr Lautrbach |
577b79d |
- rc, output = getstatusoutput("rpm -q '%s'" % pkg_name)
|
|
Petr Lautrbach |
577b79d |
- if rc == 0:
|
|
Petr Lautrbach |
577b79d |
- os_version = output.split(".")[-2]
|
|
Petr Lautrbach |
577b79d |
- except:
|
|
Petr Lautrbach |
577b79d |
- os_version = ""
|
|
Petr Lautrbach |
577b79d |
-
|
|
Petr Lautrbach |
577b79d |
- if os_version[0:2] == "fc":
|
|
Petr Lautrbach |
577b79d |
- os_version = "Fedora" + os_version[2:]
|
|
Petr Lautrbach |
577b79d |
- elif os_version[0:2] == "el":
|
|
Petr Lautrbach |
577b79d |
- os_version = "RHEL" + os_version[2:]
|
|
Petr Lautrbach |
577b79d |
- else:
|
|
Petr Lautrbach |
577b79d |
- os_version = ""
|
|
Petr Lautrbach |
577b79d |
+ import distro
|
|
Petr Lautrbach |
577b79d |
+ system_release = distro.name(pretty=True)
|
|
Petr Lautrbach |
577b79d |
+ except IOError:
|
|
Petr Lautrbach |
577b79d |
+ system_release = "Misc"
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
- return os_version
|
|
Petr Lautrbach |
577b79d |
+ return system_release
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
|
|
Petr Lautrbach |
577b79d |
def reinit():
|
|
Petr Lautrbach |
577b79d |
--
|
|
Petr Lautrbach |
577b79d |
2.38.1
|
|
Petr Lautrbach |
577b79d |
|