Skip to content

Commit

Permalink
more elaborate fix
Browse files Browse the repository at this point in the history
  • Loading branch information
br-olf committed Mar 15, 2023
1 parent 1e24a4d commit f3378cc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions selinux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ def add_location(location):

def get_system_sitepackages():
"""Get sitepackage locations from system python"""
system_python = sys.executable

system_sitepackages = json.loads(
python_paths = [
"/usr/bin/python%s",
"/usr/local/bin/python%s"
]
path_check_count = 0

getsitepackages_subprocess = lambda path: json.loads(
subprocess.check_output(
[
system_python,
Expand All @@ -82,7 +87,17 @@ def get_system_sitepackages():
]
).decode("utf-8")
)
return system_sitepackages

while path_check_count < len(python_paths):
try:
system_python = python_paths[path_check_count] % ".".join(
[str(item) for item in platform.python_version_tuple()[0:2]]
)
return getsitepackages_subprocess(system_python)
except FileNotFoundError:
path_check_count += 1
else:
return getsitepackages_subprocess(sys.executable)

def check_system_sitepackages():
"""Try add selinux module from any of the python site-packages"""
Expand Down

0 comments on commit f3378cc

Please sign in to comment.