summaryrefslogtreecommitdiff
path: root/python/vyos/utils
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-06-19 20:37:23 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-06-26 15:38:41 -0500
commit8a57e7b14c818c93655819757d99b69747c9b2ca (patch)
tree6deec6717f0a9d77c4a60ab9c5ab33facebbe8a5 /python/vyos/utils
parent734db72b916192a3988f3b1e9f4bcc3be159cfe5 (diff)
downloadvyos-1x-8a57e7b14c818c93655819757d99b69747c9b2ca.tar.gz
vyos-1x-8a57e7b14c818c93655819757d99b69747c9b2ca.zip
migration: T6007: use load_as_module_source for files without extension
Diffstat (limited to 'python/vyos/utils')
-rw-r--r--python/vyos/utils/system.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py
index f427032a4..fca93d118 100644
--- a/python/vyos/utils/system.py
+++ b/python/vyos/utils/system.py
@@ -99,6 +99,18 @@ def load_as_module(name: str, path: str):
spec.loader.exec_module(mod)
return mod
+def load_as_module_source(name: str, path: str):
+ """ Necessary modification of load_as_module for files without *.py
+ extension """
+ import importlib.util
+ from importlib.machinery import SourceFileLoader
+
+ loader = SourceFileLoader(name, path)
+ spec = importlib.util.spec_from_loader(name, loader)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod
+
def get_uptime_seconds():
""" Returns system uptime in seconds """
from re import search
@@ -127,4 +139,3 @@ def get_load_averages():
res[15] = float(matches["fifteen"]) / core_count
return res
-