selinux-python: Update to 3.5, reorganize package
[feed/packages.git] / utils / selinux-python / patches / 0004-sepolicy-fix-get_os_version-except.patch
1 commit 80ba6c49dec9c2c48775e70a4d4564ba5e59eea1
2 Author: Jeffery To <jeffery.to@gmail.com>
3 Date: Mon Jun 19 14:15:45 2023 +0800
4
5 python/sepolicy: Fix get_os_version except clause
6
7 This adds more exceptions to be handled by the except clause in
8 `get_os_version()`:
9
10 * If the `distro` package is not installed, then `import distro` raises
11 a `ModuleNotFoundError` exception.
12
13 * The distro documentation[1] lists `OSError` and `UnicodeError` as
14 exceptions that can be raised.
15
16 * Older versions of distro (<= 1.6.0) may also raise
17 `subprocessCalledProcessError`[2].
18
19 [1]: https://github.com/python-distro/distro/blob/v1.8.0/src/distro/distro.py#L749-L753
20 [2]: https://github.com/python-distro/distro/blob/v1.6.0/distro.py#L726-L728
21
22 Signed-off-by: Jeffery To <jeffery.to@gmail.com>
23
24 --- a/sepolicy/sepolicy/__init__.py
25 +++ b/sepolicy/sepolicy/__init__.py
26 @@ -1240,11 +1240,12 @@ def boolean_desc(boolean):
27
28
29 def get_os_version():
30 + import subprocess
31 system_release = ""
32 try:
33 import distro
34 system_release = distro.name(pretty=True)
35 - except IOError:
36 + except (ModuleNotFoundError, OSError, IOError, UnicodeError, subprocess.CalledProcessError):
37 system_release = "Misc"
38
39 return system_release