From f494bb9cc088216e018de45e17ea3fa41728dee3 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 18 Dec 2023 19:42:45 +0100 Subject: [PATCH] Refs #36973 - Refactor tracer loading to always define the same method This now implements the pattern where it tries to define the collect_apps method and simply use that, without additional variables. --- src/katello/tracer/__init__.py | 37 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/katello/tracer/__init__.py b/src/katello/tracer/__init__.py index 049fa3ba9..bc7056712 100644 --- a/src/katello/tracer/__init__.py +++ b/src/katello/tracer/__init__.py @@ -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): @@ -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):