summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-11-16 08:41:23 -0600
committerJohn Estabrook <jestabro@vyos.io>2022-11-16 12:10:54 -0600
commitc29f1be7372de3cb68937d01a5c3e793e1881b03 (patch)
tree1b4d17afb10a281a8651ab707394cc7a8016bf46 /python
parenta679b2da9543ad1d071a43caf9f646fbb2857c49 (diff)
downloadvyos-1x-c29f1be7372de3cb68937d01a5c3e793e1881b03.tar.gz
vyos-1x-c29f1be7372de3cb68937d01a5c3e793e1881b03.zip
firewall: T4821: add utility to load script as module
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index a80584c5a..9ebe69b6c 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -1143,3 +1143,11 @@ def camel_to_snake_case(name: str) -> str:
pattern = r'\d+|[A-Z]?[a-z]+|\W|[A-Z]{2,}(?=[A-Z][a-z]|\d|\W|$)'
words = re.findall(pattern, name)
return '_'.join(map(str.lower, words))
+
+def load_as_module(name: str, path: str):
+ import importlib.util
+
+ spec = importlib.util.spec_from_file_location(name, path)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod