Blame SOURCES/tuna-Replace-python_ethtool-with-builtin-funtionalit.patch

81c498
From f2a28b05264fa9557192b73a1b888756748930ac Mon Sep 17 00:00:00 2001
81c498
From: John Kacur <jkacur@redhat.com>
81c498
Date: Tue, 27 Sep 2022 12:59:54 -0400
81c498
Subject: [PATCH 4/6] tuna: Replace python_ethtool with builtin funtionality
81c498
81c498
This patch replaces the dependency on python_ethtool with some
81c498
simplified functions to achieve the same result.
81c498
81c498
Reviewed-by: Federico Pellegrin <fede@evolware.org>
81c498
- return 'tun' only if tun_flags exists
81c498
Signed-off-by: John Kacur <jkacur@redhat.com>
81c498
81c498
diff --git a/tuna-cmd.py b/tuna-cmd.py
81c498
index 9a3d3f32398b..b13b25b8a801 100755
81c498
--- a/tuna-cmd.py
81c498
+++ b/tuna-cmd.py
81c498
@@ -26,7 +26,7 @@ import fnmatch
81c498
 import gettext
81c498
 import locale
81c498
 from functools import reduce
81c498
-import ethtool
81c498
+import tuna.new_eth as ethtool
81c498
 import tuna.tuna_sched as tuna_sched
81c498
 import procfs
81c498
 from tuna import tuna, sysfs
81c498
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
81c498
index 35fc3fd0b0ca..5143d6dc0df5 100755
81c498
--- a/tuna/gui/irqview.py
81c498
+++ b/tuna/gui/irqview.py
81c498
@@ -7,7 +7,7 @@ from gi.repository import Gtk
81c498
 from gi.repository import GObject
81c498
 import os
81c498
 from functools import reduce
81c498
-import ethtool
81c498
+import tuna.new_eth as ethtool
81c498
 import tuna.tuna_sched as tuna_sched
81c498
 
81c498
 import gi
81c498
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
81c498
new file mode 100755
81c498
index 000000000000..98f9179d5695
81c498
--- /dev/null
81c498
+++ b/tuna/new_eth.py
81c498
@@ -0,0 +1,37 @@
81c498
+# Copyright (C) 2022 John Kacur
81c498
+""" A few functions similar to ethtool """
81c498
+import os
81c498
+import socket
81c498
+
81c498
+def get_active_devices():
81c498
+    """ return a list of network devices """
81c498
+    ret = []
81c498
+
81c498
+    for device in socket.if_nameindex():
81c498
+        ret.append(device[1])
81c498
+
81c498
+    return ret
81c498
+
81c498
+def get_module(intf):
81c498
+    """ return the kernel module for the given network interface """
81c498
+    if intf == 'lo':
81c498
+        return ""
81c498
+    myp = f'/sys/class/net/{intf}/device/driver'
81c498
+    if os.path.exists(myp):
81c498
+        return os.path.basename(os.readlink(myp))
81c498
+    if os.path.exists(f'/sys/class/net/{intf}/bridge'):
81c498
+        return 'bridge'
81c498
+    if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
81c498
+        return 'tun'
81c498
+    return ""
81c498
+
81c498
+if __name__ == "__main__":
81c498
+    nics = get_active_devices()
81c498
+    print(f'nics = {nics}')
81c498
+
81c498
+    for intf in nics:
81c498
+        driver = get_module(intf)
81c498
+        if driver:
81c498
+            print(f'{intf}, {driver}')
81c498
+        else:
81c498
+            print(f'{intf}')
81c498
diff --git a/tuna/tuna.py b/tuna/tuna.py
81c498
index 30a5a570c9d4..43adb84079e4 100755
81c498
--- a/tuna/tuna.py
81c498
+++ b/tuna/tuna.py
81c498
@@ -9,7 +9,7 @@ import sys
81c498
 import shlex
81c498
 import fnmatch
81c498
 import platform
81c498
-import ethtool
81c498
+import tuna.new_eth as ethtool
81c498
 import procfs
81c498
 from procfs import utilist
81c498
 from tuna import help
81c498
-- 
81c498
2.31.1
81c498