python/sepolicy/sepolicy: optimise sepolicy gui loading

Significantly speed up sepolicy gui loading by aggregating setools
queries.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
This commit is contained in:
Vit Mojzis 2016-12-09 16:10:00 +01:00 committed by Stephen Smalley
parent ef387e88bd
commit 8fe1b0ca27
2 changed files with 20 additions and 2 deletions

View File

@ -663,6 +663,23 @@ def get_init_entrypoint(transtype):
return entrypoints
def get_init_entrypoints_str():
q = setools.TERuleQuery(_pol,
ruletype=["type_transition"],
source="init_t",
tclass=["process"])
entrypoints = {}
for i in q.results():
try:
transtype = str(i.default)
if transtype in entrypoints:
entrypoints[transtype].append(str(i.target))
else:
entrypoints[transtype] = [str(i.target)]
except AttributeError:
continue
return entrypoints
def get_init_entrypoint_target(entrypoint):
try:

View File

@ -499,6 +499,8 @@ class SELinuxGui():
loading_gui.show()
length = len(self.all_domains)
entrypoint_dict = sepolicy.get_init_entrypoints_str()
for domain in self.all_domains:
# After the user selects a path in the drop down menu call
# get_init_entrypoint_target(entrypoint) to get the transtype
@ -509,8 +511,7 @@ class SELinuxGui():
self.progress_bar.set_pulse_step(self.percentage)
self.idle_func()
entrypoints = [str(x) for x in sepolicy.get_init_entrypoint(domain)]
for entrypoint in entrypoints:
for entrypoint in entrypoint_dict.get(domain, []):
path = sepolicy.find_entrypoint_path(entrypoint)
if path:
self.combo_box_add(path, domain)