1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

29 lines
652 B
Python
Raw Normal View History

2023-03-24 21:25:22 -04:00
import os
from importlib.machinery import SourceFileLoader
2023-03-24 21:25:22 -04:00
__all__ = (
'PythonModuleMixin',
)
class PythonModuleMixin:
@property
def path(self):
return os.path.splitext(self.file_path)[0]
@property
def python_name(self):
path, filename = os.path.split(self.full_path)
name = os.path.splitext(filename)[0]
if name == '__init__':
# File is a package
return os.path.basename(path)
else:
return name
2023-03-24 21:25:22 -04:00
def get_module(self):
loader = SourceFileLoader(self.python_name, self.full_path)
module = loader.load_module()
2023-03-24 21:25:22 -04:00
return module