Skip to content

Commit

Permalink
Refs #36973 - Refactor tracer loading to always define the same method
Browse files Browse the repository at this point in the history
This now implements the pattern where it tries to define the
collect_apps method and simply use that, without additional variables.
  • Loading branch information
ekohl authored and ianballou committed Mar 1, 2024
1 parent ca8a292 commit f494bb9
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/katello/tracer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
import imp

def collect_apps():
raise NotImplementedError("This is not the method you want to use. Normally, this method should be provided by tracer.deb or tracer.zypper")
raise NotImplementedError("Couldn't detect package manager. Failed to query affected apps!")

try:
imp.find_module('apt')
from katello.tracer.deb import collect_apps
apt = True
except ImportError as e:
apt = False

try:
imp.find_module('dnf')
dnf = True
except ImportError:
dnf = False
pass

try:
imp.find_module('yum')
yum = True
imp.find_module('dnf')
tracer = True
except ImportError:
yum = False
try:
imp.find_module('yum')
tracer = True
except ImportError:
tracer = False

if yum or dnf:
if tracer:
from tracer.query import Query
def collect_apps():
query = Query()
return query.affected_applications().get()

try:
imp.find_module('zypp_plugin')
from katello.tracer.zypper import collect_apps
zypp = True
except ImportError:
zypp = False
pass


def upload_tracer_profile(queryfunc, plugin=None):
Expand All @@ -48,13 +47,7 @@ def upload_tracer_profile(queryfunc, plugin=None):


def query_affected_apps(plugin=None):
if yum or dnf:
query = Query()
return query.affected_applications().get()
elif zypp or apt:
return collect_apps()
else:
raise Exception("Couldn't detect package manager. Failed to query affected apps!")
return collect_apps()


def get_apps(queryfunc, plugin=None):
Expand Down

0 comments on commit f494bb9

Please sign in to comment.