1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Jeremy Stretch 715592547c #12081: Script & report cleanup (#12091)
* start() and terminate() methods on Job should call save()

* Fix display of associated jobs

* Introduce get_latest_jobs() method on JobsMixin

* Update messaging when no reports/scripts exist

* Catch ImportErrors when rendering report/script lists

* Fix loading of nested modules

* Fix URLs for nested scripts/reports
2023-03-29 16:51:55 -04:00

29 lines
652 B
Python

import os
from importlib.machinery import SourceFileLoader
__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
def get_module(self):
loader = SourceFileLoader(self.python_name, self.full_path)
module = loader.load_module()
return module