Skip to content

Commit

Permalink
Add interop method for find_module
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Apr 22, 2024
1 parent 37c7fdf commit 9825cd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/katello/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import imp
from katello.find_module import find_module

ENABLED_REPOS_CACHE_FILE = '/var/cache/katello-agent/enabled_repos.json'
PACKAGE_CACHE_FILE = '/var/lib/rhsm/packages/packages.json'
Expand All @@ -13,13 +13,13 @@
PROFILE_CACHE_FILE = '/var/lib/rhsm/cache/profile.json'

try:
imp.find_module('zypp_plugin')
find_module('zypp_plugin')
ZYPPER = True
except ImportError:
ZYPPER = False

try:
imp.find_module('yum')
find_module('yum')
YUM = True
except ImportError:
YUM = False
10 changes: 10 additions & 0 deletions src/katello/find_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def find_module(module_name):
try:
import importlib
module_spec = importlib.util.find_spec(module_name)
if module_spec is None:
raise ImportError("Module not found: {}".format(module_name))
return module_spec
except (ImportError, AttributeError):
import imp
return imp.find_module(module_name)
10 changes: 5 additions & 5 deletions src/katello/tracer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from __future__ import absolute_import
from katello.uep import get_uep, lookup_consumer_id
import sys
import imp
from katello.find_module import find_module

def collect_apps():
raise NotImplementedError("Couldn't detect package manager. Failed to query affected apps!")

# RHEL based systems
try:
imp.find_module('dnf')
find_module('dnf')
from katello.tracer.dnf import collect_apps
except ImportError:
try:
imp.find_module('yum')
find_module('yum')
from tracer.query import Query
def collect_apps():
query = Query()
Expand All @@ -22,14 +22,14 @@ def collect_apps():

# debian based systems
try:
imp.find_module('apt')
find_module('apt')
from katello.tracer.deb import collect_apps
except ImportError:
pass

# SUSE based systems
try:
imp.find_module('zypp_plugin')
find_module('zypp_plugin')
from katello.tracer.zypper import collect_apps
except ImportError:
pass
Expand Down

0 comments on commit 9825cd3

Please sign in to comment.